-
Notifications
You must be signed in to change notification settings - Fork 1
/
dodo.py
204 lines (179 loc) · 4.59 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import itertools
import os
import pathlib
import shlex
from doit import task_params
from doit.action import CmdAction
HERE = pathlib.Path(__file__).parent
PACKAGE_NAME = "pystiche_papers"
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 pystiche-papers in development mode"""
yield dict(
name="dev",
file_dep=[HERE / "requirements-dev.txt"],
actions=[
do(
"python -m pip install --upgrade --upgrade-strategy=eager ",
"-r requirements-dev.txt",
)
],
)
yield dict(
name="project",
actions=[
do(
"python -m pip install --upgrade --upgrade-strategy=eager",
"--pre light-the-torch",
),
do("ltt install --upgrade --upgrade-strategy=eager -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"""
yield dict(
name="flake8",
actions=[
do("flake8 --config=.flake8"),
],
)
yield dict(
name="mypy",
actions=[
do("mypy --config-file=mypy.ini"),
],
)
@task_params(
[
dict(
name="subset",
long="subset",
type=str,
choices=[
(subset, "")
for subset in ["all", "unit", "replication", "download", "doc"]
],
default="all",
),
dict(
name="large_download",
long="large-download",
type=bool,
default=True,
),
]
)
def task_test(subset, large_download):
"""Runs the test suite"""
pytest = dict(
name="pytest",
actions=[
do(
"pytest -c pytest.ini",
f"--cov-report={'xml' if CI else 'term'}",
*[f"tests/{subset}"] if subset != "all" else [],
*["--skip-large-download"] if not large_download else [],
)
],
)
sphinx = dict(
name="sphinx",
actions=[
do(
"sphinx-build -b doctest -W --keep-going source build",
cwd=HERE / "docs",
),
],
)
if subset == "all":
yield pytest
yield sphinx
elif subset == "doc":
yield sphinx
else:
yield pytest
@task_params(
[
dict(
name="builder",
long="builder",
short="b",
type=str,
choices=[("html", ""), ("latex", "")],
default="html",
),
]
)
def task_doc(builder):
"""Builds the documentation"""
return dict(
actions=[
do(f"sphinx-build -b {builder} source build/{builder}", cwd=HERE / "docs")
]
)
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",
],
)