-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdodo.py
144 lines (117 loc) · 3.32 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
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") == "1"
DOIT_CONFIG = dict(
verbosity=2,
backend="json",
default_tasks=[
"lint",
"test",
"publishable",
],
)
def do(*cmd):
if len(cmd) == 1:
cmd = cmd[0]
if isinstance(cmd, str):
cmd = shlex.split(cmd)
return CmdAction(cmd, shell=False, cwd=HERE)
def _install_dev_requirements(pip="python -m pip"):
return f"{pip} install -r requirements-dev.txt"
def _install_project(pip="python -m pip"):
return f"{pip} install -e ."
def task_install():
"""Installs all development requirements and light-the-torch in development mode"""
yield dict(
name="dev",
file_dep=[HERE / "requirements-dev.txt"],
actions=[do(_install_dev_requirements())],
)
yield dict(
name="project",
actions=[
do(_install_project()),
],
)
def task_setup():
"""Sets up a development environment for light-the-torch"""
dev_env = HERE / ".venv"
pip = dev_env / "bin" / "pip"
return dict(
actions=[
do(f"virtualenv {dev_env} --prompt='(light-the-torch-dev) '"),
do(_install_dev_requirements(pip)),
do(_install_project(pip)),
lambda: print(
f"run `source {dev_env / 'bin' / 'activate'}` the virtual environment"
),
],
clean=[do(f"rm -rf {dev_env}")],
uptodate=[lambda: dev_env.exists()],
)
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(f"pytest -c pytest.ini --cov-report={'xml' if CI else 'term'}")],
)
def task_build():
"""Builds the source distribution and wheel of light-the-torch"""
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 light-the-torch to PyPI"""
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",
],
)