Skip to content

Commit 40269ba

Browse files
committed
Refine additions to docs.
1 parent ddb7b49 commit 40269ba

File tree

2 files changed

+75
-37
lines changed

2 files changed

+75
-37
lines changed

doc/install.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ numpydoc_validation_overrides : dict
142142
A dictionary mapping :ref:`validation checks <validation_checks>` to a
143143
container of strings using :py:mod:`re` syntax specifying patterns to
144144
ignore for docstring validation.
145-
For example, to skip the ``SS02`` check for docstrings starting with
146-
the word ``Process``::
145+
For example, the following skips the ``SS02`` check for docstrings
146+
starting with the word ``Process``::
147147

148148
numpydoc_validation_overrides = {"SS02": [r'^Process ']}
149149

doc/validation.rst

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Validation
33
==========
44

5+
.. _pre_commit_hook:
6+
57
Docstring Validation using Pre-Commit Hook
68
------------------------------------------
79

@@ -27,42 +29,50 @@ and ``setup.cfg`` are supported; however, if the project contains both
2729
you must use the ``pyproject.toml`` file. The example below configures
2830
the pre-commit hook as follows:
2931

30-
* ``checks``: Run all checks except ``EX01``, ``SA01``, and ``ES01`` (using the
31-
same logic as the :ref:`validation during Sphinx build
32-
<_validation_during_sphinx_build>`).
33-
* ``exclude``: Don't report any issues on anything matching the regular
34-
regular expressions ``\.undocumented_method$`` or ``\.__repr__$``.
32+
* ``checks``: Report findings on all checks except ``EX01``, ``SA01``, and
33+
``ES01`` (using the same logic as the :ref:`validation during Sphinx build
34+
<validation_during_sphinx_build>` for ``numpydoc_validation_checks``).
35+
* ``exclude``: Don't report issues on objects matching any of the regular
36+
regular expressions ``\.undocumented_method$`` or ``\.__repr__$``. This
37+
maps to ``numpydoc_validation_exclude`` from the
38+
:ref:`Sphinx build configuration <validation_during_sphinx_build>`.
3539
* ``override_SS05``: Allow docstrings to start with "Process ", "Assess ",
3640
or "Access ". To override different checks, add a field for each code in
37-
the form of ``override_<code>``.
41+
the form of ``override_<code>`` with a collection of regular expression(s)
42+
to search for in the contents of a docstring, not the object name. This
43+
maps to ``numpydoc_validation_overrides`` from the
44+
:ref:`Sphinx build configuration <validation_during_sphinx_build>`.
3845

3946
``pyproject.toml``::
4047

