1
+ #!/usr/bin/env -S uv run -q
2
+ # /// script
3
+ # dependencies = ["nox>=2025.2.9"]
4
+ # ///
5
+
1
6
from __future__ import annotations
2
7
3
8
import argparse
7
12
8
13
import nox
9
14
10
- nox .needs_version = ">=2024.3.2"
11
- nox .options .sessions = ["lint" , "tests" ]
15
+ nox .needs_version = ">=2025.2.9"
12
16
nox .options .default_venv_backend = "uv|virtualenv"
13
17
14
18
DIR = Path (__file__ ).parent .resolve ()
@@ -44,7 +48,7 @@ def tests(session):
44
48
session .run ("pytest" , * args , * session .posargs )
45
49
46
50
47
- @nox .session (venv_backend = "uv" )
51
+ @nox .session (venv_backend = "uv" , default = False )
48
52
def minimums (session ):
49
53
"""
50
54
Run with the minimum dependencies.
@@ -54,7 +58,7 @@ def minimums(session):
54
58
session .run ("pytest" , * session .posargs )
55
59
56
60
57
- @nox .session
61
+ @nox .session ( default = False )
58
62
def regenerate (session ):
59
63
"""
60
64
Regenerate MPL images.
@@ -67,26 +71,40 @@ def regenerate(session):
67
71
session .run ("pytest" , "--mpl-generate-path=tests/baseline" , * session .posargs )
68
72
69
73
70
- @nox .session (reuse_venv = True )
74
+ @nox .session (reuse_venv = True , default = False )
71
75
def docs (session : nox .Session ) -> None :
72
76
"""
73
- Build the docs. Pass "--serve " to serve .
77
+ Build the docs. Use "--non-interactive " to avoid serving. Pass "-b linkcheck" to check links .
74
78
"""
75
79
76
80
parser = argparse .ArgumentParser ()
77
- parser .add_argument ("--serve" , action = "store_true" , help = "Serve after building" )
78
- args = parser .parse_args (session .posargs )
81
+ parser .add_argument (
82
+ "-b" , dest = "builder" , default = "html" , help = "Build target (default: html)"
83
+ )
84
+ args , posargs = parser .parse_known_args (session .posargs )
85
+
86
+ serve = args .builder == "html" and session .interactive
87
+ extra_installs = ["sphinx-autobuild" ] if serve else []
88
+ session .install ("-e.[docs]" , * extra_installs )
79
89
80
- session .install ("-e" , ".[docs]" )
81
90
session .chdir ("docs" )
82
- session .run ("sphinx-build" , "-M" , "html" , "." , "_build" )
83
91
84
- if args .serve :
85
- print ("Launching docs at http://localhost:8000/ - use Ctrl-C to quit" )
86
- session .run ("python" , "-m" , "http.server" , "8000" , "-d" , "_build/html" )
92
+ shared_args = (
93
+ "-n" , # nitpicky mode
94
+ "-T" , # full tracebacks
95
+ f"-b={ args .builder } " ,
96
+ "." ,
97
+ f"_build/{ args .builder } " ,
98
+ * posargs ,
99
+ )
87
100
101
+ if serve :
102
+ session .run ("sphinx-autobuild" , "--open-browser" , * shared_args )
103
+ else :
104
+ session .run ("sphinx-build" , "--keep-going" , * shared_args )
88
105
89
- @nox .session (reuse_venv = True )
106
+
107
+ @nox .session (reuse_venv = True , default = False )
90
108
def build_api_docs (session : nox .Session ) -> None :
91
109
"""
92
110
Build (regenerate) API docs.
@@ -105,18 +123,18 @@ def build_api_docs(session: nox.Session) -> None:
105
123
)
106
124
107
125
108
- @nox .session (reuse_venv = True )
126
+ @nox .session (reuse_venv = True , default = False )
109
127
def build (session ):
110
128
"""
111
129
Build an SDist and wheel.
112
130
"""
113
131
114
132
args = [] if shutil .which ("uv" ) else ["uv" ]
115
- session .install ("build==1.2.0 " , * args )
133
+ session .install ("build" , * args )
116
134
session .run ("python" , "-m" , "build" , "--installer=uv" )
117
135
118
136
119
- @nox .session ()
137
+ @nox .session (default = False )
120
138
def boost (session ):
121
139
"""
122
140
Build against latest boost-histogram.
@@ -139,3 +157,7 @@ def boost(session):
139
157
session .install ("-e.[test,plot]" , "pip" )
140
158
session .run ("pip" , "list" )
141
159
session .run ("pytest" , * session .posargs )
160
+
161
+
162
+ if __name__ == "__main__" :
163
+ nox .main ()
0 commit comments