-
Notifications
You must be signed in to change notification settings - Fork 3
/
tasks.py
148 lines (112 loc) · 3.41 KB
/
tasks.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
import os
from invoke import Collection, task
from invoke.exceptions import Exit
PACKAGE = "dataclass_builder"
@task
def check_typing(c):
"""check typing"""
c.run(f"mypy {PACKAGE}")
c.run("mypy --config-file tests/mypy.ini tests")
@task
def check_style(c):
"""check code style"""
c.run(f"flake8 setup.py tasks.py {PACKAGE} tests")
@task
def check_docstrings(c):
"""check docstrings"""
c.run(f"pydocstyle {PACKAGE}")
@task(check_typing, check_style, check_docstrings)
def check_all(c):
"""run all static checkers"""
@task
def develop(c):
"""install development dependencies"""
c.run(f'pip install --upgrade -e ".[dev]"')
@task
def dist_clean(c):
"""cleanup dists"""
c.run("rm -rf dist")
c.run("rm -rf build")
@task(dist_clean)
def dist_build(c):
"""build and check source and wheel dists"""
c.run("python setup.py sdist")
c.run("python setup.py bdist_wheel")
c.run("twine check dist/*")
@task(help={"format": "format to build: html (default) or pdf"})
def doc_build(c, format="html"):
"""build documentation"""
format = format.lower().strip()
if format == "html":
c.run("sphinx-build -b html docs docs/_build/html")
elif format == "pdf":
c.run("sphinx-build -M latexpdf docs docs/_build")
else:
raise Exit(f"invalid documentation format '{format}'")
@task
def doc_clean(c):
"""clean built documentation"""
c.run("rm -rf docs/_build")
c.run("rm -f docs/api/apidoc/*.rst")
@task
def format_isort(c):
"""sort imports"""
c.run("isort -rc .")
@task
def format_black(c):
"""format the codebase with black"""
c.run("black .")
@task(format_isort, format_black)
def format_all(c):
"""isort + black."""
@task(
incrementable=["verbose"],
help={
"verbose": "enable verbose output, can be repeated up to 2 times",
"coverage": "generate a coverage report",
"html": "generate an HTML coverage report",
},
)
def test(c, verbose=0, coverage=False, html=False):
"""run unit tests."""
verbose_ = "-" + "v" * verbose if verbose > 0 else ""
coverage_ = f"--cov {PACKAGE} --cov-branch" if coverage or html else ""
c.run(f"pytest {verbose_} {coverage_}")
if html:
c.run("coverage html")
@task(doc_clean, dist_clean)
def clean(c):
"""cleanup everything"""
c.run("rm -f .coverage")
c.run("rm -rf htmlcov")
c.run("rm -rf .pytest_cache")
c.run("rm -rf .mypy_cache")
c.run("rm -rf *.egg-info")
for top_dir in [PACKAGE, "tests"]:
for root, dirs, _ in os.walk(top_dir):
for dir in dirs:
if dir == "__pycache__":
c.run(f"rm -rf {os.path.join(root, dir)}")
check = Collection("check")
check.add_task(check_all, "all", default=True)
check.add_task(check_typing, "typing")
check.add_task(check_style, "style")
check.add_task(check_docstrings, "docstrings")
dist = Collection("dist")
dist.add_task(dist_build, "build", default=True)
dist.add_task(dist_clean, "clean")
doc = Collection("doc")
doc.add_task(doc_build, "build", default=True)
doc.add_task(doc_clean, "clean")
format = Collection("format")
format.add_task(format_all, "all", default=True)
format.add_task(format_isort, "isort")
format.add_task(format_black, "black")
ns = Collection()
ns.add_task(clean)
ns.add_task(develop)
ns.add_task(test)
ns.add_collection(check)
ns.add_collection(dist)
ns.add_collection(doc)
ns.add_collection(format)