docstring-generator 2.1.2__tar.gz → 2.2.0__tar.gz
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-2.1.2/src/docstring_generator.egg-info → docstring_generator-2.2.0}/PKG-INFO +82 -2
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/README.md +80 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/pyproject.toml +5 -5
- docstring_generator-2.2.0/src/docstring_generator/__init__.py +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator/new_gen_docs.py +48 -18
- {docstring_generator-2.1.2 → docstring_generator-2.2.0/src/docstring_generator.egg-info}/PKG-INFO +82 -2
- docstring_generator-2.2.0/src/docstring_generator.egg-info/requires.txt +2 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/tests/test_library.py +287 -1
- docstring_generator-2.1.2/src/docstring_generator/__init__.py +0 -6
- docstring_generator-2.1.2/src/docstring_generator.egg-info/requires.txt +0 -2
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/LICENSE +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/NOTICE +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/setup.cfg +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator/output.py +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator.egg-info/SOURCES.txt +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator.egg-info/dependency_links.txt +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator.egg-info/entry_points.txt +0 -0
- {docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator.egg-info/top_level.txt +0 -0
{docstring_generator-2.1.2/src/docstring_generator.egg-info → docstring_generator-2.2.0}/PKG-INFO
RENAMED
|
@@ -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
|
|
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.
|
|
@@ -172,6 +172,40 @@ gendocs_new mydir/ --style google --overwrite-style true
|
|
|
172
172
|
|
|
173
173
|
Useful when migrating a codebase from one docstring convention to another.
|
|
174
174
|
|
|
175
|
+
### `--ignore-private` — Skip private functions/methods
|
|
176
|
+
|
|
177
|
+
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:
|
|
178
|
+
|
|
179
|
+
```shell
|
|
180
|
+
gendocs_new mydir/ --ignore-private
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Can also be enabled permanently via `pyproject.toml`:
|
|
184
|
+
|
|
185
|
+
```toml
|
|
186
|
+
[tool.docstring_generator]
|
|
187
|
+
ignore_private = true
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Default:** `False`
|
|
191
|
+
|
|
192
|
+
### `--ignore-uncommented` — Skip functions without an existing docstring
|
|
193
|
+
|
|
194
|
+
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):
|
|
195
|
+
|
|
196
|
+
```shell
|
|
197
|
+
gendocs_new mydir/ --ignore-uncommented
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Can also be enabled permanently via `pyproject.toml`:
|
|
201
|
+
|
|
202
|
+
```toml
|
|
203
|
+
[tool.docstring_generator]
|
|
204
|
+
ignore_uncommented = true
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Default:** `False`
|
|
208
|
+
|
|
175
209
|
---
|
|
176
210
|
|
|
177
211
|
## Configuration via `pyproject.toml`
|
|
@@ -185,12 +219,58 @@ threshold = 90
|
|
|
185
219
|
exclude_files = ["conftest.py", "settings.py"]
|
|
186
220
|
exclude_dirs = ["tests", "migrations"]
|
|
187
221
|
ignore_magic = true
|
|
222
|
+
ignore_private = true
|
|
223
|
+
ignore_uncommented = true
|
|
188
224
|
```
|
|
189
225
|
|
|
190
226
|
CLI flags always override `pyproject.toml` values. The tool automatically walks up from the target path to find the nearest `pyproject.toml`.
|
|
191
227
|
|
|
192
228
|
---
|
|
193
229
|
|
|
230
|
+
## Skip Directives — `# docstring: skip` / `# docstring: off` / `# docstring: on`
|
|
231
|
+
|
|
232
|
+
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:
|
|
233
|
+
|
|
234
|
+
### 1. File-level skip
|
|
235
|
+
|
|
236
|
+
Place the directive within the first 10 lines of the file to skip the entire file:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
# docstring: skip
|
|
240
|
+
|
|
241
|
+
def some_function():
|
|
242
|
+
return None
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### 2. Single-target skip
|
|
246
|
+
|
|
247
|
+
Place the directive as the first statement inside a function or method body to skip just that target:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
def helper_three(a: int) -> int:
|
|
251
|
+
# docstring: skip
|
|
252
|
+
return a
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 3. Block/Range skip
|
|
256
|
+
|
|
257
|
+
Wrap a group of functions or classes between `# docstring: off` and `# docstring: on` to skip everything in between:
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
# docstring: off
|
|
261
|
+
def helper_one():
|
|
262
|
+
...
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def helper_two():
|
|
266
|
+
...
|
|
267
|
+
# docstring: on
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
> ⚠️ **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.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
194
274
|
## Preserve Custom Descriptions with `$<num>` Placeholders
|
|
195
275
|
|
|
196
276
|
Write your domain-specific notes once — `docstring_generator` will place them in the right parameter slot automatically.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "docstring-generator"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.2.0"
|
|
4
4
|
description = "Auto generate docstring from type-hints."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "FelixTheC" },
|
|
@@ -22,16 +22,16 @@ classifiers=[
|
|
|
22
22
|
|
|
23
23
|
dependencies = [
|
|
24
24
|
"click == 8.4.2",
|
|
25
|
-
"docstring-generator-ext
|
|
25
|
+
"docstring-generator-ext==2.1.0",
|
|
26
26
|
]
|
|
27
27
|
|
|
28
28
|
[dependency-groups]
|
|
29
29
|
dev = [
|
|
30
30
|
"pytest>=9.1.1",
|
|
31
31
|
"pytest-cov>=7.1.0",
|
|
32
|
-
"ruff==0.
|
|
33
|
-
"fastapi==0.
|
|
34
|
-
"sqlalchemy==2.0.
|
|
32
|
+
"ruff==0.16.3",
|
|
33
|
+
"fastapi==0.141.1",
|
|
34
|
+
"sqlalchemy==2.0.52"
|
|
35
35
|
]
|
|
36
36
|
|
|
37
37
|
[tool.uv]
|
|
File without changes
|
{docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator/new_gen_docs.py
RENAMED
|
@@ -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
|
|
{docstring_generator-2.1.2 → docstring_generator-2.2.0/src/docstring_generator.egg-info}/PKG-INFO
RENAMED
|
@@ -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
|
|
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.
|
|
@@ -15,7 +15,7 @@ EXPECTED_FILES = {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
@pytest.mark.parametrize("style", ("numpy", "
|
|
18
|
+
@pytest.mark.parametrize("style", ("numpy", "google"))
|
|
19
19
|
def test_docstring_creation(style):
|
|
20
20
|
"""
|
|
21
21
|
Parameters
|
|
@@ -330,6 +330,292 @@ def test_changed_only_combined_with_dry_run():
|
|
|
330
330
|
)
|
|
331
331
|
|
|
332
332
|
|
|
333
|
+
# ---------------------------------------------------------------------------
|
|
334
|
+
# --ignore-private tests
|
|
335
|
+
# ---------------------------------------------------------------------------
|
|
336
|
+
|
|
337
|
+
def test_ignore_private_skips_private_functions():
|
|
338
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
339
|
+
|
|
340
|
+
with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
|
|
341
|
+
tmp_path = Path(tmp_file.name)
|
|
342
|
+
tmp_file.write(
|
|
343
|
+
"def public_func(a: int) -> int:\n"
|
|
344
|
+
" return a\n"
|
|
345
|
+
"\n"
|
|
346
|
+
"def _private_func(a: int) -> int:\n"
|
|
347
|
+
" return a\n"
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
try:
|
|
351
|
+
result = subprocess.run(
|
|
352
|
+
[str(gendocs_new), "--ignore-private", str(tmp_path)],
|
|
353
|
+
capture_output=True,
|
|
354
|
+
text=True,
|
|
355
|
+
)
|
|
356
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
357
|
+
|
|
358
|
+
content = tmp_path.read_text(encoding="utf-8")
|
|
359
|
+
assert '"""' in content.split("def _private_func")[0], (
|
|
360
|
+
"public function should have received a docstring"
|
|
361
|
+
)
|
|
362
|
+
assert '"""' not in content.split("def _private_func")[1], (
|
|
363
|
+
"--ignore-private should leave private functions untouched"
|
|
364
|
+
)
|
|
365
|
+
finally:
|
|
366
|
+
tmp_path.unlink(missing_ok=True)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def test_ignore_private_does_not_skip_dunder_methods():
|
|
370
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
371
|
+
|
|
372
|
+
with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
|
|
373
|
+
tmp_path = Path(tmp_file.name)
|
|
374
|
+
tmp_file.write(
|
|
375
|
+
"class Foo:\n"
|
|
376
|
+
" def __init__(self, a: int) -> None:\n"
|
|
377
|
+
" self.a = a\n"
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
try:
|
|
381
|
+
result = subprocess.run(
|
|
382
|
+
[str(gendocs_new), "--ignore-private", str(tmp_path)],
|
|
383
|
+
capture_output=True,
|
|
384
|
+
text=True,
|
|
385
|
+
)
|
|
386
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
387
|
+
|
|
388
|
+
content = tmp_path.read_text(encoding="utf-8")
|
|
389
|
+
assert '"""' in content, (
|
|
390
|
+
"--ignore-private should not skip dunder methods like __init__"
|
|
391
|
+
)
|
|
392
|
+
finally:
|
|
393
|
+
tmp_path.unlink(missing_ok=True)
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def test_ignore_private_via_pyproject_config():
|
|
397
|
+
with TemporaryDirectory() as tmp_dir:
|
|
398
|
+
tmp_dir_path = Path(tmp_dir)
|
|
399
|
+
|
|
400
|
+
(tmp_dir_path / "pyproject.toml").write_text(
|
|
401
|
+
"[tool.docstring_generator]\nignore_private = true\n",
|
|
402
|
+
encoding="utf-8",
|
|
403
|
+
)
|
|
404
|
+
sample = tmp_dir_path / "sample.py"
|
|
405
|
+
sample.write_text(
|
|
406
|
+
"def public_func(a: int) -> int:\n"
|
|
407
|
+
" return a\n"
|
|
408
|
+
"\n"
|
|
409
|
+
"def _private_func(a: int) -> int:\n"
|
|
410
|
+
" return a\n",
|
|
411
|
+
encoding="utf-8",
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
415
|
+
result = subprocess.run(
|
|
416
|
+
[str(gendocs_new), str(sample)],
|
|
417
|
+
capture_output=True,
|
|
418
|
+
text=True,
|
|
419
|
+
cwd=tmp_dir,
|
|
420
|
+
)
|
|
421
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
422
|
+
|
|
423
|
+
content = sample.read_text(encoding="utf-8")
|
|
424
|
+
assert '"""' in content.split("def _private_func")[0]
|
|
425
|
+
assert '"""' not in content.split("def _private_func")[1]
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
# ---------------------------------------------------------------------------
|
|
429
|
+
# --ignore-uncommented tests
|
|
430
|
+
# ---------------------------------------------------------------------------
|
|
431
|
+
|
|
432
|
+
def test_ignore_uncommented_skips_functions_without_docstring():
|
|
433
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
434
|
+
|
|
435
|
+
with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
|
|
436
|
+
tmp_path = Path(tmp_file.name)
|
|
437
|
+
tmp_file.write(
|
|
438
|
+
"def has_docstring(a: int) -> int:\n"
|
|
439
|
+
' """Existing docstring."""\n'
|
|
440
|
+
" return a\n"
|
|
441
|
+
"\n"
|
|
442
|
+
"def no_docstring(a: int) -> int:\n"
|
|
443
|
+
" return a\n"
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
try:
|
|
447
|
+
result = subprocess.run(
|
|
448
|
+
[str(gendocs_new), "--ignore-uncommented", str(tmp_path)],
|
|
449
|
+
capture_output=True,
|
|
450
|
+
text=True,
|
|
451
|
+
)
|
|
452
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
453
|
+
|
|
454
|
+
content = tmp_path.read_text(encoding="utf-8")
|
|
455
|
+
has_docstring_part, no_docstring_part = content.split("def no_docstring")
|
|
456
|
+
|
|
457
|
+
# the already-documented function should have been extended with parameter info
|
|
458
|
+
assert "Parameters" in has_docstring_part, (
|
|
459
|
+
"functions that already have a docstring must still be processed"
|
|
460
|
+
)
|
|
461
|
+
# the fully undocumented function must be left untouched
|
|
462
|
+
assert '"""' not in no_docstring_part, (
|
|
463
|
+
"--ignore-uncommented should leave functions without a docstring untouched"
|
|
464
|
+
)
|
|
465
|
+
finally:
|
|
466
|
+
tmp_path.unlink(missing_ok=True)
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def test_ignore_uncommented_via_pyproject_config():
|
|
470
|
+
with TemporaryDirectory() as tmp_dir:
|
|
471
|
+
tmp_dir_path = Path(tmp_dir)
|
|
472
|
+
|
|
473
|
+
(tmp_dir_path / "pyproject.toml").write_text(
|
|
474
|
+
"[tool.docstring_generator]\nignore_uncommented = true\n",
|
|
475
|
+
encoding="utf-8",
|
|
476
|
+
)
|
|
477
|
+
sample = tmp_dir_path / "sample.py"
|
|
478
|
+
sample.write_text(
|
|
479
|
+
"def no_docstring(a: int) -> int:\n"
|
|
480
|
+
" return a\n",
|
|
481
|
+
encoding="utf-8",
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
485
|
+
result = subprocess.run(
|
|
486
|
+
[str(gendocs_new), str(sample)],
|
|
487
|
+
capture_output=True,
|
|
488
|
+
text=True,
|
|
489
|
+
cwd=tmp_dir,
|
|
490
|
+
)
|
|
491
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
492
|
+
|
|
493
|
+
content = sample.read_text(encoding="utf-8")
|
|
494
|
+
assert '"""' not in content, (
|
|
495
|
+
"--ignore-uncommented (via pyproject.toml) should leave undocumented functions untouched"
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
# ---------------------------------------------------------------------------
|
|
500
|
+
# `# docstring: skip` / `# docstring: off` / `# docstring: on` directive tests
|
|
501
|
+
# ---------------------------------------------------------------------------
|
|
502
|
+
|
|
503
|
+
def test_skip_directive_file_level_leaves_file_untouched():
|
|
504
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
505
|
+
|
|
506
|
+
with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
|
|
507
|
+
tmp_path = Path(tmp_file.name)
|
|
508
|
+
tmp_file.write(
|
|
509
|
+
"# docstring: skip\n"
|
|
510
|
+
"\n"
|
|
511
|
+
"def some_function(a: int) -> int:\n"
|
|
512
|
+
" return a\n"
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
try:
|
|
516
|
+
original_content = tmp_path.read_text(encoding="utf-8")
|
|
517
|
+
|
|
518
|
+
result = subprocess.run(
|
|
519
|
+
[str(gendocs_new), str(tmp_path)],
|
|
520
|
+
capture_output=True,
|
|
521
|
+
text=True,
|
|
522
|
+
)
|
|
523
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
524
|
+
|
|
525
|
+
assert tmp_path.read_text(encoding="utf-8") == original_content, (
|
|
526
|
+
"a `# docstring: skip` comment within the first 10 lines must skip the whole file"
|
|
527
|
+
)
|
|
528
|
+
finally:
|
|
529
|
+
tmp_path.unlink(missing_ok=True)
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def test_skip_directive_single_target_skips_only_that_function():
|
|
533
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
534
|
+
|
|
535
|
+
padding = "".join(f"# padding line {i}\n" for i in range(1, 11))
|
|
536
|
+
source = (
|
|
537
|
+
padding
|
|
538
|
+
+ "def helper_three(a: int) -> int:\n"
|
|
539
|
+
+ " # docstring: skip\n"
|
|
540
|
+
+ " return a\n"
|
|
541
|
+
+ "\n"
|
|
542
|
+
+ "def normal_func(a: int) -> int:\n"
|
|
543
|
+
+ " return a\n"
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
|
|
547
|
+
tmp_path = Path(tmp_file.name)
|
|
548
|
+
tmp_file.write(source)
|
|
549
|
+
|
|
550
|
+
try:
|
|
551
|
+
result = subprocess.run(
|
|
552
|
+
[str(gendocs_new), str(tmp_path)],
|
|
553
|
+
capture_output=True,
|
|
554
|
+
text=True,
|
|
555
|
+
)
|
|
556
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
557
|
+
|
|
558
|
+
content = tmp_path.read_text(encoding="utf-8")
|
|
559
|
+
helper_part, normal_part = content.split("def normal_func")
|
|
560
|
+
|
|
561
|
+
assert '"""' not in helper_part, (
|
|
562
|
+
"a `# docstring: skip` placed below a function must skip just that function"
|
|
563
|
+
)
|
|
564
|
+
assert '"""' in normal_part, (
|
|
565
|
+
"functions without the skip directive must still be processed"
|
|
566
|
+
)
|
|
567
|
+
finally:
|
|
568
|
+
tmp_path.unlink(missing_ok=True)
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
@pytest.mark.xfail(reason="Block skip via `# docstring: off` / `# docstring: on` is not honored by the extension")
|
|
572
|
+
def test_skip_directive_block_range_skips_everything_between():
|
|
573
|
+
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
574
|
+
|
|
575
|
+
padding = "".join(f"# padding line {i}\n" for i in range(1, 11))
|
|
576
|
+
source = (
|
|
577
|
+
padding
|
|
578
|
+
+ "def before_block(a: int) -> int:\n"
|
|
579
|
+
+ " return a\n"
|
|
580
|
+
+ "\n"
|
|
581
|
+
+ "# docstring: off\n"
|
|
582
|
+
+ "def helper_one(a: int) -> int:\n"
|
|
583
|
+
+ " return a\n"
|
|
584
|
+
+ "\n"
|
|
585
|
+
+ "\n"
|
|
586
|
+
+ "def helper_two(a: int) -> int:\n"
|
|
587
|
+
+ " return a\n"
|
|
588
|
+
+ "# docstring: on\n"
|
|
589
|
+
+ "\n"
|
|
590
|
+
+ "def after_block(a: int) -> int:\n"
|
|
591
|
+
+ " return a\n"
|
|
592
|
+
)
|
|
593
|
+
|
|
594
|
+
with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
|
|
595
|
+
tmp_path = Path(tmp_file.name)
|
|
596
|
+
tmp_file.write(source)
|
|
597
|
+
|
|
598
|
+
try:
|
|
599
|
+
result = subprocess.run(
|
|
600
|
+
[str(gendocs_new), str(tmp_path)],
|
|
601
|
+
capture_output=True,
|
|
602
|
+
text=True,
|
|
603
|
+
)
|
|
604
|
+
assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
|
|
605
|
+
|
|
606
|
+
content = tmp_path.read_text(encoding="utf-8")
|
|
607
|
+
before, rest = content.split("def helper_one")
|
|
608
|
+
block, after = rest.split("# docstring: on")
|
|
609
|
+
|
|
610
|
+
assert '"""' in before, "functions before the block must still be processed"
|
|
611
|
+
assert '"""' not in block, (
|
|
612
|
+
"functions between `# docstring: off` and `# docstring: on` must be skipped"
|
|
613
|
+
)
|
|
614
|
+
assert '"""' in after, "functions after the block must still be processed"
|
|
615
|
+
finally:
|
|
616
|
+
tmp_path.unlink(missing_ok=True)
|
|
617
|
+
|
|
618
|
+
|
|
333
619
|
@pytest.mark.xfail
|
|
334
620
|
def test_overwrite_existing_style():
|
|
335
621
|
gendocs_new = Path(sys.executable).parent / "gendocs_new"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{docstring_generator-2.1.2 → docstring_generator-2.2.0}/src/docstring_generator.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|