Skip to content

Commit fd2122a

Browse files
committed
Add all keyword to validation_check configuration.
More flexibility in configuring which validation checks to run during sphinx build. If 'all' is present, treat the rest of the set as a blocklist, else an allowlist.
1 parent 0cc6277 commit fd2122a

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

doc/conf.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,7 @@
8686
numpydoc_xref_ignore = {'optional', 'type_without_description', 'BadException'}
8787
# Run docstring validation as part of build process
8888
numpydoc_validate = True
89-
numpydoc_validation_checks = {
90-
"GL06", # Unknown section name
91-
"GL07", # Sections in wrong order
92-
"GL08", # Object missing docstring
93-
"PR01", # Missing parameters
94-
"PR02", # Unknown parameters
95-
"PR03", # Incorrect parameter ordering
96-
"PR10", # Missing colon between parameter name and type
97-
"RT01", # No returns section
98-
"SA01", # Missing See Also section
99-
"EX01", # Missing Examples section
100-
}
89+
numpydoc_validation_checks = {"all", "GL01", "SA04", "RT03"}
10190

10291
# The language for content autogenerated by Sphinx. Refer to documentation
10392
# for a list of supported languages.

doc/install.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,25 @@ numpydoc_validate : bool
102102
numpydoc_validation_checks : set
103103
The set of validation checks to report during the sphinx build process.
104104
Only has an effect when ``numpydoc_validate = True``.
105-
By default, report warnings from all the validation checks provided by the
106-
:doc:`validation` module.
105+
If ``"all"`` is in the set, then the results of all of the
106+
:ref:`built-in validation checks <validation_checks>` are reported.
107+
If the set includes ``"all"`` and additional error codes, then all
108+
validation checks *except* the listed error codes will be run.
109+
If the set contains *only* individual error codes, then only those checks
110+
will be run.
111+
For example::
112+
113+
# Report warnings for all validation checks
114+
numpydoc_validation_checks = {"all"}
115+
116+
# Report warnings for all checks *except* for GL01, GL02, and GL05
117+
numpydoc_validation_checks = {"all", "GL01", "GL02", "GL05"}
118+
119+
# Only report warnings for the SA01 and EX01 checks
120+
numpydoc_validation_checks = {"SA01", "EX01"}
121+
122+
The default is an empty set, thus no warnings from docstring validation
123+
are reported.
107124
numpydoc_edit_link : bool
108125
.. deprecated:: 0.7.0
109126

doc/validation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ For an exhaustive validation of the formatting of the docstring, use the
1616
incorrect capitalization, wrong order of the sections, and many other
1717
issues.
1818

19+
.. _validation_checks:
20+
1921
Built-in Validation Checks
2022
--------------------------
2123

numpydoc/numpydoc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
raise RuntimeError("Sphinx 1.6.5 or newer is required")
3535

3636
from .docscrape_sphinx import get_doc_object
37-
from .validate import validate
37+
from .validate import validate, ERROR_MSGS
3838
from .xref import DEFAULT_LINKS
3939
from . import __version__
4040

@@ -298,6 +298,12 @@ def update_config(app, config=None):
298298
numpydoc_xref_aliases_complete[key] = value
299299
config.numpydoc_xref_aliases_complete = numpydoc_xref_aliases_complete
300300

301+
# Processing to determine whether numpydoc_validation_checks is treated
302+
# as a blocklist or allowlist
303+
if "all" in config.numpydoc_validation_checks:
304+
block = deepcopy(config.numpydoc_validation_checks)
305+
config.numpydoc_validation_checks = set(ERROR_MSGS.keys()) - block
306+
301307

302308
# ------------------------------------------------------------------------------
303309
# Docstring-mangling domains

0 commit comments

Comments
 (0)