|
1 | | -from __future__ import annotations |
| 1 | +"""Nox sessions.""" |
2 | 2 |
|
3 | 3 | import shutil |
4 | 4 | from pathlib import Path |
|
8 | 8 | DIR = Path(__file__).parent.resolve() |
9 | 9 |
|
10 | 10 | nox.needs_version = ">=2024.3.2" |
11 | | -nox.options.sessions = ["lint", "pylint", "tests"] |
| 11 | +nox.options.sessions = [ |
| 12 | + "tests", |
| 13 | + # Linting |
| 14 | + "lint", |
| 15 | + "pylint", |
| 16 | + # Testing |
| 17 | + "test", |
| 18 | + # Packaging |
| 19 | + "build", |
| 20 | +] |
12 | 21 | nox.options.default_venv_backend = "uv|virtualenv" |
13 | 22 |
|
14 | 23 |
|
15 | 24 | @nox.session |
16 | | -def lint(session: nox.Session) -> None: |
17 | | - """ |
18 | | - Run the linter. |
19 | | - """ |
20 | | - session.install("pre-commit") |
| 25 | +def lint(session: nox.Session, /) -> None: |
| 26 | + """Run the linter.""" |
21 | 27 | session.run( |
22 | | - "pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs |
| 28 | + "uv", |
| 29 | + "run", |
| 30 | + "pre-commit", |
| 31 | + "run", |
| 32 | + "--all-files", |
| 33 | + "--show-diff-on-failure", |
| 34 | + *session.posargs, |
23 | 35 | ) |
24 | 36 |
|
25 | 37 |
|
26 | 38 | @nox.session |
27 | 39 | def pylint(session: nox.Session) -> None: |
28 | | - """ |
29 | | - Run PyLint. |
30 | | - """ |
| 40 | + """Run PyLint.""" |
31 | 41 | # This needs to be installed into the package environment, and is slower |
32 | 42 | # than a pre-commit check |
33 | | - session.install(".", "pylint") |
34 | | - session.run("pylint", "xmmutablemap", *session.posargs) |
| 43 | + if shutil.which("uv"): |
| 44 | + session.run("uv", "sync", "--group", "pylint") |
| 45 | + session.run("uv", "run", "pylint", "xmmutablemap", *session.posargs) |
| 46 | + else: |
| 47 | + # Fallback to regular pip if uv is not available |
| 48 | + session.install("pylint>=3.3.8") |
| 49 | + session.install("-e", ".") |
| 50 | + session.run("pylint", "xmmutablemap", *session.posargs) |
| 51 | + |
| 52 | + |
| 53 | +# ============================================================================= |
| 54 | +# Testing |
| 55 | + |
| 56 | + |
| 57 | +@nox.session |
| 58 | +def test(session: nox.Session) -> None: |
| 59 | + """Run the tests.""" |
| 60 | + session.run("uv", "sync", "--group", "test") |
| 61 | + session.run("uv", "run", "pytest", *session.posargs) |
35 | 62 |
|
36 | 63 |
|
37 | 64 | @nox.session |
38 | 65 | def tests(session: nox.Session) -> None: |
39 | | - """ |
40 | | - Run the unit and regular tests. |
41 | | - """ |
42 | | - session.install(".[test]") |
43 | | - session.run("pytest", *session.posargs) |
| 66 | + """Run the lints and tests.""" |
| 67 | + session.notify("lint") |
| 68 | + session.notify("test") |
| 69 | + |
| 70 | + |
| 71 | +# ============================================================================= |
| 72 | +# Packaging |
44 | 73 |
|
45 | 74 |
|
46 | 75 | @nox.session |
47 | 76 | def build(session: nox.Session) -> None: |
48 | | - """ |
49 | | - Build an SDist and wheel. |
50 | | - """ |
51 | | - |
| 77 | + """Build an SDist and wheel.""" |
52 | 78 | build_path = DIR.joinpath("build") |
53 | 79 | if build_path.exists(): |
54 | 80 | shutil.rmtree(build_path) |
|
0 commit comments