|
1 | | -"""Nox configuration.""" |
| 1 | +#!/usr/bin/env -S uv run --script # noqa: EXE001 |
| 2 | +# /// script |
| 3 | +# dependencies = ["nox", "nox_uv"] |
| 4 | +# /// |
| 5 | +"""Nox setup.""" |
2 | 6 |
|
3 | | -import argparse |
4 | 7 | import shutil |
5 | 8 | from pathlib import Path |
6 | 9 |
|
7 | 10 | import nox |
| 11 | +from nox_uv import session |
| 12 | + |
| 13 | +nox.needs_version = ">=2024.3.2" |
| 14 | +nox.options.default_venv_backend = "uv" |
8 | 15 |
|
9 | 16 | DIR = Path(__file__).parent.resolve() |
10 | 17 |
|
11 | | -nox.needs_version = ">=2024.3.2" |
12 | | -nox.options.sessions = ["lint", "tests"] |
13 | | -nox.options.default_venv_backend = "uv|virtualenv" |
| 18 | +# ============================================================================= |
| 19 | +# Linting |
14 | 20 |
|
15 | 21 |
|
16 | | -@nox.session |
17 | | -def lint(session: nox.Session) -> None: |
| 22 | +@session(uv_groups=["lint"], reuse_venv=True, default=True) |
| 23 | +def lint(s: nox.Session, /) -> None: |
18 | 24 | """Run the linter.""" |
19 | | - session.install("pre-commit") |
20 | | - session.run( |
21 | | - "pre-commit", |
22 | | - "run", |
23 | | - "--all-files", |
24 | | - "--show-diff-on-failure", |
25 | | - *session.posargs, |
26 | | - ) |
27 | | - |
28 | | - |
29 | | -@nox.session |
30 | | -def pylint(session: nox.Session) -> None: |
| 25 | + s.notify("precommit") |
| 26 | + s.notify("pylint") |
| 27 | + s.notify("mypy") |
| 28 | + |
| 29 | + |
| 30 | +@session(uv_groups=["lint"], reuse_venv=True) |
| 31 | +def precommit(s: nox.Session, /) -> None: |
| 32 | + """Run pre-commit.""" |
| 33 | + s.run("pre-commit", "run", "--all-files", *s.posargs) |
| 34 | + |
| 35 | + |
| 36 | +@session(uv_groups=["lint"], reuse_venv=True) |
| 37 | +def pylint(s: nox.Session, /) -> None: |
31 | 38 | """Run PyLint.""" |
32 | | - # This needs to be installed into the package environment, and is slower |
33 | | - # than a pre-commit check |
34 | | - session.install(".", "pylint") |
35 | | - session.run("pylint", "dataclassish", *session.posargs) |
| 39 | + s.run("pylint", "dataclassish", *s.posargs) |
| 40 | + |
| 41 | + |
| 42 | +@session(uv_groups=["lint"], reuse_venv=True) |
| 43 | +def mypy(s: nox.Session, /) -> None: |
| 44 | + """Run mypy.""" |
| 45 | + s.run("mypy", "src/dataclassish", *s.posargs) |
| 46 | + |
| 47 | + |
| 48 | +# ============================================================================= |
| 49 | +# Testing |
36 | 50 |
|
37 | 51 |
|
38 | | -@nox.session |
39 | | -def tests(session: nox.Session) -> None: |
| 52 | +@session(uv_groups=["test"], reuse_venv=True, default=True) |
| 53 | +def test(s: nox.Session, /) -> None: |
40 | 54 | """Run the unit and regular tests.""" |
41 | | - session.install(".[test]") |
42 | | - session.run("pytest", *session.posargs) |
43 | | - |
44 | | - |
45 | | -@nox.session(reuse_venv=True) |
46 | | -def docs(session: nox.Session) -> None: |
47 | | - """Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links.""" |
48 | | - parser = argparse.ArgumentParser() |
49 | | - parser.add_argument("--serve", action="store_true", help="Serve after building") |
50 | | - parser.add_argument( |
51 | | - "-b", |
52 | | - dest="builder", |
53 | | - default="html", |
54 | | - help="Build target (default: html)", |
55 | | - ) |
56 | | - args, posargs = parser.parse_known_args(session.posargs) |
57 | | - |
58 | | - if args.builder != "html" and args.serve: |
59 | | - session.error("Must not specify non-HTML builder with --serve") |
60 | | - |
61 | | - extra_installs = ["sphinx-autobuild"] if args.serve else [] |
62 | | - |
63 | | - session.install("-e.[docs]", *extra_installs) |
64 | | - session.chdir("docs") |
65 | | - |
66 | | - if args.builder == "linkcheck": |
67 | | - session.run( |
68 | | - "sphinx-build", |
69 | | - "-b", |
70 | | - "linkcheck", |
71 | | - ".", |
72 | | - "_build/linkcheck", |
73 | | - *posargs, |
74 | | - ) |
75 | | - return |
76 | | - |
77 | | - shared_args = ( |
78 | | - "-n", # nitpicky mode |
79 | | - "-T", # full tracebacks |
80 | | - f"-b={args.builder}", |
81 | | - ".", |
82 | | - f"_build/{args.builder}", |
83 | | - *posargs, |
84 | | - ) |
85 | | - |
86 | | - if args.serve: |
87 | | - session.run("sphinx-autobuild", *shared_args) |
88 | | - else: |
89 | | - session.run("sphinx-build", "--keep-going", *shared_args) |
90 | | - |
91 | | - |
92 | | -@nox.session |
93 | | -def build_api_docs(session: nox.Session) -> None: |
94 | | - """Build (regenerate) API docs.""" |
95 | | - session.install("sphinx") |
96 | | - session.chdir("docs") |
97 | | - session.run( |
98 | | - "sphinx-apidoc", |
99 | | - "-o", |
100 | | - "api/", |
101 | | - "--module-first", |
102 | | - "--no-toc", |
103 | | - "--force", |
104 | | - "../src/dataclassish", |
105 | | - ) |
106 | | - |
107 | | - |
108 | | -@nox.session |
109 | | -def build(session: nox.Session) -> None: |
| 55 | + s.notify("pytest", posargs=s.posargs) |
| 56 | + |
| 57 | + |
| 58 | +@session(uv_groups=["test"], reuse_venv=True) |
| 59 | +def pytest(s: nox.Session, /) -> None: |
| 60 | + """Run the unit and regular tests.""" |
| 61 | + s.run("pytest", *s.posargs) |
| 62 | + |
| 63 | + |
| 64 | +# ============================================================================= |
| 65 | +# Build |
| 66 | + |
| 67 | + |
| 68 | +@session(uv_groups=["build"]) |
| 69 | +def build(s: nox.Session, /) -> None: |
110 | 70 | """Build an SDist and wheel.""" |
111 | 71 | build_path = DIR.joinpath("build") |
112 | 72 | if build_path.exists(): |
113 | 73 | shutil.rmtree(build_path) |
114 | 74 |
|
115 | | - session.install("build") |
116 | | - session.run("python", "-m", "build") |
| 75 | + s.run("python", "-m", "build") |
| 76 | + |
| 77 | + |
| 78 | +# ============================================================================= |
| 79 | + |
| 80 | +if __name__ == "__main__": |
| 81 | + nox.main() |
0 commit comments