Skip to content

Commit 27c013f

Browse files
committed
Activate validation during sphinx-build.
Add a conf option to turn on/off. TODO: test
1 parent eac0a72 commit 27c013f

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
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+
numpydoc_validate = True
8788

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

numpydoc/numpydoc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +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
3738
from .xref import DEFAULT_LINKS
3839
from . import __version__
3940

@@ -173,6 +174,13 @@ def mangle_docstrings(app, what, name, obj, options, lines):
173174
logger.error('[numpydoc] While processing docstring for %r', name)
174175
raise
175176

177+
# TODO: validation only applies to non-module docstrings?
178+
if app.config.numpydoc_validate:
179+
errors = validate(doc)["errors"]
180+
for err in errors:
181+
logger.warn(err)
182+
183+
176184
if (app.config.numpydoc_edit_link and hasattr(obj, '__name__') and
177185
obj.__name__):
178186
if hasattr(obj, '__module__'):
@@ -254,6 +262,7 @@ def setup(app, get_doc_object_=get_doc_object):
254262
app.add_config_value('numpydoc_xref_param_type', False, True)
255263
app.add_config_value('numpydoc_xref_aliases', dict(), True)
256264
app.add_config_value('numpydoc_xref_ignore', set(), True)
265+
app.add_config_value('numpydoc_validate', False, True)
257266

258267
# Extra mangling domains
259268
app.add_domain(NumpyPythonDomain)

numpydoc/tests/test_numpydoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MockConfig():
1919
numpydoc_edit_link = False
2020
numpydoc_citation_re = '[a-z0-9_.-]+'
2121
numpydoc_attributes_as_param_list = True
22+
numpydoc_validate = False
2223

2324

2425
class MockBuilder():

numpydoc/tests/tinybuild/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
highlight_language = 'python3'
2323
numpydoc_class_members_toctree = False
2424
numpydoc_xref_param_type = True
25+
numpydoc_validate = True

numpydoc/validate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,10 @@ def validate(obj_name):
470470
they are validated, are not documented more than in the source code of this
471471
function.
472472
"""
473-
obj = Validator._load_obj(obj_name)
474-
doc = Validator(get_doc_object(obj))
473+
if isinstance(obj_name, str):
474+
doc = Validator(get_doc_object(Validator._load_obj(obj_name)))
475+
else:
476+
doc = Validator(obj_name)
475477

476478
errs = []
477479
if not doc.raw_doc:

0 commit comments

Comments
 (0)