@@ -161,6 +161,21 @@ def docs(ctx, sphinx_target, clean, first_build, jobs, *args, **kwargs):
161
161
"""
162
162
meson .docs .ignore_unknown_options = True
163
163
164
+ # See https://github.com/scientific-python/spin/pull/199
165
+ # Can be changed when spin updates to 0.11, and moved to pyproject.toml
166
+ if clean :
167
+ clean_dirs = [
168
+ './doc/build/' ,
169
+ './doc/source/reference/generated' ,
170
+ './doc/source/reference/random/bit_generators/generated' ,
171
+ './doc/source/reference/random/generated' ,
172
+ ]
173
+
174
+ for target_dir in clean_dirs :
175
+ if os .path .isdir (target_dir ):
176
+ print (f"Removing { target_dir !r} " )
177
+ shutil .rmtree (target_dir )
178
+
164
179
# Run towncrier without staging anything for commit. This is the way to get
165
180
# release notes snippets included in a local doc build.
166
181
cmd = ['towncrier' , 'build' , '--version' , '2.x.y' , '--keep' , '--draft' ]
@@ -258,6 +273,83 @@ def test(ctx, pytest_args, markexpr, n_jobs, tests, verbose, *args, **kwargs):
258
273
ctx .forward (meson .test )
259
274
260
275
276
+ @click .command ()
277
+ @click .argument ("pytest_args" , nargs = - 1 )
278
+ @click .option (
279
+ "-j" ,
280
+ "n_jobs" ,
281
+ metavar = 'N_JOBS' ,
282
+ default = "1" ,
283
+ help = ("Number of parallel jobs for testing. "
284
+ "Can be set to `auto` to use all cores." )
285
+ )
286
+ @click .option (
287
+ '--verbose' , '-v' , is_flag = True , default = False
288
+ )
289
+ @click .pass_context
290
+ def check_docs (ctx , pytest_args , n_jobs , verbose , * args , ** kwargs ):
291
+ """🔧 Run doctests of objects in the public API.
292
+
293
+ PYTEST_ARGS are passed through directly to pytest, e.g.:
294
+
295
+ spin check-docs -- --pdb
296
+
297
+ To run tests on a directory:
298
+
299
+ \b
300
+ spin check-docs numpy/linalg
301
+
302
+ To report the durations of the N slowest doctests:
303
+
304
+ spin check-docs -- --durations=N
305
+
306
+ To run doctests that match a given pattern:
307
+
308
+ \b
309
+ spin check-docs -- -k "slogdet"
310
+ spin check-docs numpy/linalg -- -k "det and not slogdet"
311
+
312
+ \b
313
+ Note:
314
+ -----
315
+
316
+ \b
317
+ - This command only runs doctests and skips everything under tests/
318
+ - This command only doctests public objects: those which are accessible
319
+ from the top-level `__init__.py` file.
320
+
321
+ """ # noqa: E501
322
+ try :
323
+ # prevent obscure error later
324
+ import scipy_doctest
325
+ except ModuleNotFoundError as e :
326
+ raise ModuleNotFoundError ("scipy-doctest not installed" ) from e
327
+ if (not pytest_args ):
328
+ pytest_args = ('numpy' ,)
329
+
330
+ if (n_jobs != "1" ) and ('-n' not in pytest_args ):
331
+ pytest_args = ('-n' , str (n_jobs )) + pytest_args
332
+
333
+ if verbose :
334
+ pytest_args = ('-v' ,) + pytest_args
335
+
336
+ # turn doctesting on:
337
+ doctest_args = (
338
+ '--doctest-modules' ,
339
+ '--doctest-collect=api'
340
+ )
341
+
342
+ pytest_args = pytest_args + doctest_args
343
+
344
+ ctx .params ['pytest_args' ] = pytest_args
345
+
346
+ for extra_param in ('n_jobs' , 'verbose' ):
347
+ del ctx .params [extra_param ]
348
+
349
+ ctx .forward (meson .test )
350
+
351
+
352
+
261
353
# From scipy: benchmarks/benchmarks/common.py
262
354
def _set_mem_rlimit (max_mem = None ):
263
355
"""
0 commit comments