1- """Nox sessions."""
1+ #!/usr/bin/env -S uv run --script # noqa: EXE001
2+ # /// script
3+ # dependencies = ["nox"]
4+ # ///
25# pylint: disable=import-error
6+ """Nox sessions."""
37
48import argparse
59import shutil
610from pathlib import Path
711
812import nox
13+ from nox_uv import session
914
1015DIR = Path (__file__ ).parent .resolve ()
1116
1217nox .needs_version = ">=2024.3.2"
13- nox .options .sessions = [
14- # Linting
15- "lint" ,
16- "pylint" ,
17- # Testing
18- "tests" ,
19- "tests_benchmark" ,
20- # Documentation
21- "docs" ,
22- "build_api_docs" ,
23- ]
2418nox .options .default_venv_backend = "uv"
2519
2620
2721# =============================================================================
2822# Linting
2923
3024
31- @nox .session (venv_backend = "uv" )
32- def lint (session : nox .Session , / ) -> None :
25+ session (uv_groups = ["lint" ], reuse_venv = True )
26+
27+
28+ def lint (s : nox .Session , / ) -> None :
3329 """Run the linter."""
34- precommit (session ) # reuse pre-commit session
35- pylint (session ) # reuse pylint session
30+ precommit (s ) # reuse pre-commit session
31+ pylint (s ) # reuse pylint session
3632
3733
38- @nox . session
39- def precommit (session : nox .Session ) -> None :
34+ @session ( uv_groups = [ "lint" ], reuse_venv = True )
35+ def precommit (s : nox .Session , / ) -> None :
4036 """Run the linter."""
41- session .run_install (
42- "uv" ,
43- "sync" ,
44- "--group=lint" ,
45- f"--python={ session .virtualenv .location } " ,
46- env = {"UV_PROJECT_ENVIRONMENT" : session .virtualenv .location },
47- )
48- session .run ("pre-commit" , "run" , "--all-files" , * session .posargs )
37+ s .run ("pre-commit" , "run" , "--all-files" , * s .posargs )
4938
5039
51- @nox . session (venv_backend = "uv" )
52- def pylint (session : nox .Session , / ) -> None :
40+ @session (uv_groups = [ "lint" ], reuse_venv = True )
41+ def pylint (s : nox .Session , / ) -> None :
5342 """Run PyLint."""
54- session .run_install (
55- "uv" ,
56- "sync" ,
57- "--group=lint" ,
58- f"--python={ session .virtualenv .location } " ,
59- env = {"UV_PROJECT_ENVIRONMENT" : session .virtualenv .location },
60- )
61- session .run ("pylint" , "coordinax" , * session .posargs )
43+ s .install ("." , "pylint" )
44+ s .run ("pylint" , "quaxed" , * s .posargs )
6245
6346
6447# =============================================================================
6548# Testing
6649
6750
68- @nox . session (venv_backend = "uv" )
69- def tests ( session : nox .Session , / ) -> None :
51+ @session (uv_groups = [ "test" ], reuse_venv = True )
52+ def pytest ( s : nox .Session , / ) -> None :
7053 """Run the unit and regular tests."""
71- session .run_install (
72- "uv" ,
73- "sync" ,
74- "--group=test" ,
75- f"--python={ session .virtualenv .location } " ,
76- env = {"UV_PROJECT_ENVIRONMENT" : session .virtualenv .location },
77- )
78- session .run ("pytest" , * session .posargs )
54+ s .run ("pytest" , * s .posargs )
7955
8056
81- @nox . session
82- def tests_benckmark ( session : nox .Session , / ) -> None :
57+ @session ( uv_groups = [ "test" ], reuse_venv = True )
58+ def benchmark ( s : nox .Session , / ) -> None :
8359 """Run the benchmarks."""
84- session .run_install (
85- "uv" ,
86- "sync" ,
87- "--group=test" ,
88- f"--python={ session .virtualenv .location } " ,
89- env = {"UV_PROJECT_ENVIRONMENT" : session .virtualenv .location },
90- )
91- session .run ("pytest" , "tests/benchmark" , "--codspeed" , * session .posargs )
60+ s .run ("pytest" , "tests/benchmark" , "--codspeed" , * s .posargs )
9261
9362
9463# =============================================================================
9564# Documentation
9665
9766
98- @nox . session (reuse_venv = True )
99- def docs (session : nox .Session ) -> None :
67+ @session (uv_groups = [ "docs" ], reuse_venv = True )
68+ def docs (s : nox .Session , / ) -> None :
10069 """Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links."""
10170 parser = argparse .ArgumentParser ()
10271 parser .add_argument ("--serve" , action = "store_true" , help = "Serve after building" )
@@ -108,26 +77,26 @@ def docs(session: nox.Session) -> None:
10877 )
10978 parser .add_argument ("--offline" , action = "store_true" , help = "run in offline mode" )
11079 parser .add_argument ("--output-dir" , dest = "output_dir" , default = "_build" )
111- args , posargs = parser .parse_known_args (session .posargs )
80+ args , posargs = parser .parse_known_args (s .posargs )
11281
11382 if args .builder != "html" and args .serve :
114- session .error ("Must not specify non-HTML builder with --serve" )
83+ s .error ("Must not specify non-HTML builder with --serve" )
11584
11685 offline_command = ["--offline" ] if args .offline else []
11786
118- session .run_install (
87+ s .run_install (
11988 "uv" ,
12089 "sync" ,
12190 "--group=docs" ,
122- f"--python={ session .virtualenv .location } " ,
91+ f"--python={ s .virtualenv .location } " ,
12392 "--active" ,
12493 * offline_command ,
125- env = {"UV_PROJECT_ENVIRONMENT" : session .virtualenv .location },
94+ env = {"UV_PROJECT_ENVIRONMENT" : s .virtualenv .location },
12695 )
127- session .chdir ("docs" )
96+ s .chdir ("docs" )
12897
12998 if args .builder == "linkcheck" :
130- session .run (
99+ s .run (
131100 "sphinx-build" ,
132101 "-b" ,
133102 "linkcheck" ,
@@ -149,17 +118,17 @@ def docs(session: nox.Session) -> None:
149118 )
150119
151120 if args .serve :
152- session .run ("sphinx-autobuild" , * shared_args )
121+ s .run ("sphinx-autobuild" , * shared_args )
153122 else :
154- session .run ("sphinx-build" , "--keep-going" , * shared_args )
123+ s .run ("sphinx-build" , "--keep-going" , * shared_args )
155124
156125
157- @nox . session
158- def build_api_docs (session : nox .Session ) -> None :
126+ @session ( uv_groups = [ "docs" ], reuse_venv = True )
127+ def build_api_docs (s : nox .Session , / ) -> None :
159128 """Build (regenerate) API docs."""
160- session .install ("sphinx" )
161- session .chdir ("docs" )
162- session .run (
129+ s .install ("sphinx" )
130+ s .chdir ("docs" )
131+ s .run (
163132 "sphinx-apidoc" ,
164133 "-o" ,
165134 "api/" ,
@@ -173,12 +142,18 @@ def build_api_docs(session: nox.Session) -> None:
173142# =============================================================================
174143
175144
176- @nox . session
177- def build (session : nox .Session ) -> None :
145+ @session ( uv_groups = [ "build" ], reuse_venv = True )
146+ def build (s : nox .Session , / ) -> None :
178147 """Build an SDist and wheel."""
179148 build_path = DIR .joinpath ("build" )
180149 if build_path .exists ():
181150 shutil .rmtree (build_path )
182151
183- session .install ("build" )
184- session .run ("python" , "-m" , "build" )
152+ s .install ("build" )
153+ s .run ("python" , "-m" , "build" )
154+
155+
156+ ################################################################################
157+
158+ if __name__ == "__main__" :
159+ nox .main ()
0 commit comments