|
| 1 | +"""Nox configuration for multi-version Python testing. |
| 2 | +
|
| 3 | +This configuration uses nox-uv for fast, reproducible environment management |
| 4 | +with uv's lockfile. Run `nox` to test against all supported Python versions, |
| 5 | +or use `nox -s tests-3.12` to test a specific version. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +import nox |
| 11 | +from nox_uv import session |
| 12 | + |
| 13 | +# Use uv as the default venv backend for speed |
| 14 | +nox.options.default_venv_backend = "uv" |
| 15 | + |
| 16 | +# Reuse virtual environments by default for faster local iteration |
| 17 | +nox.options.reuse_venv = "yes" |
| 18 | + |
| 19 | +# All Python versions supported by the SDK (must match CI matrix) |
| 20 | +PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] |
| 21 | + |
| 22 | +# Default sessions to run |
| 23 | +nox.options.sessions = ["tests"] |
| 24 | + |
| 25 | + |
| 26 | +@session(python=PYTHON_VERSIONS, uv_groups=["test"]) |
| 27 | +def tests(s: nox.Session) -> None: |
| 28 | + """Run the test suite against all supported Python versions.""" |
| 29 | + args = s.posargs or [] |
| 30 | + s.run("pytest", *args) |
| 31 | + |
| 32 | + |
| 33 | +@session(python=PYTHON_VERSIONS, uv_groups=["test"]) |
| 34 | +def coverage(s: nox.Session) -> None: |
| 35 | + """Run tests with coverage reporting.""" |
| 36 | + s.run("pytest", "--cov=workos", "--cov-report=term-missing", *s.posargs) |
| 37 | + |
| 38 | + |
| 39 | +@session(uv_only_groups=["lint"]) |
| 40 | +def lint(s: nox.Session) -> None: |
| 41 | + """Run linting with ruff.""" |
| 42 | + s.run("ruff", "check", ".") |
| 43 | + |
| 44 | + |
| 45 | +@session(uv_only_groups=["lint"]) |
| 46 | +def format(s: nox.Session) -> None: |
| 47 | + """Check code formatting with ruff.""" |
| 48 | + s.run("ruff", "format", "--check", ".") |
| 49 | + |
| 50 | + |
| 51 | +@session(uv_only_groups=["lint"]) |
| 52 | +def format_fix(s: nox.Session) -> None: |
| 53 | + """Apply code formatting with ruff.""" |
| 54 | + s.run("ruff", "format", ".") |
| 55 | + |
| 56 | + |
| 57 | +@session(uv_groups=["type_check"]) |
| 58 | +def typecheck(s: nox.Session) -> None: |
| 59 | + """Run type checking with mypy.""" |
| 60 | + s.run("mypy") |
| 61 | + |
| 62 | + |
| 63 | +@session(uv_groups=["test", "lint", "type_check"]) |
| 64 | +def ci(s: nox.Session) -> None: |
| 65 | + """Run all CI checks (format, lint, typecheck, tests) for a single Python version. |
| 66 | +
|
| 67 | + This is useful for quick local validation before pushing. |
| 68 | + """ |
| 69 | + s.run("ruff", "format", "--check", ".") |
| 70 | + s.run("ruff", "check", ".") |
| 71 | + s.run("mypy") |
| 72 | + s.run("pytest") |
0 commit comments