Skip to content

Commit 4f8b39a

Browse files
authored
release: v1.7.2 (#220)
* fix: excessive whitespace in middle of line * test: fix failing tests * fix: space after field with no description * fix: wrapping reST section admonitions * doc: documentation for new argument * fix: not wrapping fields at proper wrap length * test: fix failing tests * fix: not considering field name in wrap length * fix: adding space in :meth: role with no link * fix: sphinx style wrapping fields with parentheses * fix: no summary description treated like summary * docs: update documentation * fix: adding blank space when no field body * chore: update version string for release --------- Signed-off-by: Doyle Rowland <[email protected]>
1 parent bd0b702 commit 4f8b39a

File tree

15 files changed

+685
-302
lines changed

15 files changed

+685
-302
lines changed

.github/workflows/do-prioritize-issues.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,19 @@ jobs:
2424
uses: weibullguy/get-labels-action@main
2525

2626
- name: Add High Urgency Labels
27-
if: |
28-
${{ (contains(steps.getlabels.outputs.labels, "C: convention") && contains (steps.getlabels.outputs.labels, "P: bug")) }}
27+
if: '${{ (contains(steps.getlabels.outputs.labels, "C: convention") && contains (steps.getlabels.outputs.labels, "P: bug")) }}'
2928
uses: andymckay/labeler@master
3029
with:
3130
add-labels: "U: high"
3231

3332
- name: Add Medium Urgency Labels
34-
if: |
35-
${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: convention") && contains(steps.getlabels.outputs.labels, "P: enhancement")) }}
33+
if: '${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: convention") && contains(steps.getlabels.outputs.labels, "P: enhancement")) }}'
3634
uses: andymckay/labeler@master
3735
with:
3836
add-labels: "U: medium"
3937

4038
- name: Add Low Urgency Labels
41-
if: |
42-
${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || contains(steps.getlabels.outputs.labels, "doc") || contains(steps.getlabels.outputs.labels, "chore") }}
39+
if: '${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || contains(steps.getlabels.outputs.labels, "doc") || contains(steps.getlabels.outputs.labels, "chore") }}'
4340
uses: andymckay/labeler@master
4441
with:
4542
add-labels: "U: low"

docs/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
# type: ignore
12
# Configuration file for the Sphinx documentation builder.
23
#
34
# For the full list of built-in configuration values, see the documentation:
45
# https://www.sphinx-doc.org/en/master/usage/configuration.html
56

67
# -- Project information -----------------------------------------------------
78
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
9+
"""Configuration file for the Sphinx documentation builder."""
810

911
project = "docformatter"
1012
copyright = "2022-2023, Steven Myint"
1113
author = "Steven Myint"
12-
release = "1.7.1"
14+
release = "1.7.2"
1315

1416
# -- General configuration ---------------------------------------------------
1517
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/source/configuration.rst

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,51 @@ automatically:
6868
* ``--wrap-descriptions`` is set to 88
6969
* ``--wrap-summaries`` is set to 88
7070

71-
All of these options can be overridden from the command line. Further, the
72-
``--pre-summary-space`` option only inserts a space before the summary when
73-
the summary begins with a double quote ("). For example:
71+
All of these options can be overridden from the command line or in the configuration
72+
file. Further, the ``--pre-summary-space`` option only inserts a space before the
73+
summary when the summary begins with a double quote ("). For example:
7474

7575
``"""This summary gets no space."""`` becomes ``"""This summary gets no space."""``
7676

7777
and
7878

7979
``""""This" summary does get a space."""`` becomes ``""" "This" summary does get a space."""``
8080

81-
The ``--style`` argument takes a string which is the name of the parameter
82-
list style you are using. Currently, only ``sphinx`` and ``epytext`` are recognized,
83-
but ``numpy`` and ``google`` are future styles. For the selected style, each line in
84-
the parameter lists will be wrapped at the ``--wrap-descriptions`` length as well as
85-
any portion of the elaborate description preceding the parameter list. Parameter lists
86-
that don't follow the passed style will cause the entire elaborate description to be
87-
ignored and remain unwrapped.
81+
The ``--style`` argument takes a string which is the name of the field list style you
82+
are using. Currently, only ``sphinx`` and ``epytext`` are recognized, but ``numpy``
83+
and ``google`` are future styles. For the selected style, each line in the field lists
84+
will be wrapped at the ``--wrap-descriptions`` length as well as any portion of the
85+
elaborate description preceding the parameter list. Field lists that don't follow the
86+
passed style will cause the entire elaborate description to be ignored and remain
87+
unwrapped.
88+
89+
A Note on reST Header Adornments Regex
90+
--------------------------------------
91+
``docformatter-1.7.2`` added a new option ``--rest-section-adorns``. This allows for
92+
setting the characters used as overline and underline adornments for reST section
93+
headers. Per the `ReStructuredText Markup Specification <https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#sections>`_,
94+
the following are all valid adornment characters,
95+
96+
.. code-block::
97+
98+
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
99+
100+
Thus, the default regular expression ``[!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]{4,}``
101+
looks for any of these characters appearing at least four times in a row. Note that the
102+
list of valid adornment characters includes the double quote (") and the greater-than
103+
sign (>). Four repetitions was selected because:
104+
105+
* Docstrings open and close with triple double quotes.
106+
* Doctests begin with >>>.
107+
* It would be rare for a section header to consist of fewer than four characters.
108+
109+
The user can override this default list of characters by passing a regex from the
110+
command line or setting the ``rest-section-adorns`` option in the configuration file.
111+
It may be usefule to set this regex to only include the subset of characters you
112+
actually use in your docstrings. For example, to only recognize the recommended list
113+
in the ReStructuredText Markup Specification, the following regular expression would
114+
be used:
115+
116+
.. code-block::
117+
118+
[=-`:.'"~^_*+#]{4,}

docs/source/requirements.rst

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ Docstring Style
5757
There are at least four "flavors" of docstrings in common use today;
5858
Epytext, Sphinx, NumPy, and Google. Each of these docstring flavors follow the
5959
PEP 257 *convention* requirements. What differs between the three docstring
60-
flavors is the reST syntax used in the parameter description of the multi-line
61-
docstring.
60+
flavors is the reST syntax used in the field list of the multi-line docstring.
6261

6362
For example, here is how each syntax documents function arguments.
6463

@@ -97,11 +96,10 @@ syntactical directives so they can be placed properly in the structure of the
9796
docstring. To accommodate the various syntax flavors used in docstrings, a
9897
third requirement category is introduced, *style*.
9998

100-
Another consideration in for the *style* category is line wrapping.
101-
According to PEP 257, splitting a one-line docstring is to allow "Emacs’
102-
``fill-paragraph`` command" to be used. The ``fill-paragraph`` command is a
103-
line-wrapping command. Additionally, it would be desirable to wrap
104-
docstrings for visual continuity with the code.
99+
Another consideration in the *style* category is line wrapping. According to PEP
100+
257, splitting a one-line docstring is to allow "Emacs’ ``fill-paragraph`` command"
101+
to be used. The ``fill-paragraph`` command is a line-wrapping command. Additionally,
102+
it would be desirable to wrap docstrings for visual continuity with the code.
105103

106104
NumPy makes a stylistic decision to place a blank line after the long
107105
description.
@@ -141,7 +139,7 @@ The following items are exceptions or interpretations of the PEP 257
141139
requirements:
142140

143141
* One-line and summary lines can end with any punctuation. ``docformatter`` will recognize any of [. ! ?]. Exception to requirement PEP_257_4.5; consistent with Google style. See also #56 for situations when this is not desired.
144-
* One-line and summary lines will have the first word capitalized. ``docformatter`` will capitalize the first word for grammatical correctness. Interpretation of requirement PEP_257_4.5.
142+
* One-line and summary lines will have the first word capitalized. ``docformatter`` will capitalize the first word for grammatical correctness. Interpretation of requirement PEP_257_4.5. Some proper nouns are explicitly spelled using a lowercase letter (e.g., ``docformatter``). A user option is provided for a list of words to maintain lower case.
145143
* PEP 257 discusses placing closing quotes on a new line in the multi-line section. However, it really makes no sense here as there is no way this condition could be met for a multi-line docstring. Given the basis provided in PEP 257, this requirement really applies to wrapped one-liners. Thus, this is assumed to apply to wrapped one-liners and the closing quotes will be placed on a line by themselves in this case. However, an argument will be provided to allow the user to select their desired behavior. Interpretation of requirement PEP_257_5.5.
146144

147145
These give rise to the *derived* requirement category which would also cover
@@ -208,22 +206,28 @@ the requirement falls in, the type of requirement, and whether
208206
' docformatter_10.1.3.1', ' Shall maintain in-line links on one line even if the resulting line exceeds wrap length.', ' Derived', ' Shall', ' Yes [*PR #152*]'
209207
' docformatter_10.1.3.2', ' Shall not place a newline between description text and a wrapped link.', ' Derived', ' Shall', ' Yes [PR #182]'
210208
' docformatter_10.2', ' Should format docstrings using NumPy style.', ' Style', ' Should', ' No'
211-
' docformatter_10.2.1', ' Shall ignore docstrings in other styles when using NumPy style.', ' Shall', ' Yes'
209+
' docformatter_10.2.1', ' Shall ignore docstrings in other styles when using NumPy style.', ' Style', ' Shall', ' Yes'
212210
' docformatter_10.2.2', ' Shall wrap NumPy-style parameter descriptions that exceed wrap length when using NumPy style.', ' Shall', ' No'
213211
' docformatter_10.3', ' Should format docstrings using Google style.', ' Style', ' Should', ' No'
214-
' docformatter_10.3.1', ' Shall ignore docstrings in other styles when using Google style.', ' Shall', ' Yes'
212+
' docformatter_10.3.1', ' Shall ignore docstrings in other styles when using Google style.', ' Style', ' Shall', ' Yes'
215213
' docformatter_10.3.2', ' Shall wrap Google-style parameter descriptions that exceed wrap length when using Google style.', ' Shall', ' No'
216214
' docformatter_10.4', ' Should format docstrings using Sphinx style.', ' Style', ' Should', ' Yes'
217-
' docformatter_10.4.1', ' Shall ignore docstrings in other styles when using Sphinx style.', ' Shall', ' Yes'
215+
' docformatter_10.4.1', ' Shall ignore docstrings in other styles when using Sphinx style.', ' Style', ' Shall', ' Yes'
218216
' docformatter_10.4.2', ' Shall wrap Sphinx-style parameter descriptions that exceed wrap length when using Sphinx style.', ' Shall', ' Yes'
217+
' docformatter_10.4.3', ' Shall ensure one blank space between a field name and field body.', ' Style', ' Shall', ' Yes [PR #220]'
218+
' docformatter_10.4.3.1', ' Shall NOT add a blank space after a field name when the field body is a link.', ' Style', ' Shall', ' Yes [PR #220]'
219+
' docformatter_10.4.3.2', ' Shall NOT add a blank space after a field name when there is no field body.', ' Style', ' Shall', ' Yes [PR #220]'
219220
' docformatter_10.5', ' Should format docstrings compatible with black.', ' Style', ' Should', ' Yes [PR #192]'
220221
' docformatter_10.5.1', ' Should wrap summaries at 88 characters by default in black mode.', ' Style', ' Should', ' Yes'
221222
' docformatter_10.5.2', ' Should wrap descriptions at 88 characters by default in black mode.', ' Style', ' Should', ' Yes'
222223
' docformatter_10.5.3', ' Should insert a space before the first word in the summary if that word is quoted when in black mode.', ' Style', ' Should', ' Yes'
223224
' docformatter_10.5.4', ' Default black mode options should be over-rideable by passing arguments or using configuration files.', ' Style', ' Should', ' Yes'
224225
' docformatter_10.6', ' Should format docstrings using Epytext style.', ' Style', ' Should', ' Yes'
225-
' docformatter_10.6.1', ' Shall ignore docstrings in other styles when using Epytext style.', ' Shall', ' Yes'
226+
' docformatter_10.6.1', ' Shall ignore docstrings in other styles when using Epytext style.', ' Style', ' Shall', ' Yes'
226227
' docformatter_10.6.2', ' Shall wrap Epytext-style parameter descriptions that exceed wrap length when using Epytext style.', ' Shall', ' Yes'
228+
' docformatter_10.7', ' Should format docstrings using ReStructured Text (reST) directives.', ' Style', ' Should', ' No'
229+
' docformatter_10.7.1', ' Shall NOT wrap section headers or their adornments.', ' Style', 'Shall', ' Yes [PR #220]'
230+
' docformatter_10.7.2', ' Shall NOT wrap literal blocks.', ' Style', ' Shall', ' Yes [PR #211]'
227231
' docformatter_11', '**Program Control**'
228232
' docformatter_11.1', ' Should check formatting and report incorrectly documented docstrings.', ' Stakeholder', ' Should', ' Yes [*PR #32*]'
229233
' docformatter_11.2', ' Should fix formatting and save changes to file.', ' Stakeholder', ' Should', ' Yes'
@@ -263,6 +267,11 @@ with *convention* requirements.
263267
-s, --style [string, default sphinx]
264268
name of the docstring syntax style to use for formatting parameter
265269
lists.
270+
--rest-section-adorns [REGEX, default [!\"#$%&'()*+,-./\\:;<=>?@[]^_`{|}~]{4,}]
271+
regular expression for identifying reST section adornments
272+
-n, --non-cap [string, default []]
273+
list of words not to capitalize when they appear as the first word in the
274+
summary
266275
--black [boolean, default False]
267276
Boolean to indicate whether to format docstrings to be compatible
268277
with black.

docs/source/usage.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ help output provides a summary of these options:
2121

2222
.. code-block:: console
2323
24-
usage: docformatter [-h] [-i | -c] [-r] [--wrap-summaries length]
25-
[--wrap-descriptions length] [--black] [--blank]
26-
[--pre-summary-newline] [--make-summary-multi-line]
27-
[--force-wrap] [--range start_line end_line]
28-
[--docstring-length min_length max_length]
29-
[--config CONFIG] [--version]
30-
files [files ...]
24+
usage: docformatter [-h] [-i | -c] [-d] [-r] [-e [EXCLUDE ...]]
25+
[-n [NON-CAP ...]] [-s [style]] [--rest-section-adorns REGEX]
26+
[--black] [--wrap-summaries length]
27+
[--wrap-descriptions length] [--force-wrap]
28+
[--tab-width width] [--blank] [--pre-summary-newline]
29+
[--pre-summary-space] [--make-summary-multi-line]
30+
[--close-quotes-on-newline] [--range line line]
31+
[--docstring-length length length] [--non-strict]
32+
[--config CONFIG] [--version] files [files ...]
3133
3234
Formats docstrings to follow PEP 257.
3335
@@ -46,17 +48,17 @@ help output provides a summary of these options:
4648
-s style, --style style
4749
the docstring style to use when formatting parameter
4850
lists. One of epytext, sphinx. (default: sphinx)
49-
--black
50-
make formatting compatible with standard black options
51+
--rest-section-adorns REGEX
52+
regular expression for identifying reST section adornments
53+
(default: [!\"#$%&'()*+,-./\\:;<=>?@[]^_`{|}~]{4,})
54+
--black make formatting compatible with standard black options
5155
(default: False)
5256
--wrap-summaries length
53-
wrap long summary lines at this length; set
54-
to 0 to disable wrapping
55-
(default: 79)
57+
wrap long summary lines at this length; set to 0 to
58+
disable wrapping (default: 79, 88 with --black option)
5659
--wrap-descriptions length
57-
wrap descriptions at this length; set to 0 to
58-
disable wrapping
59-
(default: 72)
60+
wrap descriptions at this length; set to 0 to disable
61+
wrapping (default: 72, 88 with --black option)
6062
--force-wrap
6163
force descriptions to be wrapped even if it may result
6264
in a mess (default: False)

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "docformatter"
3-
version = "1.7.1"
3+
version = "1.7.2"
44
description = "Formats docstrings to follow PEP 257"
55
authors = ["Steven Myint"]
66
maintainers = [
@@ -95,6 +95,9 @@ disable = [
9595
[tool.docformatter]
9696
black = true
9797
non-strict = false
98+
non-cap = [
99+
"docformatter",
100+
]
98101

99102
[tool.pydocstyle]
100103
convention = "pep257"

src/docformatter/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def _help():
4141
print(
4242
"""\
4343
usage: docformatter [-h] [-i | -c] [-d] [-r] [-e [EXCLUDE ...]]
44-
[-n [NON-CAP ...]] [--black] [--wrap-summaries length]
44+
[-n [NON-CAP ...]] [-s [style]] [--rest-section-adorns REGEX]
45+
[--black] [--wrap-summaries length]
4546
[--wrap-descriptions length] [--force-wrap]
4647
[--tab-width width] [--blank] [--pre-summary-newline]
4748
[--pre-summary-space] [--make-summary-multi-line]
@@ -69,6 +70,9 @@ def _help():
6970
-s style, --style style
7071
the docstring style to use when formatting parameter
7172
lists. One of epytext, sphinx. (default: sphinx)
73+
--rest-section-adorns REGEX
74+
regular expression for identifying reST section adornments
75+
(default: [!\"#$%&'()*+,-./\\:;<=>?@[]^_`{|}~]{4,})
7276
--black make formatting compatible with standard black options
7377
(default: False)
7478
--wrap-summaries length
@@ -113,7 +117,7 @@ def _main(argv, standard_out, standard_error, standard_in):
113117

114118
if "--help" in configurator.args_lst:
115119
_help()
116-
sys.exit()
120+
return 0
117121
else:
118122
configurator.do_parse_arguments()
119123

src/docformatter/__pkginfo__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
# SOFTWARE.
2424
"""Package information for docformatter."""
2525

26-
__version__ = "1.7.1"
26+
__version__ = "1.7.2"

src/docformatter/configuration.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ def do_parse_arguments(self) -> None:
139139
action="store",
140140
nargs="*",
141141
default=self.flargs_dct.get("non-cap", None),
142-
help="list of words not to capitalize "
143-
"when they appear as the "
144-
"first word in the summary",
142+
help="list of words not to capitalize when they appear as the first word "
143+
"in the summary",
145144
)
146145
self.parser.add_argument(
147146
"--black",
@@ -171,6 +170,15 @@ def do_parse_arguments(self) -> None:
171170
help="name of the docstring style to use when formatting "
172171
"parameter lists (default: sphinx)",
173172
)
173+
self.parser.add_argument(
174+
"--rest-section-adorns",
175+
type=str,
176+
dest="rest_section_adorns",
177+
default=self.flargs_dct.get(
178+
"rest_section_adorns", r"[!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]{4,}"
179+
),
180+
help="regex for identifying reST section header adornments",
181+
)
174182
self.parser.add_argument(
175183
"--wrap-summaries",
176184
default=int(self.flargs_dct.get("wrap-summaries", _default_wrap_summaries)),
@@ -229,7 +237,7 @@ def do_parse_arguments(self) -> None:
229237
"pre-summary-space", _default_pre_summary_space
230238
).lower()
231239
== "true",
232-
help="add a space after the opening triple quotes " "(default: False)",
240+
help="add a space after the opening triple quotes (default: False)",
233241
)
234242
self.parser.add_argument(
235243
"--make-summary-multi-line",

0 commit comments

Comments
 (0)