Skip to content

Commit 9730ba2

Browse files
authored
Merge pull request numpy#26680 from ev-br/smoke-docs-followup
remove doctesting from refguide-check, add `spin check-tutorials`
2 parents dc93d9f + f87d191 commit 9730ba2

File tree

9 files changed

+107
-612
lines changed

9 files changed

+107
-612
lines changed

.circleci/config.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,10 @@ jobs:
9595
# destination: neps
9696

9797
- run:
98-
name: run doctests on documentation
98+
name: run refguide-check
9999
command: |
100100
. venv/bin/activate
101-
# Note: keep these two checks separate, because they seem to
102-
# influence each other through changing global state (e.g., via
103-
# `np.polynomial.set_default_printstyle`)
104-
python tools/refguide_check.py --rst
105-
python tools/refguide_check.py --doctests
101+
python tools/refguide_check.py -v
106102
107103
- persist_to_workspace:
108104
root: ~/repo

.github/workflows/linux.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ jobs:
181181
- name: Check docstests
182182
shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"'
183183
run: |
184-
pip install scipy-doctest hypothesis matplotlib scipy pytz
184+
pip install scipy-doctest hypothesis matplotlib scipy pytz pandas
185185
spin check-docs -v
186+
spin check-tutorials -v
186187
187188
sdist:
188189
needs: [smoke_test]

.spin/cmds.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,75 @@ def check_docs(ctx, pytest_args, n_jobs, verbose, *args, **kwargs):
352352
ctx.forward(meson.test)
353353

354354

355+
@click.command()
356+
@click.argument("pytest_args", nargs=-1)
357+
@click.option(
358+
"-j",
359+
"n_jobs",
360+
metavar='N_JOBS',
361+
default="1",
362+
help=("Number of parallel jobs for testing. "
363+
"Can be set to `auto` to use all cores.")
364+
)
365+
@click.option(
366+
'--verbose', '-v', is_flag=True, default=False
367+
)
368+
@click.pass_context
369+
def check_tutorials(ctx, pytest_args, n_jobs, verbose, *args, **kwargs):
370+
"""🔧 Run doctests of user-facing rst tutorials.
371+
372+
To test all tutorials in the numpy/doc/source/user/ directory, use
373+
374+
spin check-tutorials
375+
376+
To run tests on a specific RST file:
377+
378+
\b
379+
spin check-tutorials numpy/doc/source/user/absolute-beginners.rst
380+
381+
\b
382+
Note:
383+
-----
384+
385+
\b
386+
- This command only runs doctests and skips everything under tests/
387+
- This command only doctests public objects: those which are accessible
388+
from the top-level `__init__.py` file.
389+
390+
""" # noqa: E501
391+
# handle all of
392+
# - `spin check-tutorials` (pytest_args == ())
393+
# - `spin check-tutorials path/to/rst`, and
394+
# - `spin check-tutorials path/to/rst -- --durations=3`
395+
if (not pytest_args) or all(arg.startswith('-') for arg in pytest_args):
396+
pytest_args = ('numpy/doc/source/user',) + pytest_args
397+
398+
# make all paths relative to the numpy source folder
399+
pytest_args = tuple(
400+
str(curdir / '..' / '..' / arg) if not arg.startswith('-') else arg
401+
for arg in pytest_args
402+
)
403+
404+
if (n_jobs != "1") and ('-n' not in pytest_args):
405+
pytest_args = ('-n', str(n_jobs)) + pytest_args
406+
407+
if verbose:
408+
pytest_args = ('-v',) + pytest_args
409+
410+
# turn doctesting on:
411+
doctest_args = (
412+
'--doctest-glob=*rst',
413+
)
414+
415+
pytest_args = pytest_args + doctest_args
416+
417+
ctx.params['pytest_args'] = pytest_args
418+
419+
for extra_param in ('n_jobs', 'verbose'):
420+
del ctx.params[extra_param]
421+
422+
ctx.forward(meson.test)
423+
355424

356425
# From scipy: benchmarks/benchmarks/common.py
357426
def _set_mem_rlimit(max_mem=None):

doc/TESTS.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ Testing a subset of NumPy::
7474

7575
For detailed info on testing, see :ref:`testing-builds`
7676

77+
78+
Running doctests
79+
----------------
80+
81+
NumPy documentation contains code examples, "doctests". To check that the examples
82+
are correct, install the ``scipy-doctest`` package::
83+
84+
$ pip install scipy-doctest
85+
86+
and run one of::
87+
88+
$ spin check-docs -v
89+
$ spin check-docs numpy/linalg
90+
$ spin check-docs -- -k 'det and not slogdet'
91+
92+
Note that the doctests are not run when you use ``spin test``.
93+
94+
7795
Other methods of running tests
7896
------------------------------
7997

doc/source/dev/development_environment.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ argument to pytest::
114114

115115
$ spin test -v -t numpy/_core/tests/test_multiarray.py -- -k "MatMul and not vector"
116116

117+
To run "doctests" -- to check that the code examples in the documentation is correct --
118+
use the `check-docs` spin command. It relies on the `scipy-docs` package, which
119+
provides several additional features on top of the standard library ``doctest``
120+
package. Install ``scipy-doctest`` and run one of::
121+
122+
$ spin check-docs -v
123+
$ spin check-docs numpy/linalg
124+
$ spin check-docs -v -- -k 'det and not slogdet'
125+
117126
.. note::
118127

119128
Remember that all tests of NumPy should pass before committing your changes.

doc/source/user/how-to-partition.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ fully-dimensional result array.
244244
::
245245

246246
>>> np.ogrid[0:4, 0:6]
247-
[array([[0],
247+
(array([[0],
248248
[1],
249249
[2],
250-
[3]]), array([[0, 1, 2, 3, 4, 5]])]
250+
[3]]), array([[0, 1, 2, 3, 4, 5]]))
251251

252252
All three methods described here can be used to evaluate function values on a
253253
grid.

numpy/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ def warnings_errors_and_rng(test=None):
210210
'c-info.ufunc-tutorial.rst': '',
211211
'basics.interoperability.rst': 'needs pandas',
212212
'basics.dispatch.rst': 'errors out in /testing/overrides.py',
213-
'basics.subclassing.rst': '.. testcode:: admonitions not understood'
213+
'basics.subclassing.rst': '.. testcode:: admonitions not understood',
214+
'misc.rst': 'manipulates warnings',
214215
}
215216

216217
# ignores are for things fail doctest collection (optionals etc)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ cli = 'vendored-meson/meson/meson.py'
211211
".spin/cmds.py:docs",
212212
".spin/cmds.py:changelog",
213213
".spin/cmds.py:notes",
214-
".spin/cmds.py:check_docs"
214+
".spin/cmds.py:check_docs",
215+
".spin/cmds.py:check_tutorials",
215216
]
216217
"Metrics" = [".spin/cmds.py:bench"]

0 commit comments

Comments
 (0)