@@ -57,10 +57,11 @@ def find_my_name() -> str:
57
57
raise ValueError (msg )
58
58
59
59
60
- package : Final = find_my_name ()
61
- locations : Final = f"src/{ package } " , "tests" , "./noxfile.py" , "docs/source/conf.py"
60
+ package : Final [ str ] = find_my_name ()
61
+ locations : Final [ tuple [ str , ...]] = f"src/{ package } " , "tests" , "./noxfile.py" , "docs/source/conf.py"
62
62
63
- supported_pythons : Final = "3.10" , "3.11" , "3.12"
63
+ supported_pythons : Final [tuple [str , ...]] = "3.10" , "3.11" , "3.12"
64
+ default_python : Final [str ] = "3.12"
64
65
65
66
66
67
def _update_hook (hook : Path , virtualenv : str , s : Session ) -> None :
@@ -77,7 +78,7 @@ def _update_hook(hook: Path, virtualenv: str, s: Session) -> None:
77
78
{ s .bin !r} ,
78
79
os.environ.get("PATH", ""),
79
80
))
80
- """ ,
81
+ """
81
82
)
82
83
lines .insert (1 , header )
83
84
hook .write_text ("\n " .join (lines ))
@@ -102,23 +103,15 @@ def activate_virtualenv_in_precommit_hooks(s: Session) -> None:
102
103
return
103
104
104
105
for hook in filter (
105
- lambda x : not x .name .endswith (".sample" ) and x .is_file (),
106
- hook_dir .iterdir (),
106
+ lambda x : not x .name .endswith (".sample" ) and x .is_file (), hook_dir .iterdir ()
107
107
):
108
108
_update_hook (hook , virtualenv , s )
109
109
110
110
111
- @session (name = "pre-commit" )
111
+ @session (name = "pre-commit" , python = default_python )
112
112
def precommit (s : Session ) -> None :
113
113
"""Lint using pre-commit."""
114
- s .run (
115
- "poetry" ,
116
- "install" ,
117
- "--no-root" ,
118
- "--only" ,
119
- "pre_commit,isort,black,ruff" ,
120
- external = True ,
121
- )
114
+ s .run ("poetry" , "install" , "--no-root" , "--only" , "pre_commit,ruff" , external = True )
122
115
args = s .posargs or ["run" , "--all-files" , "--show-diff-on-failure" ]
123
116
s .run ("pre-commit" , * args )
124
117
if args and args [0 ] == "install" :
@@ -128,13 +121,7 @@ def precommit(s: Session) -> None:
128
121
@session (python = supported_pythons )
129
122
def tests (s : Session ) -> None :
130
123
"""Run the test suite."""
131
- s .run (
132
- "poetry" ,
133
- "install" ,
134
- "--only" ,
135
- "main,test,xdoctest,coverage" ,
136
- external = True ,
137
- )
124
+ s .run ("poetry" , "install" , "--only" , "main,test,xdoctest,coverage" , external = True )
138
125
try :
139
126
s .run ("coverage" , "run" , "--parallel" , "-m" , "pytest" , * s .posargs )
140
127
finally :
@@ -149,14 +136,7 @@ def coverage(s: Session) -> None:
149
136
To obtain html report run
150
137
nox -rs coverage -- html
151
138
"""
152
- s .run (
153
- "poetry" ,
154
- "install" ,
155
- "--no-root" ,
156
- "--only" ,
157
- "coverage" ,
158
- external = True ,
159
- )
139
+ s .run ("poetry" , "install" , "--no-root" , "--only" , "coverage" , external = True )
160
140
161
141
if not s .posargs and any (Path ().glob (".coverage.*" )):
162
142
s .run ("coverage" , "combine" )
@@ -168,88 +148,22 @@ def coverage(s: Session) -> None:
168
148
@session
169
149
def typeguard (s : Session ) -> None :
170
150
"""Runtime type checking using Typeguard."""
171
- s .run (
172
- "poetry" ,
173
- "install" ,
174
- "--only" ,
175
- "main,test,typeguard" ,
176
- external = True ,
177
- )
151
+ s .run ("poetry" , "install" , "--only" , "main,test,typeguard" , external = True )
178
152
s .run ("pytest" , "--typeguard-packages=src" , * s .posargs , external = True )
179
153
180
154
181
- @session
182
- def isort (s : Session ) -> None :
183
- """Organize imports."""
184
- search_patterns = [
185
- "*.py" ,
186
- f"src/{ package } /*.py" ,
187
- "tests/*.py" ,
188
- "benchmarks/*.py" ,
189
- "profiles/*.py" ,
190
- "adhoc/*.py" ,
191
- ]
192
- cwd = Path .cwd ()
193
- files_to_process : list [str ] = [str (x ) for p in search_patterns for x in cwd .glob (p )]
194
- if files_to_process :
195
- s .run (
196
- "poetry" ,
197
- "install" ,
198
- "--no-root" ,
199
- "--only" ,
200
- "isort" ,
201
- external = True ,
202
- )
203
- s .run (
204
- "isort" ,
205
- "--check" ,
206
- "--diff" ,
207
- * files_to_process ,
208
- external = True ,
209
- )
210
-
211
-
212
- @session
213
- def black (s : Session ) -> None :
214
- """Run black code formatter."""
215
- s .run (
216
- "poetry" ,
217
- "install" ,
218
- "--no-root" ,
219
- "--only" ,
220
- "black" ,
221
- external = True ,
222
- )
223
- args = s .posargs or locations
224
- s .run ("black" , * args )
225
-
226
-
227
155
@session
228
156
def lint (s : Session ) -> None :
229
157
"""Lint using flake8."""
230
- s .run (
231
- "poetry" ,
232
- "install" ,
233
- "--no-root" ,
234
- "--only" ,
235
- "flake8" ,
236
- external = True ,
237
- )
158
+ s .run ("poetry" , "install" , "--no-root" , "--only" , "flake8" , external = True )
238
159
args = s .posargs or locations
239
160
s .run ("flake8" , * args )
240
161
241
162
242
163
@session
243
164
def mypy (s : Session ) -> None :
244
165
"""Type-check using mypy."""
245
- s .run (
246
- "poetry" ,
247
- "install" ,
248
- "--no-root" ,
249
- "--only" ,
250
- "main,mypy" ,
251
- external = True ,
252
- )
166
+ s .run ("poetry" , "install" , "--no-root" , "--only" , "main,mypy" , external = True )
253
167
args = s .posargs or ["src" , "docs/source/conf.py" ]
254
168
s .run ("mypy" , * args )
255
169
@@ -258,46 +172,35 @@ def mypy(s: Session) -> None:
258
172
s .run ("mypy" , f"--python-executable={ sys .executable } " , "noxfile.py" )
259
173
260
174
261
- @session (python = "3.11" )
175
+ @session (python = default_python )
262
176
def xdoctest (s : Session ) -> None :
263
177
"""Run examples with xdoctest."""
264
- s .run (
265
- "poetry" ,
266
- "install" ,
267
- "--no-root" ,
268
- "--only" ,
269
- "main,xdoctest" ,
270
- external = True ,
271
- )
272
- args = s .posargs or ["--quiet" , "-m" , f"src/{ package } " ]
178
+ # Cannot use --no-root, because imports in __init__ require the package metadata
179
+ s .run ("poetry" , "install" , "--only" , "main,xdoctest" , external = True )
180
+ args = s .posargs or ["--silent" , "--style" , "google" , "-c" , "all" , "-m" , f"src/{ package } " ]
273
181
s .run ("python" , "-m" , "xdoctest" , * args )
274
182
275
183
276
- @session (python = "3.11" )
184
+ @session (python = default_python )
277
185
def ruff (s : Session ) -> None :
278
186
"""Run ruff linter."""
279
- s .run (
280
- "poetry" ,
281
- "install" ,
282
- "--no-root" ,
283
- "--only" ,
284
- "main,ruff" ,
285
- external = True ,
286
- )
287
- args = s .posargs or ["src" , "tests" ]
187
+ s .run ("poetry" , "install" , "--no-root" , "--only" , "ruff" , external = True )
188
+ args = s .posargs or ["check" , "src" , "tests" ]
189
+ s .run ("ruff" , * args )
190
+
191
+
192
+ @session (python = default_python , name = "ruff-format" )
193
+ def ruff_format (s : Session ) -> None :
194
+ """Run ruff formatter."""
195
+ s .run ("poetry" , "install" , "--no-root" , "--only" , "ruff" , external = True )
196
+ args = s .posargs or ["format" , "src" , "tests" ]
288
197
s .run ("ruff" , * args )
289
198
290
199
291
- @session (name = "docs-build" , python = "3.11" )
200
+ @session (name = "docs-build" , python = default_python )
292
201
def docs_build (s : Session ) -> None :
293
202
"""Build the documentation."""
294
- s .run (
295
- "poetry" ,
296
- "install" ,
297
- "--only" ,
298
- "main,docs" ,
299
- external = True ,
300
- )
203
+ s .run ("poetry" , "install" , "--only" , "main,docs" , external = True )
301
204
build_dir = Path ("docs" , "_build" )
302
205
if build_dir .exists ():
303
206
shutil .rmtree (build_dir )
@@ -306,16 +209,10 @@ def docs_build(s: Session) -> None:
306
209
s .run ("sphinx-build" , * args )
307
210
308
211
309
- @session (python = "3.11" )
212
+ @session (python = default_python )
310
213
def docs (s : Session ) -> None :
311
214
"""Build and serve the documentation with live reloading on file changes."""
312
- s .run (
313
- "poetry" ,
314
- "install" ,
315
- "--only" ,
316
- "main,docs,docs_auto" ,
317
- external = True ,
318
- )
215
+ s .run ("poetry" , "install" , "--only" , "main,docs,docs_auto" , external = True )
319
216
_clean_docs_build_folder ()
320
217
321
218
args = s .posargs or ["--open-browser" , "docs/source" , "docs/_build" ]
0 commit comments