-
Notifications
You must be signed in to change notification settings - Fork 55
ci: add nox utilities for conditional session execution instead of using github actions #1982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
6dfd3a1
5fb4a81
b032f35
e24eaeb
bd66f86
eeb2709
b945f52
a74bdb6
c483e64
f0d5c82
3fd76e8
4ece1f1
3456cb6
fcc242c
0a30b09
03275fb
b3655ca
b7aa661
a6eed30
e8f0497
23980d7
a4be642
019cf6c
08ea3c5
3ea0c5e
763f903
0001431
d476732
052bbaf
bda11db
ede2ad3
48c0dd7
7ca8037
dc06e36
61643d4
9c688f0
cd77635
520acf8
e9fcdfd
60ccc5b
4c4937d
afe48dd
8d7ac17
3b8f38b
9477463
641d521
7f7917a
8802cc7
e604f44
3b6b25d
983e73d
2312e0f
19105af
3d895d3
ca0140f
27a4946
1911ab4
c43de08
3cf2b4a
72a1815
c6429f4
cddca1a
3f8e49d
8ed755a
53e7bb4
0124e4e
2c252f3
2033c6c
05b8220
22bc05c
0dbd2ff
21deb87
c3453d5
67ac9e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,17 @@ | |
|
|
||
| import os | ||
| import pathlib | ||
| import sys | ||
| import types | ||
| from collections.abc import Sequence | ||
| from typing import Final, Literal, TypeAlias | ||
| from collections.abc import Callable, Sequence | ||
| from unittest import mock | ||
| from typing import Any, Final, Literal, TypeAlias, TypeVar | ||
|
|
||
| import nox | ||
|
|
||
| with mock.patch("sys.path", [".", *sys.path]): | ||
| import noxfile_utils as nox_utils | ||
|
|
||
| #: 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 | ||
|
|
@@ -39,6 +44,9 @@ | |
| "test_storage-3.11(cpu)", | ||
| ] | ||
|
|
||
|
|
||
| PYTHON_VERSIONS: Final[list[str]] = pathlib.Path(".python-versions").read_text().splitlines() | ||
|
|
||
| # -- Parameter sets -- | ||
| DeviceOption: TypeAlias = Literal["cpu", "cuda11", "cuda12", "rocm4_3", "rocm5_0"] | ||
| DeviceNoxParam: Final = types.SimpleNamespace( | ||
|
|
@@ -69,8 +77,13 @@ | |
| } | ||
|
|
||
|
|
||
| # -- nox sessions -- | ||
| @nox.session(python=["3.10", "3.11"], tags=["cartesian"]) | ||
| # -- Sessions -- | ||
| @nox_utils.customize_session( | ||
| python=PYTHON_VERSIONS, | ||
| tags=["cartesian"], | ||
| env_vars=["NUM_PROCESSES"], | ||
| ignore_paths=["src/gt4py/next/*", "tests/next_tests/**", "examples/**", "*.md", "*.rst"], | ||
| ) | ||
| @nox.parametrize("device", [DeviceNoxParam.cpu, DeviceNoxParam.cuda12]) | ||
| @nox.parametrize("codegen", [CodeGenNoxParam.internal, CodeGenNoxParam.dace]) | ||
| def test_cartesian( | ||
|
|
@@ -83,13 +96,13 @@ def test_cartesian( | |
| codegen_settings = CodeGenTestSettings[codegen] | ||
| device_settings = DeviceTestSettings[device] | ||
|
|
||
| _install_session_venv( | ||
| nox_utils.install_session_venv( | ||
| session, | ||
| extras=["performance", "testing", *codegen_settings["extras"], *device_settings["extras"]], | ||
| groups=["test"], | ||
| ) | ||
|
|
||
| num_processes = os.environ.get("NUM_PROCESSES", "auto") | ||
| num_processes = session.env.get("NUM_PROCESSES", "auto") | ||
| markers = " and ".join(codegen_settings["markers"] + device_settings["markers"]) | ||
|
|
||
| session.run( | ||
|
|
@@ -104,13 +117,26 @@ def test_cartesian( | |
| ) | ||
|
|
||
|
|
||
| @nox.session(python=["3.10", "3.11"], tags=["cartesian", "next", "cpu"]) | ||
| @nox_utils.customize_session( | ||
| python=PYTHON_VERSIONS, | ||
| tags=["cartesian", "next", "cpu"], | ||
| env_vars=["NUM_PROCESSES"], | ||
| paths=[ # Run when gt4py.eve files (or package settings) are changed | ||
| "src/gt4py/eve/*", | ||
| "tests/eve_tests/*", | ||
| ".github/workflows/*", | ||
| "*.lock", | ||
| "*.toml", | ||
| "*.yml", | ||
| "noxfile.py", | ||
| ], | ||
| ) | ||
| def test_eve(session: nox.Session) -> None: | ||
| """Run 'gt4py.eve' tests.""" | ||
|
|
||
| _install_session_venv(session, groups=["test"]) | ||
| nox_utils.install_session_venv(session, groups=["test"]) | ||
|
|
||
| num_processes = os.environ.get("NUM_PROCESSES", "auto") | ||
| num_processes = session.env.get("NUM_PROCESSES", "auto") | ||
|
|
||
| session.run( | ||
| *f"pytest --cache-clear -sv -n {num_processes}".split(), | ||
|
|
@@ -123,11 +149,11 @@ def test_eve(session: nox.Session) -> None: | |
| ) | ||
|
|
||
|
|
||
| @nox.session(python=["3.10", "3.11"]) | ||
| @nox.session(python=PYTHON_VERSIONS) | ||
| def test_examples(session: nox.Session) -> None: | ||
| """Run and test documentation workflows.""" | ||
|
|
||
| _install_session_venv(session, extras=["testing"], groups=["docs", "test"]) | ||
| nox_utils.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()) | ||
|
|
@@ -145,7 +171,18 @@ def test_examples(session: nox.Session) -> None: | |
| ) | ||
|
|
||
|
|
||
| @nox.session(python=["3.10", "3.11"], tags=["next"]) | ||
| @nox_utils.customize_session( | ||
| python=PYTHON_VERSIONS, | ||
| tags=["next"], | ||
| env_vars=["NUM_PROCESSES"], | ||
| ignore_paths=[ # Skip when only gt4py.cartesian or doc files have been updated | ||
egparedes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "src/gt4py/cartesian/**", | ||
| "tests/cartesian_tests/**", | ||
| "examples/**", | ||
| "*.md", | ||
| "*.rst", | ||
| ], | ||
| ) | ||
| @nox.parametrize( | ||
| "meshlib", | ||
| [ | ||
|
|
@@ -175,13 +212,13 @@ def test_next( | |
| mesh_markers.append("requires_atlas") | ||
| groups.append("frameworks") | ||
|
|
||
| _install_session_venv( | ||
| nox_utils.install_session_venv( | ||
| session, | ||
| extras=["performance", "testing", *codegen_settings["extras"], *device_settings["extras"]], | ||
| groups=groups, | ||
| ) | ||
|
|
||
| num_processes = os.environ.get("NUM_PROCESSES", "auto") | ||
| num_processes = session.env.get("NUM_PROCESSES", "auto") | ||
| markers = " and ".join(codegen_settings["markers"] + device_settings["markers"] + mesh_markers) | ||
|
|
||
| session.run( | ||
|
|
@@ -198,14 +235,14 @@ def test_next( | |
| ) | ||
|
|
||
|
|
||
| @nox.session(python=["3.10", "3.11"], tags=["cartesian", "next", "cpu"]) | ||
| @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"]) | ||
| nox_utils.install_session_venv(session, groups=["test"]) | ||
|
|
||
| session.run( | ||
| *f"pytest --cache-clear -sv".split(), | ||
| *"pytest --cache-clear -sv".split(), | ||
| str(pathlib.Path("tests") / "package_tests"), | ||
| *session.posargs, | ||
| ) | ||
|
|
@@ -218,7 +255,20 @@ def test_package(session: nox.Session) -> None: | |
| ) | ||
|
|
||
|
|
||
| @nox.session(python=["3.10", "3.11"], tags=["cartesian", "next"]) | ||
| @nox_utils.customize_session( | ||
| python=PYTHON_VERSIONS, | ||
| tags=["cartesian", "next"], | ||
| env_vars=["NUM_PROCESSES"], | ||
| paths=[ # Run when gt4py.storage files (or package settings) are changed | ||
| "src/gt4py/storage/**", | ||
| "src/gt4py/cartesian/backend/**", # For DaCe storages | ||
| "tests/storage_tests/**", | ||
| ".github/workflows/**", | ||
| "*.lock", "*.toml", | ||
| "*.yml", | ||
| "noxfile.py", | ||
| ], | ||
| ) | ||
| @nox.parametrize("device", [DeviceNoxParam.cpu, DeviceNoxParam.cuda12]) | ||
| def test_storage( | ||
| session: nox.Session, | ||
|
|
@@ -228,11 +278,11 @@ def test_storage( | |
|
|
||
| device_settings = DeviceTestSettings[device] | ||
|
|
||
| _install_session_venv( | ||
| nox_utils.install_session_venv( | ||
| session, extras=["performance", "testing", *device_settings["extras"]], groups=["test"] | ||
| ) | ||
|
|
||
| num_processes = os.environ.get("NUM_PROCESSES", "auto") | ||
| num_processes = session.env.get("NUM_PROCESSES", "auto") | ||
|
||
| markers = " and ".join(device_settings["markers"]) | ||
|
|
||
| session.run( | ||
|
|
@@ -246,31 +296,3 @@ def test_storage( | |
| str(pathlib.Path("src") / "gt4py" / "storage"), | ||
| success_codes=[0, NO_TESTS_COLLECTED_EXIT_CODE], | ||
| ) | ||
|
|
||
|
|
||
| # -- utils -- | ||
| def _install_session_venv( | ||
| session: nox.Session, | ||
| *args: str | Sequence[str], | ||
| extras: Sequence[str] = (), | ||
| groups: Sequence[str] = (), | ||
| ) -> None: | ||
| """Install session packages using uv.""" | ||
| session.run_install( | ||
| "uv", | ||
| "sync", | ||
| *("--python", session.python), | ||
| "--no-dev", | ||
| *(f"--extra={e}" for e in extras), | ||
| *(f"--group={g}" for g in groups), | ||
| env={key: value for key, value in os.environ.items()} | ||
| | {"UV_PROJECT_ENVIRONMENT": session.virtualenv.location}, | ||
| ) | ||
| for item in args: | ||
| session.run_install( | ||
| "uv", | ||
| "pip", | ||
| "install", | ||
| *((item,) if isinstance(item, str) else item), | ||
| env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location}, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.