-
Notifications
You must be signed in to change notification settings - Fork 686
Expand file tree
/
Copy pathnoxfile.py
More file actions
109 lines (89 loc) · 3.25 KB
/
noxfile.py
File metadata and controls
109 lines (89 loc) · 3.25 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
"""Nox sessions for cog Python SDK testing."""
import glob
import platform
import nox
# Use uv for venv creation and Python management (uv auto-downloads Python if needed)
nox.options.default_venv_backend = "uv"
PYTHON_VERSIONS = ["3.10", "3.11", "3.12", "3.13"]
PYTHON_DEFAULT = "3.13"
# Test dependencies (mirrored from pyproject.toml [dependency-groups].test)
TEST_DEPS = [
"pytest",
"pytest-timeout",
"pytest-xdist",
"pytest-cov",
]
def _find_compatible_wheel(pattern: str) -> str | None:
"""Find a wheel matching the current platform from dist/.
Returns None when no wheels exist at all. Raises RuntimeError when
wheels exist but none are compatible — that means the build produced
the wrong platform and should be fixed, not silently papered over.
"""
wheels = glob.glob(pattern)
if not wheels:
return None
system = platform.system().lower()
machine = platform.machine().lower()
platform_tags = {
("darwin", "arm64"): "macosx",
("darwin", "x86_64"): "macosx",
("linux", "x86_64"): "manylinux",
("linux", "aarch64"): "manylinux",
}
tag = platform_tags.get((system, machine))
if tag:
for whl in wheels:
if tag in whl or "none-any" in whl:
return whl
raise RuntimeError(
f"Found wheel(s) in dist/ but none compatible with {system}/{machine}:\n"
+ "\n".join(f" {w}" for w in wheels)
+ "\nRun 'mise run build:coglet:wheel' to build a native wheel."
)
# Unknown platform — let pip figure it out
return wheels[0]
def _install_coglet(session: nox.Session) -> None:
"""Install coglet wheel (required dependency)."""
whl = _find_compatible_wheel("dist/coglet-*.whl")
if whl:
session.install(whl)
else:
session.error(
"No coglet wheel found in dist/. Run 'mise run build:coglet:wheel' first."
)
def _install_package(session: nox.Session) -> None:
"""Install the cog SDK and coglet dependency."""
_install_coglet(session)
whl = _find_compatible_wheel("dist/cog-*.whl")
if whl:
session.install(whl)
else:
# No pre-built wheel — editable install from source.
# This fails in CI (setuptools_scm needs a full git checkout),
# so CI must run build:sdk first.
session.install("-e", ".")
@nox.session(python=PYTHON_VERSIONS)
def tests(session: nox.Session) -> None:
"""Run the test suite."""
_install_package(session)
session.install(*TEST_DEPS)
args = session.posargs or ["-n", "auto", "-vv"]
session.run(
"pytest",
"python/tests",
"--cov=python/cog",
"--cov-report=term-missing:skip-covered",
*args,
)
@nox.session(python=PYTHON_DEFAULT)
def typecheck(session: nox.Session) -> None:
"""Run type checking with pyright."""
_install_package(session)
session.install("pyright==1.1.375")
session.run("pyright", *session.posargs)
@nox.session(name="coglet", python=PYTHON_VERSIONS)
def coglet_tests(session: nox.Session) -> None:
"""Run coglet-python binding tests."""
_install_package(session)
session.install("pytest", "requests")
session.run("pytest", "crates/coglet-python/tests", "-v", *session.posargs)