1+ # /// script
2+ # dependencies = ["nox>=2025.2.9"]
3+ # ///
4+
15from __future__ import annotations
26
37import os
610
711import nox
812
9- nox .options . sessions = [ "lint" , "test-dist" ]
13+ nox .needs_version = ">=2025.2.9"
1014
1115PYTHON_ALL_VERSIONS = ["3.9" , "3.10" , "3.11" , "3.12" , "3.13" ]
1216RUNNING_CI = "TRAVIS" in os .environ or "GITHUB_ACTIONS" in os .environ
1317
18+ wheel = ""
19+ sdist = ""
20+
1421
1522@nox .session (python = ["3.9" ], reuse_venv = True )
1623def lint (session : nox .Session ) -> None :
@@ -21,12 +28,14 @@ def lint(session: nox.Session) -> None:
2128 session .run ("pre-commit" , "run" , "--all-files" )
2229
2330
24- @nox .session ()
31+ @nox .session (default = False )
2532def coverage (session : nox .Session ) -> None :
2633 """
2734 Run coverage using unit tests.
2835 """
29- session .install (".[coverage]" )
36+ pyproject = nox .project .load_toml ("pyproject.toml" )
37+ deps = nox .project .dependency_groups (pyproject , "coverage" )
38+ session .install ("-e" , "." , * deps )
3039 session .run (
3140 "python" ,
3241 "-m" ,
@@ -55,14 +64,16 @@ def _docker_images(session: nox.Session) -> list[str]:
5564 return images_file .read_text ().splitlines ()
5665
5766
58- @nox .session (python = PYTHON_ALL_VERSIONS )
67+ @nox .session (python = PYTHON_ALL_VERSIONS , default = False )
5968def tests (session : nox .Session ) -> None :
6069 """
6170 Run tests.
6271 """
6372 posargs = session .posargs
64- extras = "coverage" if RUNNING_CI else "test"
65- session .install ("-e" , f".[{ extras } ]" )
73+ dep_group = "coverage" if RUNNING_CI else "test"
74+ pyproject = nox .project .load_toml ("pyproject.toml" )
75+ deps = nox .project .dependency_groups (pyproject , dep_group )
76+ session .install ("-e" , "." , * deps )
6677 if RUNNING_CI :
6778 posargs .extend (["--cov" , "auditwheel" , "--cov-branch" ])
6879 # pull manylinux images that will be used.
@@ -76,62 +87,53 @@ def tests(session: nox.Session) -> None:
7687 session .run ("coverage" , "xml" , "-ocoverage.xml" )
7788
7889
79- def _build (session : nox .Session , dist : Path ) -> None :
90+ @nox .session (python = ["3.9" ], default = False )
91+ def build (session : nox .Session ) -> None :
8092 session .install ("build" )
8193 tmp_dir = Path (session .create_tmp ()) / "build-output"
8294 session .run ("python" , "-m" , "build" , "--outdir" , str (tmp_dir ))
8395 (wheel_path ,) = tmp_dir .glob ("*.whl" )
8496 (sdist_path ,) = tmp_dir .glob ("*.tar.gz" )
85- dist .mkdir (exist_ok = True )
86- wheel_path .rename (dist / wheel_path .name )
87- sdist_path .rename (dist / sdist_path .name )
97+ Path ( " dist" ) .mkdir (exist_ok = True )
98+ wheel_path .rename (f" dist/ { wheel_path .name } " )
99+ sdist_path .rename (f" dist/ { sdist_path .name } " )
88100
89-
90- @nox .session (name = "test-dist" )
91- def test_dist (session : nox .Session ) -> None :
92- """
93- Builds SDist & Wheels then run unit tests on those.
94- """
95- tmp_dir = Path (session .create_tmp ())
96- dist = tmp_dir / "dist"
97- _build (session , dist )
98- python_versions = session .posargs or PYTHON_ALL_VERSIONS
99- for version in python_versions :
100- session .notify (f"_test_sdist-{ version } " , [str (dist )])
101- session .notify (f"_test_wheel-{ version } " , [str (dist )])
101+ global sdist # noqa: PLW0603
102+ sdist = f"dist/{ sdist_path .name } "
103+ global wheel # noqa: PLW0603
104+ wheel = f"dist/{ wheel_path .name } "
102105
103106
104- def _test_dist (session : nox .Session , path : str , pattern : str ) -> None :
105- (dist_path ,) = Path (path ).glob (pattern )
106- session .install (f"{ dist_path !s} [test]" )
107+ def _test_dist (session : nox .Session , path : str ) -> None :
108+ pyproject = nox .project .load_toml ("pyproject.toml" )
109+ deps = nox .project .dependency_groups (pyproject , "test" )
110+ session .install (path , * deps )
107111 session .run ("pytest" , "tests/unit" )
108112
109113
110- @nox .session (python = PYTHON_ALL_VERSIONS )
111- def _test_sdist (session : nox .Session ) -> None :
114+ @nox .session (name = "test-sdist" , python = PYTHON_ALL_VERSIONS , requires = [ "build" ] )
115+ def test_sdist (session : nox .Session ) -> None :
112116 """
113117 Do not run explicitly.
114118 """
115- _test_dist (session , session . posargs [ 0 ], "*.tar.gz" )
119+ _test_dist (session , sdist )
116120
117121
118- @nox .session (python = PYTHON_ALL_VERSIONS )
119- def _test_wheel (session : nox .Session ) -> None :
122+ @nox .session (name = "test-wheel" , python = PYTHON_ALL_VERSIONS , requires = [ "build" ] )
123+ def test_wheel (session : nox .Session ) -> None :
120124 """
121125 Do not run explicitly.
122126 """
123- _test_dist (session , session . posargs [ 0 ], "*.whl" )
127+ _test_dist (session , wheel )
124128
125129
126- @nox .session
127- def build (session : nox .Session ) -> None :
128- """
129- Make an SDist and a wheel.
130- """
131- _build ( session , Path ( "dist" ) )
130+ @nox .session ( python = PYTHON_ALL_VERSIONS , reuse_venv = True , default = False )
131+ def develop (session : nox .Session ) -> None :
132+ session . run ( "python" , "-m" , "pip" , "install" , "--upgrade" , "pip" )
133+ pyproject = nox . project . load_toml ( "pyproject.toml" )
134+ deps = nox . project . dependency_groups ( pyproject , "dev" )
135+ session . install ( "-e" , "." , * deps )
132136
133137
134- @nox .session (python = PYTHON_ALL_VERSIONS , reuse_venv = True )
135- def develop (session : nox .Session ) -> None :
136- session .run ("python" , "-m" , "pip" , "install" , "--upgrade" , "pip" , "setuptools" )
137- session .install ("-e" , ".[develop]" )
138+ if __name__ == "__main__" :
139+ nox .main ()
0 commit comments