-
Notifications
You must be signed in to change notification settings - Fork 17
/
dodo.py
206 lines (157 loc) · 4.93 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
"""doit configuration for BCDI."""
import os
import shutil
from pathlib import Path
import coverage
from bcdi import __version__
# Generic functions go here
def get_path():
"""Get the path of the dodo.py file."""
return os.path.dirname(os.path.abspath(__file__))
# Tasks go here
def task_black():
"""Run black against the package."""
path = get_path()
return {
"actions": [f"python -m black --line-length=88 {path}"],
"verbosity": 2,
}
def task_isort():
"""Run isort against the package."""
path = get_path()
return {
"actions": [f"python -m isort {path}"],
"verbosity": 2,
}
def task_mypy():
"""Run mypy against the package."""
path = get_path()
return {
"actions": [f"python -m mypy {path + '/bcdi'}"],
"verbosity": 2,
}
def task_clean_dist():
"""Remove the build directory and its content."""
def delete_dir(dirname):
"""Delete the directory if it exists."""
path = os.path.join(get_path(), dirname).replace("\\", "/")
if os.path.isdir(path):
shutil.rmtree(path)
print(f"\n\tDeleted {path}\n")
else:
print("\n\tNo build directory to delete.\n")
return {
"actions": [(delete_dir, ["dist/"])],
"verbosity": 2,
}
def task_clean_doc():
"""Remove the compiled documentation."""
def delete_dir(dirname):
"""Delete the directory if it exists."""
path = os.path.join(get_path(), dirname).replace("\\", "/")
if os.path.isdir(path):
shutil.rmtree(path)
print(f"\n\tDeleted {path}\n")
else:
print("\n\tNo built documentation to delete.\n")
return {
"actions": [(delete_dir, ["doc/doc_html/"])],
"verbosity": 2,
}
def task_coverage_xml():
"""
Generate an XML version of the coverage report.
It can be opened with Notepad++.
"""
def create_coverage_xml(coverage_file, output_file):
"""Create an XML report for the coverage."""
print("\n\tXML coverage report generated in 'test_output/'\n")
cov = coverage.Coverage(data_file=coverage_file)
cov.load()
cov.xml_report(outfile=output_file)
return {
"actions": [
(create_coverage_xml, [".coverage", "test_output/coverage-report.xml"])
],
"file_dep": [".coverage"],
"targets": ["test_output/coverage-report.xml"],
"verbosity": 2,
}
def task_clean_coverage():
"""Delete the coverage report."""
def delete_coverage(filename):
"""Delete the file if it exists."""
path = os.path.join(get_path(), filename).replace("\\", "/")
if os.path.isfile(path):
os.unlink(path)
print(f"\n\tDeleted {path}\n")
else:
print("\n\tNo coverage file to delete.\n")
return {
"actions": [(delete_coverage, [".coverage"])],
"file_dep": ["test_output/coverage-report.xml"],
"verbosity": 2,
}
def task_ruff():
"""Run ruff on the modules."""
return {
"actions": ["ruff check ."],
"verbosity": 2,
}
def task_docstrings():
"""Run pydocstyle on the modules."""
return {
"actions": ["pydocstyle bcdi --ignore=D102,D107,D212,D203"],
"verbosity": 2,
}
def task_tests():
"""Run unit tests with coverage."""
return {
"actions": ["coverage run --source=bcdi -m unittest discover"],
"targets": [".coverage"],
"verbosity": 1,
}
def task_check_links_doc():
"""Check external links in the doc using sphinx."""
sourcedir = Path(get_path()) / "doc"
outputdir = sourcedir / "doc_html"
return {
"actions": [f"sphinx-build -b linkcheck {sourcedir} {outputdir}"],
"verbosity": 1,
}
def task_build_doc():
"""Build the documentation with sphinx."""
sourcedir = Path(get_path()) / "doc"
outputdir = sourcedir / "doc_html"
return {
"actions": [f"sphinx-build -b html {sourcedir} {outputdir}"],
"targets": ["docs/"],
"verbosity": 2,
}
def task_build_distribution():
"""Build the distribution."""
return {
"actions": ["poetry build"],
"verbosity": 2,
}
def task_clean_build():
"""Remove the build directory"""
def delete_dir(dirname):
"""Delete the directory if it exists."""
path = os.path.join(get_path(), dirname).replace("\\", "/")
if os.path.isdir(path):
shutil.rmtree(path)
print(f"\n\tDeleted {path}\n")
else:
print("\n\tNo build directory to delete.\n")
return {
"actions": [(delete_dir, ["build/"])],
"verbosity": 2,
}
def task_check_long_description_pypi():
"""Check whether the long description will render correctly on PyPI."""
return {
"actions": ["twine check dist/*"],
"file_dep": [f"dist/bcdi-{__version__}.tar.gz"],
"verbosity": 2,
}