1+ # /// script
2+ # dependencies = ["nox>=2025.2.9"]
3+ # ///
4+
15from __future__ import annotations
26
37import argparse
610
711import nox
812
9- nox .needs_version = ">=2024.4.15 "
13+ nox .needs_version = ">=2025.2.9 "
1014nox .options .default_venv_backend = "uv|virtualenv"
11- nox .options .sessions = ["lint" , "build" , "tests" ]
1215
1316if sys .platform .startswith ("darwin" ):
1417 BUILD_ENV = {
1821else :
1922 BUILD_ENV = {}
2023
21- built = ""
24+ wheel = ""
2225
2326
2427@nox .session
2528def build (session : nox .Session ) -> str :
2629 """
2730 Make an SDist and a wheel. Only runs once.
2831 """
29- global built # noqa: PLW0603
30- if not built :
31- session . log (
32- "The files produced locally by this job are not intended to be redistributable"
33- )
34- session .install ( "build" )
35- tmpdir = session . create_tmp ( )
36- session . run ( "python" , "-m" , "build" , "--outdir" , tmpdir , env = BUILD_ENV )
37- ( wheel_path ,) = Path (tmpdir ).glob ("*.whl " )
38- ( sdist_path ,) = Path (tmpdir ). glob ( "*.tar.gz" )
39- Path ( "dist" ). mkdir ( exist_ok = True )
40- wheel_path .rename (f"dist/{ wheel_path .name } " )
41- sdist_path . rename ( f"dist/ { sdist_path . name } " )
42- built = wheel_path . name
43- return built
32+ session . log (
33+ "The files produced locally by this job are not intended to be redistributable"
34+ )
35+ extra = [ "--installer=uv" ] if session . venv_backend == "uv" else []
36+ session . install ( "build" )
37+ tmpdir = session .create_tmp ( )
38+ session . run ( "python" , "-m" , "build" , "--outdir" , tmpdir , * extra , env = BUILD_ENV )
39+ ( wheel_path ,) = Path ( tmpdir ). glob ( "*.whl" )
40+ ( sdist_path ,) = Path (tmpdir ).glob ("*.tar.gz " )
41+ Path ("dist" ). mkdir ( exist_ok = True )
42+ wheel_path . rename ( f "dist/ { wheel_path . name } " )
43+ sdist_path .rename (f"dist/{ sdist_path .name } " )
44+
45+ global wheel # noqa: PLW0603
46+ wheel = f"dist/ { wheel_path . name } "
4447
4548
4649@nox .session
@@ -52,17 +55,18 @@ def lint(session: nox.Session) -> str:
5255 session .run ("pre-commit" , "run" , "-a" , * session .posargs )
5356
5457
55- @nox .session
58+ @nox .session ( requires = [ "build" ])
5659def tests (session : nox .Session ) -> str :
5760 """
5861 Run the tests.
5962 """
60- wheel = build (session )
61- session .install (f"./dist/{ wheel } [test]" )
63+ pyproject = nox .project .load_toml ("pyproject.toml" )
64+ deps = nox .project .dependency_groups (pyproject , "test" )
65+ session .install (wheel , * deps )
6266 session .run ("pytest" , * session .posargs )
6367
6468
65- @nox .session
69+ @nox .session ( default = False )
6670def bump (session : nox .Session ) -> None :
6771 """
6872 Set to a new version, use -- <version>, otherwise will use the latest version.
@@ -115,3 +119,7 @@ def bump(session: nox.Session) -> None:
115119 session .log (
116120 'Complete! Now run: gh pr create --fill --body "Created by running `nox -s bump -- --commit`"'
117121 )
122+
123+
124+ if __name__ == "__main__" :
125+ nox .main ()
0 commit comments