-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathnoxfile.py
More file actions
executable file
·349 lines (299 loc) · 11.1 KB
/
noxfile.py
File metadata and controls
executable file
·349 lines (299 loc) · 11.1 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#! /usr/bin/env -S uv run -q --script --python 3.11
#
# GT4Py - GridTools Framework
#
# Copyright (c) 2014-2024, ETH Zurich
# All rights reserved.
#
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause
#
# Note:
# The explicit '--python 3.11' in the shebang is only needed due
# to the existence of the .python-versions file, which overrides
# the PEP 723 'requires-python' metadata.
# /// script
# requires-python = ">=3.11"
# dependencies = ["nox>=2025.02.09", "uv>=0.6.10"]
# ///
from __future__ import annotations
import pathlib
from collections.abc import Sequence
from typing import Final, Literal, TypeAlias
import nox
import tomllib
# This should just be `pytest.ExitCode.NO_TESTS_COLLECTED` but `pytest`
# is not guaranteed to be available in the venv where `nox` is running.
NO_TESTS_COLLECTED_EXIT_CODE: Final = 5
# -- nox configuration --
nox.options.default_venv_backend = "uv"
nox.options.sessions = [
"test_cartesian-3.10(internal, cpu)",
"test_cartesian-3.10(dace, cpu)",
"test_cartesian-3.11(internal, cpu)",
"test_cartesian-3.11(dace, cpu)",
"test_cartesian-3.12(internal, cpu)",
"test_cartesian-3.12(dace, cpu)",
"test_cartesian-3.13(internal, cpu)",
"test_cartesian-3.13(dace, cpu)",
"test_cartesian-3.14(internal, cpu)",
"test_cartesian-3.14(dace, cpu)",
"test_eve-3.10",
"test_eve-3.11",
"test_eve-3.12",
"test_eve-3.13",
"test_eve-3.14",
"test_next-3.10(internal, cpu, nomesh)",
"test_next-3.10(dace, cpu, nomesh)",
"test_next-3.11(internal, cpu, nomesh)",
"test_next-3.11(dace, cpu, nomesh)",
"test_next-3.12(internal, cpu, nomesh)",
"test_next-3.12(dace, cpu, nomesh)",
"test_next-3.13(internal, cpu, nomesh)",
"test_next-3.13(dace, cpu, nomesh)",
"test_next-3.14(internal, cpu, nomesh)",
"test_next-3.14(dace, cpu, nomesh)",
"test_package-3.10",
"test_package-3.11",
"test_package-3.12",
"test_package-3.13",
"test_package-3.14",
"test_storage-3.10(cpu)",
"test_storage-3.11(cpu)",
"test_storage-3.12(cpu)",
"test_storage-3.13(cpu)",
"test_storage-3.14(cpu)",
]
REPO_ROOT: Final = pathlib.Path(__file__).parent.resolve().absolute()
PYTHON_VERSIONS: Final[list[str]] = [
v
for line in (REPO_ROOT / ".python-versions").read_text().splitlines()
if (v := line.strip()) and not v.startswith("#")
]
REQUIRES_PYTHON = tomllib.loads((REPO_ROOT / "pyproject.toml").read_text())["project"][
"requires-python"
]
# -- Parameter sets --
DeviceOption: TypeAlias = Literal["cpu", "cuda12", "cuda13", "rocm6", "rocm7"]
DeviceNoxParam: Final[dict[DeviceOption, nox.param]] = {
device: nox.param(device, id=device, tags=[device]) for device in DeviceOption.__args__
}
DeviceTestSettings: Final[dict[DeviceOption, dict[str, list[str]]]] = {
"cpu": {"extras": [], "markers": ["not requires_gpu"]},
**{
device: {"extras": [device], "markers": ["requires_gpu"]}
for device in DeviceOption.__args__
if device != "cpu"
},
}
CodeGenOption: TypeAlias = Literal["internal", "dace"]
CodeGenNoxParam: Final[dict[CodeGenOption, nox.param]] = {
codegen: nox.param(codegen, id=codegen, tags=[codegen]) for codegen in CodeGenOption.__args__
}
CodeGenTestSettings: Final[dict[str, dict[str, list[str]]]] = {
"internal": {"extras": ["jax"], "markers": ["not requires_dace"]}
}
# Use dace-cartesian group to select the appropriate dace version
CodeGenCartesianTestSettings = CodeGenTestSettings | {
"dace": {"extras": [], "groups": ["dace-cartesian"], "markers": ["requires_dace"]},
}
# Install dace-next group to select the appropriate dace version
CodeGenNextTestSettings = CodeGenTestSettings | {
"dace": {"extras": [], "groups": ["dace-next"], "markers": ["requires_dace"]},
}
# -- Utilities --
def install_session_venv(
session: nox.Session,
*args: str | Sequence[str],
extras: Sequence[str] = (),
groups: Sequence[str] = (),
) -> None:
"""
Install session packages using the `uv` tool.
Args:
session: The Nox session object.
*args: Additional packages to install in the session (via `uv pip install`)
extras: Names of package's extras to install.
groups: Names of dependency groups to install.
"""
session.run_install(
"uv",
"sync",
"--python",
# uv does not yet combine explicit python version requests with the
# `requires-python` range in `pyproject.toml`, so we do it manually.
# See: https://github.com/astral-sh/uv/issues/16654
f"{REQUIRES_PYTHON}, >={session.python!s}.0",
"--no-dev",
*(f"--extra={e}" for e in extras),
*(f"--group={g}" for g in groups),
env=session.env | dict(UV_PROJECT_ENVIRONMENT=session.virtualenv.location),
)
for item in args:
session.run_install(
"uv",
"pip",
"install",
*((item,) if isinstance(item, str) else item),
env=session.env | dict(UV_PROJECT_ENVIRONMENT=session.virtualenv.location),
)
# -- Sessions --
@nox.session(python=PYTHON_VERSIONS, tags=["cartesian"])
@nox.parametrize("device", [*DeviceNoxParam.values()])
@nox.parametrize("codegen", [*CodeGenNoxParam.values()])
def test_cartesian(
session: nox.Session,
codegen: CodeGenOption,
device: DeviceOption,
) -> None:
"""Run selected 'gt4py.cartesian' tests."""
codegen_settings = CodeGenCartesianTestSettings[codegen]
device_settings = DeviceTestSettings[device]
extras = [
"standard",
"testing",
*codegen_settings.get("extras", []),
*device_settings.get("extras", []),
]
groups = ["test", *codegen_settings.get("groups", []), *device_settings.get("groups", [])]
install_session_venv(session, extras=extras, groups=groups)
markers = " and ".join(codegen_settings["markers"] + device_settings["markers"])
session.run(
*"pytest --cache-clear -sv -n auto --dist loadgroup".split(),
*("-m", f"{markers}"),
str(pathlib.Path("tests") / "cartesian_tests"),
*session.posargs,
)
session.run(
*"pytest --doctest-modules --doctest-ignore-import-errors -sv".split(),
str(pathlib.Path("src") / "gt4py" / "cartesian"),
)
@nox.session(python=PYTHON_VERSIONS, tags=["cartesian", "next", "cpu"])
def test_eve(session: nox.Session) -> None:
"""Run 'gt4py.eve' tests."""
install_session_venv(session, groups=["test"])
session.run(
*"pytest --cache-clear -sv -n auto --dist loadgroup".split(),
str(pathlib.Path("tests") / "eve_tests"),
*session.posargs,
)
session.run(
*"pytest --doctest-modules -sv".split(),
str(pathlib.Path("src") / "gt4py" / "eve"),
)
@nox.session(python=PYTHON_VERSIONS, tags=["next"])
def test_examples(session: nox.Session) -> None:
"""Run and test documentation workflows."""
install_session_venv(session, extras=["testing"], groups=["docs", "test"])
session.run(*"jupytext docs/user/next/QuickstartGuide.md --to .ipynb".split())
session.run(*"jupytext docs/user/next/advanced/*.md --to .ipynb".split())
for notebook, extra_args in [
("docs/user/next/workshop/slides", None),
("docs/user/next/workshop/exercises", ["-k", "solutions"]),
("docs/user/next/QuickstartGuide.ipynb", None),
("docs/user/next/advanced", None),
("examples", (None)),
]:
session.run(
*f"pytest --nbmake {notebook} -sv -n 1 --benchmark-disable".split(),
*(extra_args or []),
)
@nox.session(python=PYTHON_VERSIONS, tags=["next"])
@nox.parametrize(
"meshlib",
[
nox.param("nomesh", id="nomesh", tags=["nomesh"]),
nox.param("atlas", id="atlas", tags=["atlas"]),
],
)
@nox.parametrize("device", [*DeviceNoxParam.values()])
@nox.parametrize("codegen", [*CodeGenNoxParam.values()])
def test_next(
session: nox.Session,
codegen: CodeGenOption,
device: DeviceOption,
meshlib: Literal["nomesh", "atlas"],
) -> None:
"""Run selected 'gt4py.next' tests."""
codegen_settings = CodeGenNextTestSettings[codegen]
device_settings = DeviceTestSettings[device]
extras = [
"standard",
"testing",
*codegen_settings.get("extras", []),
*device_settings.get("extras", []),
]
groups = ["test", *codegen_settings.get("groups", []), *device_settings.get("groups", [])]
mesh_markers: list[str] = []
match meshlib:
case "nomesh":
mesh_markers.append("not requires_atlas")
case "atlas":
mesh_markers.append("requires_atlas")
groups.append("frameworks")
install_session_venv(session, extras=extras, groups=groups)
markers = " and ".join(codegen_settings["markers"] + device_settings["markers"] + mesh_markers)
session.run(
*"pytest --cache-clear -sv -n auto --dist loadgroup".split(),
*("-m", f"{markers}"),
str(pathlib.Path("tests") / "next_tests"),
*session.posargs,
success_codes=[0, NO_TESTS_COLLECTED_EXIT_CODE],
)
session.run(
*"pytest --doctest-modules --doctest-ignore-import-errors -sv".split(),
str(pathlib.Path("src") / "gt4py" / "next"),
success_codes=[0, NO_TESTS_COLLECTED_EXIT_CODE],
)
@nox.session(python=PYTHON_VERSIONS, tags=["cartesian", "next", "cpu"])
def test_package(session: nox.Session) -> None:
"""Run 'gt4py' package level tests."""
install_session_venv(session, groups=["test"])
session.run(
*"pytest --cache-clear -sv".split(),
str(pathlib.Path("tests") / "package_tests"),
*session.posargs,
)
modules = [str(path) for path in (pathlib.Path("src") / "gt4py").glob("*.py")]
session.run(
*"pytest --doctest-modules --doctest-ignore-import-errors -sv".split(),
*modules,
success_codes=[0, NO_TESTS_COLLECTED_EXIT_CODE],
)
@nox.session(python=PYTHON_VERSIONS, tags=["cartesian", "next"])
@nox.parametrize("device", [*DeviceNoxParam.values()])
def test_storage(
session: nox.Session,
device: DeviceOption,
) -> None:
"""Run selected 'gt4py.storage' tests."""
device_settings = DeviceTestSettings[device]
install_session_venv(
session, extras=["standard", "testing", *device_settings["extras"]], groups=["test"]
)
markers = " and ".join(device_settings["markers"])
session.run(
*"pytest --cache-clear -sv -n auto --dist loadgroup".split(),
*("-m", f"{markers}"),
str(pathlib.Path("tests") / "storage_tests"),
*session.posargs,
)
session.run(
*"pytest --doctest-modules -sv".split(),
str(pathlib.Path("src") / "gt4py" / "storage"),
success_codes=[0, NO_TESTS_COLLECTED_EXIT_CODE],
)
@nox.session(python=PYTHON_VERSIONS, tags=["next"])
def test_typing_exports(session: nox.Session) -> None:
"""Test GT4Py usability in a typed client context."""
install_session_venv(session, extras=["standard"], groups=["test", "typing_exports"])
session.run(
"pytest",
"-sv",
"--mypy-testing-base",
"typing_tests",
"typing_tests",
*session.posargs,
)
if __name__ == "__main__":
nox.main()