1
+ # /// script
2
+ # dependencies = ["nox>=2025.2.9"]
3
+ # ///
4
+
1
5
from __future__ import annotations
2
6
3
7
import argparse
6
10
7
11
import nox
8
12
9
- nox .needs_version = ">=2024.4.15 "
13
+ nox .needs_version = ">=2025.2.9 "
10
14
nox .options .default_venv_backend = "uv|virtualenv"
11
- nox .options .sessions = ["lint" , "build" , "tests" ]
12
15
13
16
if sys .platform .startswith ("darwin" ):
14
17
BUILD_ENV = {
18
21
else :
19
22
BUILD_ENV = {}
20
23
21
- built = ""
24
+ wheel = ""
22
25
23
26
24
27
@nox .session
25
28
def build (session : nox .Session ) -> str :
26
29
"""
27
30
Make an SDist and a wheel. Only runs once.
28
31
"""
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 } "
44
47
45
48
46
49
@nox .session
@@ -52,17 +55,18 @@ def lint(session: nox.Session) -> str:
52
55
session .run ("pre-commit" , "run" , "-a" , * session .posargs )
53
56
54
57
55
- @nox .session
58
+ @nox .session ( requires = [ "build" ])
56
59
def tests (session : nox .Session ) -> str :
57
60
"""
58
61
Run the tests.
59
62
"""
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 )
62
66
session .run ("pytest" , * session .posargs )
63
67
64
68
65
- @nox .session
69
+ @nox .session ( default = False )
66
70
def bump (session : nox .Session ) -> None :
67
71
"""
68
72
Set to a new version, use -- <version>, otherwise will use the latest version.
@@ -115,3 +119,7 @@ def bump(session: nox.Session) -> None:
115
119
session .log (
116
120
'Complete! Now run: gh pr create --fill --body "Created by running `nox -s bump -- --commit`"'
117
121
)
122
+
123
+
124
+ if __name__ == "__main__" :
125
+ nox .main ()
0 commit comments