Skip to content

Commit 1472c6f

Browse files
committed
Add mechanism for validation check selection.
Adds a config option with a set to allow users to select which validation checks are used. Default is an empty set, which means none of the validation checks raise warnings during the build process. Add documentation for new option and activate in the doc build.
1 parent 22c56f3 commit 1472c6f

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

doc/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@
8484
version = re.sub(r'(\.dev\d+).*?$', r'\1', version)
8585
numpydoc_xref_param_type = True
8686
numpydoc_xref_ignore = {'optional', 'type_without_description', 'BadException'}
87+
# Run docstring validation as part of build process
8788
numpydoc_validate = True
89+
# Report warnings from all build-in validation checks
90+
from numpydoc.validate import ERROR_MSGS
91+
numpydoc_validation_checks = set(ERROR_MSGS.keys())
8892

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

doc/install.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ numpydoc_xref_ignore : set or ``"all"``
9999
numpydoc_validate : bool
100100
Whether or not to run docstring validation during the sphinx-build process.
101101
Default is ``False``.
102+
numpydoc_validation_checks : set
103+
The set of validation checks to report during the sphinx build process.
104+
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.
102107
numpydoc_edit_link : bool
103108
.. deprecated:: 0.7.0
104109

doc/validation.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ For an exhaustive validation of the formatting of the docstring, use the
1515
``--validate`` parameter. This will report the errors detected, such as
1616
incorrect capitalization, wrong order of the sections, and many other
1717
issues.
18+
19+
Built-in Validation Checks
20+
--------------------------
21+
22+
The `~numpydoc.validation` module provides a mapping with all of the checks
23+
that are run as part of the validation procedure.
24+
The mapping is of the form: ``error_code : <explanation>`` where ``error_code``
25+
provides a shorthand for the check being run, and ``<explanation>`` provides
26+
a more detailed message. For example::
27+
28+
"EX01" : "No examples section found"
29+
30+
The full mapping of validation checks is given below.
31+
32+
.. literalinclude:: ../numpydoc/validate.py
33+
:lines: 36-90

numpydoc/numpydoc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,14 @@ def mangle_docstrings(app, what, name, obj, options, lines):
176176

177177
# TODO: validation only applies to non-module docstrings?
178178
if app.config.numpydoc_validate:
179+
# TODO: Currently, all validation checks are run and only those
180+
# selected via config are reported. It would be more efficient to
181+
# only run the selected checks.
179182
errors = validate(doc)["errors"]
180183
for err in errors:
181-
logger.warning(err)
184+
# err[0] = error code
185+
if err[0] in app.config.numpydoc_validation_checks:
186+
logger.warning(err)
182187

183188

184189
if (app.config.numpydoc_edit_link and hasattr(obj, '__name__') and
@@ -263,6 +268,7 @@ def setup(app, get_doc_object_=get_doc_object):
263268
app.add_config_value('numpydoc_xref_aliases', dict(), True)
264269
app.add_config_value('numpydoc_xref_ignore', set(), True)
265270
app.add_config_value('numpydoc_validate', False, True)
271+
app.add_config_value('numpydoc_validation_checks', set(), True)
266272

267273
# Extra mangling domains
268274
app.add_domain(NumpyPythonDomain)

0 commit comments

Comments
 (0)