|
1 | | -"""Nox configuration.""" |
| 1 | +"""Nox setup.""" |
2 | 2 |
|
3 | 3 | import shutil |
4 | 4 | from pathlib import Path |
5 | 5 |
|
6 | 6 | import nox |
7 | | - |
8 | | -DIR = Path(__file__).parent.resolve() |
| 7 | +from nox_uv import session |
9 | 8 |
|
10 | 9 | nox.needs_version = ">=2024.3.2" |
11 | | -nox.options.sessions = ["lint", "pylint", "tests"] |
12 | 10 | nox.options.default_venv_backend = "uv" |
13 | 11 |
|
| 12 | +DIR = Path(__file__).parent.resolve() |
| 13 | + |
| 14 | +# ============================================================================= |
| 15 | +# Linting |
14 | 16 |
|
15 | | -@nox.session |
16 | | -def lint(session: nox.Session) -> None: |
| 17 | + |
| 18 | +@session(uv_groups=["lint"], reuse_venv=True) |
| 19 | +def lint(s: nox.Session, /) -> None: |
17 | 20 | """Run the linter.""" |
18 | | - session.install("pre-commit") |
19 | | - session.run( |
20 | | - "pre-commit", |
21 | | - "run", |
22 | | - "--all-files", |
23 | | - "--show-diff-on-failure", |
24 | | - *session.posargs, |
25 | | - ) |
26 | | - |
27 | | - |
28 | | -@nox.session |
29 | | -def pylint(session: nox.Session) -> None: |
| 21 | + s.notify("precommit") |
| 22 | + s.notify("pylint") |
| 23 | + s.notify("mypy") |
| 24 | + |
| 25 | + |
| 26 | +@session(uv_groups=["lint"], reuse_venv=True) |
| 27 | +def precommit(s: nox.Session, /) -> None: |
| 28 | + """Run pre-commit.""" |
| 29 | + s.run("pre-commit", "run", "--all-files", *s.posargs) |
| 30 | + |
| 31 | + |
| 32 | +@session(uv_groups=["lint"], reuse_venv=True) |
| 33 | +def pylint(s: nox.Session, /) -> None: |
30 | 34 | """Run PyLint.""" |
31 | | - # This needs to be installed into the package environment, and is slower |
32 | | - # than a pre-commit check |
33 | | - session.install(".", "pylint>=3.2") |
34 | | - session.run("pylint", "is_annotated", *session.posargs) |
| 35 | + s.install(".", "pylint>=3.2") |
| 36 | + s.run("pylint", "is_annotated", *s.posargs) |
| 37 | + |
| 38 | + |
| 39 | +@session(uv_groups=["lint"], reuse_venv=True) |
| 40 | +def mypy(s: nox.Session, /) -> None: |
| 41 | + """Run mypy.""" |
| 42 | + s.run("mypy", "src/is_annotated", *s.posargs) |
| 43 | + |
35 | 44 |
|
| 45 | +# ============================================================================= |
| 46 | +# Testing |
36 | 47 |
|
37 | | -@nox.session |
38 | | -def tests(session: nox.Session) -> None: |
| 48 | + |
| 49 | +@session(uv_groups=["test"], reuse_venv=True) |
| 50 | +def pytest(s: nox.Session, /) -> None: |
39 | 51 | """Run the unit and regular tests.""" |
40 | | - session.install(".[test]") |
41 | | - session.run("pytest", *session.posargs) |
| 52 | + s.run("pytest", *s.posargs) |
| 53 | + |
| 54 | + |
| 55 | +# ============================================================================= |
| 56 | +# Build |
42 | 57 |
|
43 | 58 |
|
44 | | -@nox.session |
45 | | -def build(session: nox.Session) -> None: |
| 59 | +@session(uv_groups=["build"]) |
| 60 | +def build(s: nox.Session, /) -> None: |
46 | 61 | """Build an SDist and wheel.""" |
47 | 62 | build_path = DIR.joinpath("build") |
48 | 63 | if build_path.exists(): |
49 | 64 | shutil.rmtree(build_path) |
50 | 65 |
|
51 | | - session.install("build") |
52 | | - session.run("python", "-m", "build") |
| 66 | + s.run("python", "-m", "build") |
0 commit comments