@@ -141,11 +141,24 @@ def docs(*, parent_callback, **kwargs):
141141 default = default ,
142142 help = "Run tests with the given markers"
143143)
144+ @click .option (
145+ "-p" ,
146+ "--parallel-threads" ,
147+ metavar = 'PARALLEL_THREADS' ,
148+ default = "1" ,
149+ help = "Run tests many times in number of parallel threads under pytest-run-parallel."
150+ " Can be set to `auto` to use all cores. Use `spin test -p <number> -- "
151+ "--skip-thread-unsafe=true` to only run tests that can run in parallel. "
152+ "pytest-run-parallel must be installed to use."
153+ )
144154@spin .util .extend_command (spin .cmds .meson .test )
145- def test (* , parent_callback , pytest_args , tests , markexpr , ** kwargs ):
155+ def test (* , parent_callback , pytest_args , tests , markexpr , parallel_threads , ** kwargs ):
146156 """
147157 By default, spin will run `-m 'not slow'`. To run the full test suite, use
148158 `spin test -m full`
159+
160+ When pytest-run-parallel is avaliable, use `spin test -p auto` or
161+ `spin test -p <num_of_threads>` to run tests sequentional in parallel threads.
149162 """ # noqa: E501
150163 if (not pytest_args ) and (not tests ):
151164 pytest_args = ('--pyargs' , 'numpy' )
@@ -154,6 +167,9 @@ def test(*, parent_callback, pytest_args, tests, markexpr, **kwargs):
154167 if markexpr != "full" :
155168 pytest_args = ('-m' , markexpr ) + pytest_args
156169
170+ if parallel_threads != "1" :
171+ pytest_args = ('--parallel-threads' , parallel_threads ) + pytest_args
172+
157173 kwargs ['pytest_args' ] = pytest_args
158174 parent_callback (** {'pytest_args' : pytest_args , 'tests' : tests , ** kwargs })
159175
@@ -521,6 +537,46 @@ def mypy(ctx):
521537 ctx .forward (test )
522538
523539
540+ @click .command ()
541+ @click .option (
542+ '--concise' ,
543+ is_flag = True ,
544+ default = False ,
545+ help = "Concise output format" ,
546+ )
547+ @meson .build_dir_option
548+ def stubtest (* , concise : bool , build_dir : str ) -> None :
549+ """🧐 Run stubtest on NumPy's .pyi stubs
550+
551+ Requires mypy to be installed
552+ """
553+ click .get_current_context ().invoke (build )
554+ meson ._set_pythonpath (build_dir )
555+ print (f"{ build_dir = !r} " )
556+
557+ import sysconfig
558+ purellib = sysconfig .get_paths ()["purelib" ]
559+ print (f"{ purellib = !r} " )
560+
561+ stubtest_dir = curdir .parent / 'tools' / 'stubtest'
562+ mypy_config = stubtest_dir / 'mypy.ini'
563+ allowlists = [stubtest_dir / 'allowlist.txt' ]
564+ if sys .version_info >= (3 , 12 ):
565+ allowlists .append (stubtest_dir / 'allowlist_py312.txt' )
566+
567+ cmd = [
568+ 'stubtest' ,
569+ '--ignore-disjoint-bases' ,
570+ f'--mypy-config-file={ mypy_config } ' ,
571+ * (f'--allowlist={ allowlist } ' for allowlist in allowlists ),
572+ ]
573+ if concise :
574+ cmd .append ('--concise' )
575+ cmd .append ('numpy' )
576+
577+ spin .util .run (cmd )
578+
579+
524580@click .command (context_settings = {
525581 'ignore_unknown_options' : True
526582})
0 commit comments