-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
134 lines (106 loc) · 3.69 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
import os
import sys
from pathlib import Path
import nox
from packaging import version
os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"})
nox.options.reuse_existing_virtualenvs = 1
@nox.parametrize("with_cython", [0, 1])
@nox.parametrize("with_pythran", [0, 1])
@nox.session
def test(session, with_pythran, with_cython):
command = "pdm sync -G base-test"
session.run_always(*command.split(), external=True)
py_version = (
session.python
if session.python is not None
else sys.version.split(maxsplit=1)[0]
)
if version.parse(py_version) < version.parse("3.13"):
# Numba not yet compatible with 3.13 (2024-12-02)
session.install("numba")
session.install("jax", "jaxlib")
if with_pythran:
session.install("pythran")
if with_cython:
session.install("cython")
if version.parse(py_version) < version.parse("3.12"):
session.install("setuptools<60.0")
for backend in ("python", "pythran"):
print(f"TRANSONIC_BACKEND={backend}")
session.run(
"pytest",
"--nbval-lax",
"data_tests/ipynb",
env={"TRANSONIC_BACKEND": backend},
)
path_coverage = Path(".coverage")
path_coverage.mkdir(exist_ok=True)
code_dependencies = 10 * with_pythran + with_cython
for backend in ("python", "pythran", "numba", "jax", "cython"):
print(f"TRANSONIC_BACKEND={backend}")
session.run(
"pytest",
"--cov",
"--cov-config=pyproject.toml",
"tests",
env={
"COVERAGE_FILE": f".coverage/coverage{code_dependencies}.{backend}",
"TRANSONIC_BACKEND": backend,
},
)
command = "mpirun -np 2 coverage run --rcfile=pyproject.toml -m mpi4py -m pytest tests"
session.run(
*command.split(),
external=True,
env={
"TRANSONIC_BACKEND": "pythran",
},
)
@nox.session
def doc(session):
session.run_always("pdm", "sync", "-G", "doc", external=True)
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"
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):
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)