-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
286 lines (217 loc) · 7.56 KB
/
noxfile.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
"""Task runner for the developer
Usage
-----
nox -l
nox -s <session>
nox -k <keyword>
or:
make <session>
execute `make list-sessions` or `nox -l` for a list of sessions.
"""
import os
from pathlib import Path
from functools import partial
from shutil import rmtree
import nox
os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"})
nox.options.reuse_existing_virtualenvs = 1
nox.options.sessions = ["tests"]
no_venv_session = partial(nox.session, venv_backend="none")
@nox.session(reuse_venv=True)
def validate_code(session):
"""Validate the code with black and pylint"""
session.run_always(
"pdm", "sync", "--clean", "-G", "lint", "--no-self", external=True
)
session.run("pdm", "validate_code", external=True)
@nox.parametrize("with_mpi", [True, False])
@nox.parametrize("with_cov", [True, False])
@nox.session(reuse_venv=True)
def tests(session, with_mpi, with_cov):
"""Execute unit-tests using pytest"""
with_pfft = "--with-pfft" in session.posargs
with_p3dfft = "--with-p3dfft" in session.posargs
command = "pdm sync --clean --no-self -G test -G build -G pyfftw"
if with_mpi:
command += " -G mpi"
session.run_always(*command.split(), external=True)
session.install(
"-e",
".",
"--no-deps",
"--no-build-isolation",
"-v",
silent=False,
)
session.install("plugins/fluidfft-builder")
plugin_name_seq = ["fftw"]
plugin_names = plugin_name_seq.copy()
if with_mpi:
plugin_names_par = ["mpi_with_fftw", "fftwmpi"]
if with_pfft:
plugin_names_par.append("pfft")
if with_p3dfft:
plugin_names_par.append("p3dfft")
plugin_names.extend(plugin_names_par)
for name in plugin_names:
session.install("-e", f"plugins/fluidfft-{name}", "--no-build-isolation")
if with_cov:
path_coverage = Path.cwd() / ".coverage"
rmtree(path_coverage, ignore_errors=True)
path_coverage.mkdir(exist_ok=True)
def run_command(command, **kwargs):
if with_cov:
command += " --cov --cov-config=pyproject.toml --no-cov-on-fail --cov-report=term-missing --cov-append"
session.run(*command.split(), **kwargs)
command = "pytest -v -s tests"
run_command(command)
run_command(command, env={"TRANSONIC_NO_REPLACE": "1"})
for name in plugin_name_seq:
run_command(f"pytest -v plugins/fluidfft-{name}")
if with_mpi:
def test_plugin(package_name):
if with_cov:
command = "mpirun -np 2 --oversubscribe coverage run -p -m pytest -v -s --exitfirst"
else:
command = "mpirun -np 2 --oversubscribe pytest -v -s "
command += f" plugins/{package_name}"
session.run(*command.split(), external=True)
for name in plugin_names_par:
test_plugin(f"fluidfft-{name}")
if with_cov:
if with_mpi:
session.run("coverage", "combine")
session.run("coverage", "report")
session.run("coverage", "xml")
session.run("coverage", "html")
@nox.session(reuse_venv=True)
def doc(session):
"""Build the documentation"""
session.run_always(
"pdm", "sync", "--clean", "-G", "doc", "--no-self", external=True
)
session.run_always(
"python",
"-c",
"from fluidfft_builder import create_fake_modules as c; c()",
)
session.install(
".", "--no-deps", "-C", "setup-args=-Dtransonic-backend=python"
)
session.chdir("doc")
session.run("make", "cleanall", external=True)
session.run("make", external=True)
def _get_version_from_pyproject(path=Path.cwd()):
if isinstance(path, str):
path = Path(path)
if not path.name == "pyproject.toml":
path /= "pyproject.toml"
if not path.exists():
raise IOError(f"{path} does not exist.")
in_project = False
version = None
with open(path, encoding="utf-8") as file:
for line in file:
if line.startswith("[project]"):
in_project = True
if line.startswith("version =") and in_project:
version = line.split("=")[1].strip()
version = version[1:-1]
break
assert version is not None
return version
@nox.session(name="add-tag-for-release", venv_backend="none")
def add_tag_for_release(session):
"""Add a version tag in the repo"""
session.run("hg", "pull", external=True)
result = session.run(
*"hg log -r default -G".split(), external=True, silent=True
)
if result[0] != "@":
session.run("hg", "update", "default", external=True)
version = _get_version_from_pyproject()
print(f"{version = }")
result = session.run("hg", "tags", "-T", "{tag},", external=True, silent=True)
last_tag = result.split(",", 2)[1]
print(f"{last_tag = }")
if last_tag == version:
session.error("last_tag == version")
answer = input(
f'Do you really want to add and push the new tag "{version}"? (yes/[no]) '
)
if answer != "yes":
print("Maybe next time then. Bye!")
return
print("Let's go!")
session.run("hg", "tag", version, external=True)
session.run("hg", "push", external=True)
@nox.session(name="release-plugin", reuse_venv=True)
def release_plugin(session):
"""Release a plugin on PyPI"""
for project in ("build", "twine", "lastversion"):
session.install(project)
try:
short_name = session.posargs[0]
except IndexError:
session.error(
"No short name given. Use as `nox -R -s release-plugin -- fftw`"
)
print(short_name)
path = Path.cwd() / f"plugins/fluidfft-{short_name}"
if not path.exists():
session.error(f"{path} does not exist")
version = _get_version_from_pyproject(path)
print(f"{version = }")
ret = session.run(
"lastversion",
f"fluidfft-{short_name}",
"--at",
"pip",
success_codes=[0, 1],
silent=True,
)
if ret.startswith("CRITICAL: No release was found"):
print(ret[len("CRITICAL: ") :])
else:
version_on_pypi = ret.strip()
if version_on_pypi == version:
session.error(f"Local version {version} is already released")
session.chdir(path)
path_dist = path / "dist"
rmtree(path_dist, ignore_errors=True)
command = "python -m build"
if short_name in ["fftw", "mpi_with_fftw", "fftwmpi", "pfft", "p3dfft"]:
command += " --sdist"
session.run(*command.split())
session.run("twine", "check", "dist/*")
answer = input(
f"Do you really want to release fluidfft-{short_name} {version}? (yes/[no]) "
)
if answer != "yes":
print("Maybe next time then. Bye!")
return
session.run("twine", "upload", "dist/*")
@nox.session(name="create-fake-modules", reuse_venv=True)
def create_fake_modules(session):
"""Create fake modules for doc"""
session.install("-e", "./plugins/fluidfft-builder")
session.install("black")
session.run(
"python",
"-c",
"from fluidfft_builder import create_fake_modules as c; c()",
)
session.run("black", "src/fluidfft")
@nox.session(python=False)
def detect_pythran_extensions(session):
"""Detect and print Pythran extension modules"""
session.chdir("src")
begin = "- "
# begin = "import "
paths_pythran_files = sorted(Path("fluidfft").rglob("*/__pythran__/*.py"))
print(
begin
+ f"\n{begin}".join(
[str(p)[:-3].replace("/", ".") for p in paths_pythran_files]
)
)