2
2
Validation
3
3
==========
4
4
5
+ .. _pre_commit_hook :
6
+
5
7
Docstring Validation using Pre-Commit Hook
6
8
------------------------------------------
7
9
@@ -27,42 +29,50 @@ and ``setup.cfg`` are supported; however, if the project contains both
27
29
you must use the ``pyproject.toml `` file. The example below configures
28
30
the pre-commit hook as follows:
29
31
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 >`.
35
39
* ``override_SS05 ``: Allow docstrings to start with "Process ", "Assess ",
36
40
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 >`.
38
45
39
46
``pyproject.toml ``::
40
47
41
48
[tool.numpydoc_validation]
42
49
checks = [
43
- "all", # run all checks, except the below
50
+ "all", # report on all checks, except the below
44
51
"EX01",
45
52
"SA01",
46
53
"ES01",
47
54
]
48
- exclude = [
55
+ exclude = [ # don't report on objects that match any of these regex
49
56
'\.undocumented_method$',
50
57
'\.__repr__$',
51
58
]
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 ',
56
63
]
57
64
58
65
``setup.cfg ``::
59
66
60
67
[tool:numpydoc_validation]
61
68
checks = all,EX01,SA01,ES01
62
69
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.
64
74
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
66
76
commit is halted:
67
77
68
78
.. code-block :: output
@@ -80,7 +90,9 @@ commit is halted:
80
90
| src/pkg/module.py:33 | module.MyClass.parse | RT03 | Return value has no description |
81
91
+----------------------+----------------------+---------+--------------------------------------+
82
92
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 :
84
96
85
97
Docstring Validation using Python
86
98
---------------------------------
@@ -98,15 +110,15 @@ For an exhaustive validation of the formatting of the docstring, use the
98
110
``--validate `` parameter. This will report the errors detected, such as
99
111
incorrect capitalization, wrong order of the sections, and many other
100
112
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.
103
115
104
116
.. _validation_during_sphinx_build :
105
117
106
118
Docstring Validation during Sphinx Build
107
119
----------------------------------------
108
120
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
110
122
process.
111
123
This behavior is controlled by the ``numpydoc_validation_checks `` configuration
112
124
parameter in ``conf.py ``.
@@ -116,7 +128,7 @@ following line to ``conf.py``::
116
128
117
129
numpydoc_validation_checks = {"PR01"}
118
130
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
120
132
that has undocumented parameters in the signature.
121
133
The full set of validation checks can be activated by::
122
134
@@ -132,6 +144,48 @@ special keyword ``"all"``::
132
144
# Report warnings for all validation checks except GL01, GL02, and GL05
133
145
numpydoc_validation_checks = {"all", "GL01", "GL02", "GL05"}
134
146
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
+
135
189
.. _validation_checks :
136
190
137
191
Built-in Validation Checks
@@ -150,19 +204,3 @@ The full mapping of validation checks is given below.
150
204
.. literalinclude :: ../numpydoc/validate.py
151
205
:start-after: start-err-msg
152
206
: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