-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdodo.py
211 lines (175 loc) · 3.95 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
205
206
207
208
209
210
211
"""
Doit file to wrap development workflow commands.
"""
import shutil
from pathlib import Path
from doit.task import Task
from doit.tools import create_folder
PACKAGE = "trilium_alchemy"
# badges output
BADGES_PATH = Path("badges")
PYTEST_BADGE = BADGES_PATH / "tests.svg"
COV_BADGE = BADGES_PATH / "cov.svg"
# artifact output
OUT_PATH = Path("__out__")
# test coverage results
TESTS_PATH = OUT_PATH / "test"
JUNIT_PATH = TESTS_PATH / "junit.xml"
COV_PATH = TESTS_PATH / "cov"
COV_HTML_PATH = COV_PATH / "html"
COV_XML_PATH = COV_PATH / "coverage.xml"
# documentation
DOC_PATH = OUT_PATH / "doc"
DOC_HTML_PATH = DOC_PATH / "html"
# static analysis results
ANALYSIS_PATH = OUT_PATH / "analysis"
MYPY_PATH = ANALYSIS_PATH / "mypy"
MYPY_HTML_PATH = MYPY_PATH / "html"
MYPY_XML_PATH = MYPY_PATH / "xml"
PYRIGHT_PATH = ANALYSIS_PATH / "pyright"
PYRIGHT_JSON_PATH = PYRIGHT_PATH / "report.json"
def cleanup_dir(output_dir: Path):
if output_dir.exists():
shutil.rmtree(output_dir)
def task_pytest() -> Task:
"""
Run pytest and generate coverage reports.
"""
args = [
"pytest",
f"--cov={PACKAGE}",
f"--cov-report=html:{COV_HTML_PATH}",
f"--cov-report=xml:{COV_XML_PATH}",
f"--junitxml={JUNIT_PATH}",
]
return Task(
"test",
actions=[
(create_folder, [COV_PATH]),
" ".join(args),
],
targets=[
f"{COV_HTML_PATH}/index.html",
COV_XML_PATH,
JUNIT_PATH,
],
file_dep=[],
clean=[(cleanup_dir, [COV_PATH])],
)
def task_badges() -> Task:
"""
Generate badges from coverage results.
"""
tests_args = [
"genbadge",
"tests",
f"-i {JUNIT_PATH}",
f"-o {PYTEST_BADGE}",
]
cov_args = [
"genbadge",
"coverage",
f"-i {COV_XML_PATH}",
f"-o {COV_BADGE}",
]
return Task(
"badges",
actions=[
(create_folder, [BADGES_PATH]),
" ".join(tests_args),
" ".join(cov_args),
],
targets=[
PYTEST_BADGE,
COV_BADGE,
],
file_dep=[
JUNIT_PATH,
COV_XML_PATH,
],
)
def task_doc() -> Task:
"""
Generate documentation.
"""
args = [
"sphinx-build",
"-T", # show full traceback upon error
"doc",
str(DOC_HTML_PATH),
]
return Task(
"doc",
actions=[
(create_folder, [DOC_HTML_PATH]),
" ".join(args),
],
targets=[
f"{DOC_HTML_PATH}/index.html",
],
file_dep=[],
clean=[(cleanup_dir, [DOC_HTML_PATH])],
)
def task_format() -> Task:
"""
Run formatters.
"""
autoflake_args = [
"autoflake",
"--remove-all-unused-imports",
"--remove-unused-variables",
"-i",
"-r",
".",
]
isort_args = [
"isort",
".",
]
black_args = [
"black",
".",
]
toml_sort_args = [
"toml-sort",
"-i",
"pyproject.toml",
]
return Task(
"format",
actions=[
" ".join(autoflake_args),
" ".join(isort_args),
" ".join(black_args),
" ".join(toml_sort_args),
],
targets=[],
file_dep=[],
)
def task_analysis() -> Task:
"""
Run static analysis tools.
"""
# TODO: command line option to filter specific path
mypy_args = [
"mypy",
"--html-report",
str(MYPY_HTML_PATH),
"--cobertura-xml-report",
str(MYPY_XML_PATH),
PACKAGE,
]
# TODO: get json output from stdout
pyright_args = [
"pyright",
PACKAGE,
]
return Task(
"analysis",
actions=[
" ".join(mypy_args),
" ".join(pyright_args),
],
targets=[],
file_dep=[],
)