-
Notifications
You must be signed in to change notification settings - Fork 7
/
dodo.py
122 lines (101 loc) · 2.71 KB
/
dodo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import itertools
import os
import pathlib
import shlex
from doit.action import CmdAction
HERE = pathlib.Path(__file__).parent
PACKAGE_NAME = "light_the_torch"
CI = os.environ.get("CI") == "true"
DOIT_CONFIG = dict(
verbosity=2,
backend="json",
default_tasks=[
"lint",
"test",
"publishable",
],
)
def do(*cmd, cwd=HERE):
if len(cmd) == 1 and callable(cmd[0]):
cmd = cmd[0]
else:
cmd = list(itertools.chain.from_iterable(shlex.split(part) for part in cmd))
return CmdAction(cmd, shell=False, cwd=cwd)
def task_install():
"""Installs all development requirements and light-the-torch in development mode"""
yield dict(
name="dev",
actions=[do("python -m pip install --upgrade -r requirements-dev.txt")],
)
yield dict(
name="project",
actions=[do("python -m pip install --upgrade -e .")],
)
def task_format():
"""Auto-formats all project files"""
return dict(
actions=[
do("pre-commit run --all-files"),
]
)
def task_lint():
"""Lints all project files"""
return dict(
actions=[
do("flake8 --config=.flake8"),
],
)
def task_test():
"""Runs the test suite"""
return dict(
actions=[
do(
"pytest -c pytest.ini",
f"--cov-report={'xml' if CI else 'term'}",
)
]
)
def task_build():
"""Builds the source distribution and wheel"""
return dict(
actions=[
do("python -m build ."),
],
clean=[
do(f"rm -rf build dist {PACKAGE_NAME}.egg-info"),
],
)
def task_publishable():
"""Checks if metadata is correct"""
yield dict(
name="twine",
actions=[
# We need the lambda here to lazily glob the files in dist/*, since they
# are only created by the build task rather than when this task is
# created.
do(lambda: ["twine", "check", *list((HERE / "dist").glob("*"))]),
],
task_dep=["build"],
)
yield dict(
name="check-wheel-contents",
actions=[
do("check-wheel-contents dist"),
],
task_dep=["build"],
)
def task_publish():
"""Publishes to PyPI"""
# TODO: check if env vars are set
return dict(
# We need the lambda here to lazily glob the files in dist/*, since they are
# only created by the build task rather than when this task is created.
actions=[
do(lambda: ["twine", "upload", *list((HERE / "dist").glob("*"))]),
],
task_dep=[
"lint",
"test",
"publishable",
],
)