docstring-generator 2.1.3__py3-none-any.whl → 2.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docstring_generator/__init__.py +0 -6
- docstring_generator/new_gen_docs.py +48 -18
- {docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/METADATA +82 -2
- docstring_generator-2.2.0.dist-info/RECORD +11 -0
- docstring_generator-2.1.3.dist-info/RECORD +0 -11
- {docstring_generator-2.1.3.data → docstring_generator-2.2.0.data}/data/doc/NOTICE +0 -0
- {docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/WHEEL +0 -0
- {docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/entry_points.txt +0 -0
- {docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/licenses/LICENSE +0 -0
- {docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/licenses/NOTICE +0 -0
- {docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/top_level.txt +0 -0
docstring_generator/__init__.py
CHANGED
|
@@ -3,10 +3,10 @@ import pathlib
|
|
|
3
3
|
import shutil
|
|
4
4
|
import subprocess
|
|
5
5
|
import tempfile
|
|
6
|
+
import tomllib # type: ignore
|
|
6
7
|
|
|
7
8
|
import click
|
|
8
9
|
import docstring_generator_ext
|
|
9
|
-
import tomllib # type: ignore
|
|
10
10
|
|
|
11
11
|
from docstring_generator.output import print_results
|
|
12
12
|
|
|
@@ -24,7 +24,7 @@ def find_pyproject_toml(start_paths: tuple[str, ...]) -> pathlib.Path | None:
|
|
|
24
24
|
|
|
25
25
|
Parameters
|
|
26
26
|
----------
|
|
27
|
-
start_paths : tuple[str, Ellipsis]
|
|
27
|
+
start_paths : tuple[str, Ellipsis]
|
|
28
28
|
|
|
29
29
|
Returns
|
|
30
30
|
-------
|
|
@@ -50,7 +50,7 @@ def load_toml_config(config_path: pathlib.Path | None) -> dict:
|
|
|
50
50
|
"""Finds and parses configuration options from pyproject.toml.
|
|
51
51
|
Parameters
|
|
52
52
|
----------
|
|
53
|
-
config_path : Union[pathlib.Path, None]
|
|
53
|
+
config_path : Union[pathlib.Path, None]
|
|
54
54
|
|
|
55
55
|
Returns
|
|
56
56
|
-------
|
|
@@ -98,6 +98,16 @@ def load_toml_config(config_path: pathlib.Path | None) -> dict:
|
|
|
98
98
|
is_flag=True,
|
|
99
99
|
help="Only process files changed or staged in git. Aborts if git is not available.",
|
|
100
100
|
)
|
|
101
|
+
@click.option(
|
|
102
|
+
"--ignore-private",
|
|
103
|
+
is_flag=True,
|
|
104
|
+
help="Ignore private functions.",
|
|
105
|
+
)
|
|
106
|
+
@click.option(
|
|
107
|
+
"--ignore-uncommented",
|
|
108
|
+
is_flag=True,
|
|
109
|
+
help="Ignore functions without docstrings. This is good for simple helper functions where the name is enough",
|
|
110
|
+
)
|
|
101
111
|
def main(
|
|
102
112
|
paths: tuple[str, ...],
|
|
103
113
|
style: str,
|
|
@@ -110,21 +120,25 @@ def main(
|
|
|
110
120
|
dry_run: bool,
|
|
111
121
|
ignore_magic: bool,
|
|
112
122
|
changed_only: bool,
|
|
123
|
+
ignore_private: bool,
|
|
124
|
+
ignore_uncommented: bool,
|
|
113
125
|
) -> None:
|
|
114
126
|
"""
|
|
115
127
|
Parameters
|
|
116
128
|
----------
|
|
117
|
-
paths : tuple[str, Ellipsis]
|
|
118
|
-
style : str
|
|
119
|
-
check : bool
|
|
120
|
-
strict : bool
|
|
121
|
-
threshold : Union[int, None]
|
|
122
|
-
exclude_file : list[str]
|
|
123
|
-
exclude_dir : list[str]
|
|
124
|
-
overwrite_style : bool
|
|
125
|
-
dry_run : bool
|
|
126
|
-
ignore_magic : bool
|
|
127
|
-
changed_only : bool
|
|
129
|
+
paths : tuple[str, Ellipsis]
|
|
130
|
+
style : str
|
|
131
|
+
check : bool
|
|
132
|
+
strict : bool
|
|
133
|
+
threshold : Union[int, None]
|
|
134
|
+
exclude_file : list[str]
|
|
135
|
+
exclude_dir : list[str]
|
|
136
|
+
overwrite_style : bool
|
|
137
|
+
dry_run : bool
|
|
138
|
+
ignore_magic : bool
|
|
139
|
+
changed_only : bool
|
|
140
|
+
ignore_private : bool
|
|
141
|
+
ignore_uncommented : bool
|
|
128
142
|
|
|
129
143
|
Returns
|
|
130
144
|
-------
|
|
@@ -138,6 +152,8 @@ def main(
|
|
|
138
152
|
_exclude_files = config.get("exclude_files", [])
|
|
139
153
|
_exclude_dirs = config.get("exclude_dirs", [])
|
|
140
154
|
_ignore_magic = config.get("ignore_magic", False)
|
|
155
|
+
_ignore_private = config.get("ignore_private", False)
|
|
156
|
+
_ignore_uncommented = config.get("ignore_uncommented", False)
|
|
141
157
|
|
|
142
158
|
# CLI args always wins
|
|
143
159
|
if exclude_file:
|
|
@@ -146,6 +162,10 @@ def main(
|
|
|
146
162
|
_exclude_dirs = exclude_dir
|
|
147
163
|
if ignore_magic:
|
|
148
164
|
_ignore_magic = ignore_magic
|
|
165
|
+
if ignore_private:
|
|
166
|
+
_ignore_private = ignore_private
|
|
167
|
+
if ignore_uncommented:
|
|
168
|
+
_ignore_uncommented = ignore_uncommented
|
|
149
169
|
|
|
150
170
|
changed_files: set[str] | None = None
|
|
151
171
|
if changed_only:
|
|
@@ -202,7 +222,7 @@ def main(
|
|
|
202
222
|
if check:
|
|
203
223
|
checked_files = {
|
|
204
224
|
file.absolute().as_posix(): docstring_generator_ext.check_docstring(
|
|
205
|
-
file.absolute().as_posix(), _ignore_magic
|
|
225
|
+
file.absolute().as_posix(), _ignore_magic, _ignore_private, _ignore_uncommented
|
|
206
226
|
)
|
|
207
227
|
for file in files_
|
|
208
228
|
}
|
|
@@ -223,7 +243,12 @@ def main(
|
|
|
223
243
|
shutil.copy2(file, tmp_path)
|
|
224
244
|
try:
|
|
225
245
|
docstring_generator_ext.parse_file(
|
|
226
|
-
tmp_path.as_posix(),
|
|
246
|
+
tmp_path.as_posix(),
|
|
247
|
+
docstring_style,
|
|
248
|
+
overwrite_style,
|
|
249
|
+
_ignore_magic,
|
|
250
|
+
_ignore_private,
|
|
251
|
+
_ignore_uncommented,
|
|
227
252
|
)
|
|
228
253
|
original = file.read_text(encoding="utf-8").splitlines(keepends=True)
|
|
229
254
|
modified = tmp_path.read_text(encoding="utf-8").splitlines(keepends=True)
|
|
@@ -243,11 +268,16 @@ def main(
|
|
|
243
268
|
tmp_path.unlink(missing_ok=True)
|
|
244
269
|
else:
|
|
245
270
|
docstring_generator_ext.parse_file(
|
|
246
|
-
file.absolute().as_posix(),
|
|
271
|
+
file.absolute().as_posix(),
|
|
272
|
+
docstring_style,
|
|
273
|
+
overwrite_style,
|
|
274
|
+
_ignore_magic,
|
|
275
|
+
_ignore_private,
|
|
276
|
+
_ignore_uncommented,
|
|
247
277
|
)
|
|
248
278
|
except SyntaxError as e:
|
|
249
279
|
print(f"Error processing file {file}: {e}")
|
|
250
|
-
except Exception as e:
|
|
280
|
+
except Exception as e: # noqa
|
|
251
281
|
print(f"Error processing file {file}: {e}")
|
|
252
282
|
|
|
253
283
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstring-generator
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Auto generate docstring from type-hints.
|
|
5
5
|
Author: FelixTheC
|
|
6
6
|
License: Apache-2.0
|
|
@@ -16,7 +16,7 @@ Description-Content-Type: text/markdown
|
|
|
16
16
|
License-File: LICENSE
|
|
17
17
|
License-File: NOTICE
|
|
18
18
|
Requires-Dist: click==8.4.2
|
|
19
|
-
Requires-Dist: docstring-generator-ext==2.0
|
|
19
|
+
Requires-Dist: docstring-generator-ext==2.1.0
|
|
20
20
|
Dynamic: license-file
|
|
21
21
|
|
|
22
22
|
[](https://www.python.org/downloads/)
|
|
@@ -193,6 +193,40 @@ gendocs_new mydir/ --style google --overwrite-style true
|
|
|
193
193
|
|
|
194
194
|
Useful when migrating a codebase from one docstring convention to another.
|
|
195
195
|
|
|
196
|
+
### `--ignore-private` — Skip private functions/methods
|
|
197
|
+
|
|
198
|
+
Skip functions and methods whose name starts with a single underscore (e.g. `_helper`), leaving them untouched. Dunder methods (e.g. `__init__`, `__str__`) are **not** affected by this flag — use `--ignore-magic` for those:
|
|
199
|
+
|
|
200
|
+
```shell
|
|
201
|
+
gendocs_new mydir/ --ignore-private
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Can also be enabled permanently via `pyproject.toml`:
|
|
205
|
+
|
|
206
|
+
```toml
|
|
207
|
+
[tool.docstring_generator]
|
|
208
|
+
ignore_private = true
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Default:** `False`
|
|
212
|
+
|
|
213
|
+
### `--ignore-uncommented` — Skip functions without an existing docstring
|
|
214
|
+
|
|
215
|
+
Skip functions and methods that currently have **no docstring at all**, leaving them untouched instead of generating one. Good for simple helper functions where the name is already self-explanatory. Functions that already have *some* docstring are still processed normally (e.g. missing `Parameters`/`Returns` sections are added):
|
|
216
|
+
|
|
217
|
+
```shell
|
|
218
|
+
gendocs_new mydir/ --ignore-uncommented
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Can also be enabled permanently via `pyproject.toml`:
|
|
222
|
+
|
|
223
|
+
```toml
|
|
224
|
+
[tool.docstring_generator]
|
|
225
|
+
ignore_uncommented = true
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Default:** `False`
|
|
229
|
+
|
|
196
230
|
---
|
|
197
231
|
|
|
198
232
|
## Configuration via `pyproject.toml`
|
|
@@ -206,12 +240,58 @@ threshold = 90
|
|
|
206
240
|
exclude_files = ["conftest.py", "settings.py"]
|
|
207
241
|
exclude_dirs = ["tests", "migrations"]
|
|
208
242
|
ignore_magic = true
|
|
243
|
+
ignore_private = true
|
|
244
|
+
ignore_uncommented = true
|
|
209
245
|
```
|
|
210
246
|
|
|
211
247
|
CLI flags always override `pyproject.toml` values. The tool automatically walks up from the target path to find the nearest `pyproject.toml`.
|
|
212
248
|
|
|
213
249
|
---
|
|
214
250
|
|
|
251
|
+
## Skip Directives — `# docstring: skip` / `# docstring: off` / `# docstring: on`
|
|
252
|
+
|
|
253
|
+
When a CLI flag is too coarse, tell the generator to leave specific parts of a file untouched using `# docstring: skip` comments. Three scopes are supported:
|
|
254
|
+
|
|
255
|
+
### 1. File-level skip
|
|
256
|
+
|
|
257
|
+
Place the directive within the first 10 lines of the file to skip the entire file:
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
# docstring: skip
|
|
261
|
+
|
|
262
|
+
def some_function():
|
|
263
|
+
return None
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 2. Single-target skip
|
|
267
|
+
|
|
268
|
+
Place the directive as the first statement inside a function or method body to skip just that target:
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
def helper_three(a: int) -> int:
|
|
272
|
+
# docstring: skip
|
|
273
|
+
return a
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 3. Block/Range skip
|
|
277
|
+
|
|
278
|
+
Wrap a group of functions or classes between `# docstring: off` and `# docstring: on` to skip everything in between:
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
# docstring: off
|
|
282
|
+
def helper_one():
|
|
283
|
+
...
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def helper_two():
|
|
287
|
+
...
|
|
288
|
+
# docstring: on
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
> ⚠️ **Known limitation:** currently only the function immediately following `# docstring: off` is reliably skipped — functions further down the block may still receive a generated docstring. Until this is fixed upstream, prefer the single-target directive on each function if you need every function in a range excluded. See the full [Skip Directives guide](https://felixthec.github.io/docstring_generator/skip-directives/) for details.
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
215
295
|
## Preserve Custom Descriptions with `$<num>` Placeholders
|
|
216
296
|
|
|
217
297
|
Write your domain-specific notes once — `docstring_generator` will place them in the right parameter slot automatically.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
docstring_generator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
docstring_generator/new_gen_docs.py,sha256=2m0Ec3RquTwpjPSepA-Hc6cHFrpMC9nswoqJcHY3Byc,9033
|
|
3
|
+
docstring_generator/output.py,sha256=R1UJItxYK0kFeekP2QO1KJrKBxdif3H2TjePxvKSk5c,3900
|
|
4
|
+
docstring_generator-2.2.0.data/data/doc/NOTICE,sha256=g3gPAC-x9BI86_vLNsber3wdxNvmU3hvJoymfy9mvb0,883
|
|
5
|
+
docstring_generator-2.2.0.dist-info/licenses/LICENSE,sha256=xhR1A67exdZYRRQ8w_yl2czbXPdsUoBC_EfosGN1BYM,554
|
|
6
|
+
docstring_generator-2.2.0.dist-info/licenses/NOTICE,sha256=g3gPAC-x9BI86_vLNsber3wdxNvmU3hvJoymfy9mvb0,883
|
|
7
|
+
docstring_generator-2.2.0.dist-info/METADATA,sha256=4C3KUBC6Zt_9ZNvdp2RIqfWFKkP92n9VjtJenv61heI,21664
|
|
8
|
+
docstring_generator-2.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
9
|
+
docstring_generator-2.2.0.dist-info/entry_points.txt,sha256=gTDh_jPmZJsXSPtcvbnrOFNj3el1mX5kBxkA7LvocD0,70
|
|
10
|
+
docstring_generator-2.2.0.dist-info/top_level.txt,sha256=lbWGtPCtaT4NhNvqCqXsVaEmlzBQy_dpLJ7UnYRMDcA,20
|
|
11
|
+
docstring_generator-2.2.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
docstring_generator/__init__.py,sha256=b5dvFC0GYw2pfMTYFpXleTqzp7LOyviaKTzoBi5znCg,89
|
|
2
|
-
docstring_generator/new_gen_docs.py,sha256=Yv6326y4NsBRoBmie-lP2sxtGw2j0FtMAdqZ7Zujrcg,8111
|
|
3
|
-
docstring_generator/output.py,sha256=R1UJItxYK0kFeekP2QO1KJrKBxdif3H2TjePxvKSk5c,3900
|
|
4
|
-
docstring_generator-2.1.3.data/data/doc/NOTICE,sha256=g3gPAC-x9BI86_vLNsber3wdxNvmU3hvJoymfy9mvb0,883
|
|
5
|
-
docstring_generator-2.1.3.dist-info/licenses/LICENSE,sha256=xhR1A67exdZYRRQ8w_yl2czbXPdsUoBC_EfosGN1BYM,554
|
|
6
|
-
docstring_generator-2.1.3.dist-info/licenses/NOTICE,sha256=g3gPAC-x9BI86_vLNsber3wdxNvmU3hvJoymfy9mvb0,883
|
|
7
|
-
docstring_generator-2.1.3.dist-info/METADATA,sha256=gcXlHV11fBCQih9aBjCJ-dRiGzBY3t2J96latXoFSNg,19205
|
|
8
|
-
docstring_generator-2.1.3.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
9
|
-
docstring_generator-2.1.3.dist-info/entry_points.txt,sha256=gTDh_jPmZJsXSPtcvbnrOFNj3el1mX5kBxkA7LvocD0,70
|
|
10
|
-
docstring_generator-2.1.3.dist-info/top_level.txt,sha256=lbWGtPCtaT4NhNvqCqXsVaEmlzBQy_dpLJ7UnYRMDcA,20
|
|
11
|
-
docstring_generator-2.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{docstring_generator-2.1.3.dist-info → docstring_generator-2.2.0.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|