8
8
9
9
A tool to automatically format Python docstrings to follow recommendations from
10
10
[ ` PEP 8 ` ] ( https://www.python.org/dev/peps/pep-0008/ ) and
11
- [ ` PEP 257 ` ] ( https://www.python.org/dev/peps/pep-0257/ ) .
11
+ [ ` PEP 257 ` ] ( https://www.python.org/dev/peps/pep-0257/ ) (or other supported style guides.)
12
12
13
13
See [ What it does] ( #what-it-does ) for currently supported auto-formatting.
14
14
@@ -19,7 +19,7 @@ This project is heavily inspired by
19
19
20
20
When this project was started ` docformatter ` did not meet all of the requirements the
21
21
[ ` pylint ` ] ( https://github.com/PyCQA/pylint ) project had for its docstring formatter and
22
- sadly ` docformatter ` is now also no longer fully supported . Therefore, some contributors
22
+ was no longer actively maintained (this has changed since then) . Therefore, some contributors
23
23
of ` pylint ` got together and started working on our own formatter to fulfill our needs.
24
24
25
25
When asked we defined the objective of the tool as:
@@ -45,23 +45,6 @@ pip install pydocstringformatter
45
45
[ ` Click here ` ] ( https://pydocstringformatter.readthedocs.io/en/latest/usage.html ) for a
46
46
full Usage overview.
47
47
48
- ``` shell
49
- usage: pydocstringformatter [-h] [-w] [--exclude EXCLUDE] [-v] [files ...]
50
-
51
- positional arguments:
52
- files The directory or files to format.
53
-
54
- options:
55
- -h, --help show this help message and exit
56
- -w, --write Write the changes to file instead of printing the diffs to stdout.
57
- --quiet Do not print any logging or status messages to stdout.
58
- -v, --version Show version number and exit.
59
- --max-line-length The maximum docstring line length. Default set to 88.
60
-
61
- configuration:
62
- --exclude EXCLUDE A comma separated list of glob patterns of file path names not to be formatted.
63
- ```
64
-
65
48
### Configuration
66
49
67
50
Pydocstringformatter will also read any configuration added to the
@@ -77,6 +60,16 @@ exclude = "**/my_dir/**,**/my_other_dir/**"
77
60
exclude = [" **/my_dir/**" , " **/my_other_dir/**" ]
78
61
```
79
62
63
+ #### Style
64
+
65
+ Pydocstringformatter can be configured to use a specific style. The default is `` pep257 `` but
66
+ we support other styles as well.
67
+ These can also be used at the same time. For example with:
68
+
69
+ ``` console
70
+ pydocstringformatter --style=pep257 --style=numpydoc myfile.py
71
+ ```
72
+
80
73
## Pre-commit
81
74
82
75
Pydocstringformatter can also be used as a [ pre-commit hook] ( https://pre-commit.com ) .
@@ -91,77 +84,20 @@ Add the following to your `.pre-commit-config.yaml` file:
91
84
92
85
## What it does
93
86
94
- The following examples show what pydocstringformatter will pick up on. All _bad_
95
- examples will be rewritten to follow the _good_ patterns.
96
-
97
- **PEP 8: _Note that most importantly, the """ that ends a multiline docstring should be
98
- on a line by itself:_**
87
+ The following examples show some of the changes pydocstringformatter will apply. For a full
88
+ overview of all potential changes you can check out the [` Usage`](https://pydocstringformatter.readthedocs.io/en/latest/usage.html) page which
89
+ shows an up to date list of all formatters and their description.
99
90
100
91
` ` ` python
101
92
# Bad
102
- " " " My
103
- multi-line docstring" " "
104
-
105
- # Good
106
- " " " My
107
- multi-line docstring
108
- " " "
109
- ```
110
-
111
- ** PEP 257: _ The closing quotes are on the same line as the opening quotes_ **
112
-
113
- This can be enforced on multi-line docstrings with the ` --summary-quotes-same-line `
114
- option. This behaviour is turned off by default.
115
-
116
- ``` python
117
- # Bad
118
- """
119
- My docstring"""
120
-
121
- """ My docstring
122
- """
123
-
124
- """
125
- My
126
- multi-line docstring
127
- """
128
-
129
- # With --summary-quotes-same-line
130
- """
131
- My
132
- multi-line docstring
133
- """
134
-
135
- # Good
136
- """ My docstring"""
137
-
138
- """ My docstring"""
139
-
140
- """
141
- My
142
- multi-line docstring
143
- """
144
-
145
- # With --summary-quotes-same-line
146
- """ My
147
- multi-line docstring
148
- """
149
- ```
150
-
151
- ** PEP 257: _ The docstring is a phrase ending in a period & Multi-line docstrings consist
152
- of a summary line just like a one-line docstring_ **
153
-
154
- Since the first line should be a phrase or summary the first character gets capitalized.
155
-
156
- When the second line is one recurring character we consider the summary line to be a
157
- title as used in many Sphinx documentation schemes and do not add a period.
93
+ '''
94
+ my docstring'''
158
95
159
- ``` python
160
- # Bad
161
- """ my docstring"""
96
+ """ my
97
+ multi-line docstring """
162
98
163
- """
164
- summary
99
+ """my title
100
+ ===========
165
101
166
102
my docstring
167
103
"""
@@ -170,103 +106,29 @@ my docstring
170
106
# Good
171
107
"""My docstring."""
172
108
173
- """
174
- Summary.
175
-
176
- my docstring
109
+ """My
110
+ multi-line docstring.
177
111
"""
178
112
179
113
"""My title
180
114
===========
181
115
182
116
My docstring
183
117
"""
184
- ```
185
-
186
- ** PEP 257: _ Multi-line docstrings consist of a summary line just like a one-line
187
- docstring, followed by a blank line, followed by a more elaborate description._ **
188
118
189
- When the second line is one recurring character we consider the summary line to be a
190
- title as used in many Sphinx documentation schemes and do not add a white line.
191
-
192
- ``` python
119
+ # With --summary-quotes-same-line
193
120
# Bad
194
- """ Summary. Body."""
195
-
196
- """ Summary.
197
- Body.
198
121
"""
199
-
200
- # Good
201
- """ Summary.
202
-
203
- Body.
204
- """
205
-
206
- """ My title
207
- ===========
208
-
209
- My docstring
122
+ My
123
+ multi-line docstring
210
124
"""
211
- ```
212
-
213
- ** PEP 257: _ For consistency, always use """triple double quotes""" around docstrings._ **
214
-
215
- ``` python
216
- # Bad
217
- " My docstring"
218
-
219
- ' My docstring'
220
-
221
- ''' My docstring'''
222
-
223
- ''' Summary.
224
-
225
- Body.
226
- '''
227
125
228
126
# Good
229
- """ My docstring"""
230
-
231
- """ My docstring"""
232
-
233
- """ My docstring"""
234
-
235
- """ Summary.
236
-
237
- Body.
127
+ """My
128
+ multi-line docstring
238
129
"""
239
130
` ` `
240
131
241
- ** _ Trailing or leading whitespaces get removed as well._ **
242
-
243
- ``` python
244
- # Bad
245
- """ My docstring. """
246
-
247
- """ Summary.
248
-
249
- Body
250
- """
251
-
252
- """ My docstring.
253
-
254
- My indented section
255
- """
256
-
257
- # Good
258
- """ My docstring."""
259
-
260
- """ Summary.
261
-
262
- Body
263
- """
264
-
265
- """ My docstring.
266
-
267
- My indented section
268
- """
269
- ```
270
132
271
133
# # Development
272
134
0 commit comments