4148
[tool.numpydoc_validation]
4249
checks = [
43-
"all", # run all checks, except the below
50+
"all", # report on all checks, except the below
4451
"EX01",
4552
"SA01",
4653
"ES01",
4754
]
48-
exclude = [
55+
exclude = [ # don't report on objects that match any of these regex
4956
'\.undocumented_method$',
5057
'\.__repr__$',
5158
]
52-
override_SS05 = [
53-
'^Process',
54-
'^Assess',
55-
'^Access',
59+
override_SS05 = [ # override SS05 to allow docstrings starting with these words
60+
'^Process ',
61+
'^Assess ',
62+
'^Access ',
5663
]
5764

5865
``setup.cfg``::
5966

6067
[tool:numpydoc_validation]
6168
checks = all,EX01,SA01,ES01
6269
exclude = \.undocumented_method$,\.__repr__$
63-
override_SS05 = ^Process,^Assess,^Access
70+
override_SS05 = ^Process ,^Assess ,^Access ,
71+
72+
In addition to the above, :ref:`inline ignore comments <inline_ignore_comments>`
73+
can be used to ignore findings on a case by case basis.
6474

65-
If any issues are found when commiting, a report is printed out and the
75+
If any issues are found when commiting, a report is printed out, and the
6676
commit is halted:
6777

6878
.. code-block:: output
@@ -80,7 +90,9 @@ commit is halted:
8090
| src/pkg/module.py:33 | module.MyClass.parse | RT03 | Return value has no description |
8191
+----------------------+----------------------+---------+--------------------------------------+
8292
83-
See below for a full listing of checks.
93+
See :ref:`below <validation_checks>` for a full listing of checks.
94+
95+
.. _validation_via_cli:
8496

8597
Docstring Validation using Python
8698
---------------------------------
@@ -98,15 +110,15 @@ For an exhaustive validation of the formatting of the docstring, use the
98110
``--validate`` parameter. This will report the errors detected, such as
99111
incorrect capitalization, wrong order of the sections, and many other
100112
issues. Note that this will honor :ref:`inline ignore comments <inline_ignore_comments>`,
101-
but will not look for any configuration like the pre-commit hook or Sphinx
102-
extension do.
113+
but will not look for any configuration like the :ref:`pre-commit hook <pre_commit_hook>`
114+
or :ref:`Sphinx extension <validation_during_sphinx_build>` do.
103115

104116
.. _validation_during_sphinx_build:
105117

106118
Docstring Validation during Sphinx Build
107119
----------------------------------------
108120

109-
It is also possible to run docstring validation as part of the sphinx build
121+
It is also possible to run docstring validation as part of the Sphinx build
110122
process.
111123
This behavior is controlled by the ``numpydoc_validation_checks`` configuration
112124
parameter in ``conf.py``.
@@ -116,7 +128,7 @@ following line to ``conf.py``::
116128

117129
numpydoc_validation_checks = {"PR01"}
118130

119-
This will cause a sphinx warning to be raised for any (non-module) docstring
131+
This will cause a Sphinx warning to be raised for any (non-module) docstring
120132
that has undocumented parameters in the signature.
121133
The full set of validation checks can be activated by::
122134

@@ -132,6 +144,48 @@ special keyword ``"all"``::
132144
# Report warnings for all validation checks except GL01, GL02, and GL05
133145
numpydoc_validation_checks = {"all", "GL01", "GL02", "GL05"}
134146

147+
In addition, you can exclude any findings on certain objects with
148+
``numpydoc_validation_exclude``, which maps to ``exclude`` in the
149+
:ref:`pre-commit hook setup <pre_commit_hook>`::
150+
151+
# don't report on objects that match any of these regex
152+
numpydoc_validation_exclude = [
153+
'\.undocumented_method$',
154+
'\.__repr__$',
155+
]
156+
157+
Overrides based on docstring contents are also supported, but the structure
158+
is slightly different than the :ref:`pre-commit hook setup <pre_commit_hook>`::
159+
160+
numpydoc_validation_overrides = {
161+
"SS02": [ # override SS05 to allow docstrings starting with these words
162+
'^Process ',
163+
'^Assess ',
164+
'^Access ',
165+
]
166+
}
167+
168+
.. _inline_ignore_comments:
169+
170+
Ignoring Validation Checks with Inline Comments
171+
-----------------------------------------------
172+
173+
Sometimes you only want to ignore a specific check or set of checks for a
174+
specific piece of code. This level of fine-tuned control is provided via
175+
inline comments:
176+
177+
.. code-block:: python
178+
179+
class SomeClass: # numpydoc ignore=EX01,SA01,ES01
180+
"""This is the docstring for SomeClass."""
181+
182+
def __init__(self): # numpydoc ignore=GL08
183+
pass
184+
185+
This is supported by the :ref:`CLI <validation_via_cli>`,
186+
:ref:`pre-commit hook <pre_commit_hook>`, and
187+
:ref:`Sphinx extension <validation_during_sphinx_build>`.
188+
135189
.. _validation_checks:
136190

137191
Built-in Validation Checks
@@ -150,19 +204,3 @@ The full mapping of validation checks is given below.
150204
.. literalinclude:: ../numpydoc/validate.py
151205
:start-after: start-err-msg
152206
:end-before: end-err-msg
153-
154-
.. _inline_ignore_comments:
155-
156-
Ignoring Validation Checks with Inline Comments
157-
-----------------------------------------------
158-
159-
For more fine-tuned control, you can also include inline comments
160-
to ignore certain checks:
161-
162-
.. code-block:: python
163-
164-
class SomeClass: # numpydoc ignore=EX01,SA01,ES01
165-
"""This is the docstring for SomeClass."""
166-
167-
def __init__(self): # numpydoc ignore=GL08
168-
pass

0 commit comments

Comments
 (0)