docstringify 0.1.1__tar.gz → 0.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.
- {docstringify-0.1.1 → docstringify-0.2.0}/PKG-INFO +17 -7
- {docstringify-0.1.1 → docstringify-0.2.0}/README.md +15 -5
- {docstringify-0.1.1 → docstringify-0.2.0}/pyproject.toml +1 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify/__init__.py +1 -1
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify/cli.py +5 -3
- docstringify-0.2.0/src/docstringify/converters/__init__.py +11 -0
- docstringify-0.2.0/src/docstringify/converters/google.py +46 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify/visitor.py +1 -1
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify.egg-info/PKG-INFO +17 -7
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify.egg-info/SOURCES.txt +1 -0
- docstringify-0.1.1/src/docstringify/converters/__init__.py +0 -1
- {docstringify-0.1.1 → docstringify-0.2.0}/.github/dependabot.yml +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/.github/release.yml +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/.github/workflows/ci.yml +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/.github/workflows/pypi-publish.yml +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/.gitignore +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/.pre-commit-config.yaml +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/.pre-commit-hooks.yaml +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/LICENSE +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/setup.cfg +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify/__main__.py +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify/components.py +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify/converters/base.py +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify/converters/numpydoc.py +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify.egg-info/dependency_links.txt +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify.egg-info/entry_points.txt +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify.egg-info/requires.txt +0 -0
- {docstringify-0.1.1 → docstringify-0.2.0}/src/docstringify.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstringify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Flag missing docstrings and, optionally, generate them from signatures and type annotations.
|
|
5
5
|
Author-email: Stefanie Molin <docstringify@stefaniemolin.com>
|
|
6
6
|
License: MIT License
|
|
@@ -28,7 +28,7 @@ License: MIT License
|
|
|
28
28
|
Project-URL: Documentation, https://github.com/stefmolin/docstringify
|
|
29
29
|
Project-URL: Homepage, https://github.com/stefmolin/docstringify
|
|
30
30
|
Project-URL: Source, https://github.com/stefmolin/docstringify
|
|
31
|
-
Keywords: ast,docstring generation,numpydoc-style docstring,pre-commit
|
|
31
|
+
Keywords: ast,docstring generation,google-style docstring,numpydoc-style docstring,pre-commit
|
|
32
32
|
Classifier: Development Status :: 3 - Alpha
|
|
33
33
|
Classifier: License :: OSI Approved :: MIT License
|
|
34
34
|
Classifier: Programming Language :: Python
|
|
@@ -60,7 +60,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
60
60
|
|
|
61
61
|
```yaml
|
|
62
62
|
- repo: https://github.com/stefmolin/docstringify
|
|
63
|
-
rev: 0.
|
|
63
|
+
rev: 0.2.0
|
|
64
64
|
hooks:
|
|
65
65
|
- id: docstringify
|
|
66
66
|
```
|
|
@@ -69,22 +69,32 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
69
69
|
|
|
70
70
|
```yaml
|
|
71
71
|
- repo: https://github.com/stefmolin/docstringify
|
|
72
|
-
rev: 0.
|
|
72
|
+
rev: 0.2.0
|
|
73
73
|
hooks:
|
|
74
74
|
- id: docstringify
|
|
75
75
|
args: [--threshold=0.75]
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument. By default, these will be [numpydoc-style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html#)
|
|
78
|
+
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument. By default, these will be [numpydoc-style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html#):
|
|
79
79
|
|
|
80
80
|
```yaml
|
|
81
81
|
- repo: https://github.com/stefmolin/docstringify
|
|
82
|
-
rev: 0.
|
|
82
|
+
rev: 0.2.0
|
|
83
83
|
hooks:
|
|
84
84
|
- id: docstringify
|
|
85
85
|
args: [--suggest-changes]
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
+
For [Google-style docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html), specify `--style google`:
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
- repo: https://github.com/stefmolin/docstringify
|
|
92
|
+
rev: 0.2.0
|
|
93
|
+
hooks:
|
|
94
|
+
- id: docstringify
|
|
95
|
+
args: [--suggest-changes, --style=google]
|
|
96
|
+
```
|
|
97
|
+
|
|
88
98
|
Be sure to check out the [pre-commit documentation](https://pre-commit.com/#pre-commit-configyaml---hooks) for additional configuration options.
|
|
89
99
|
|
|
90
100
|
### Command line
|
|
@@ -124,7 +134,7 @@ test.say_hello is missing a docstring
|
|
|
124
134
|
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide a converter:
|
|
125
135
|
|
|
126
136
|
```pycon
|
|
127
|
-
>>> from docstringify.converters
|
|
137
|
+
>>> from docstringify.converters import NumpydocDocstringConverter
|
|
128
138
|
>>> from docstringify.visitor import DocstringVisitor
|
|
129
139
|
>>> visitor = DocstringVisitor('test.py', converter=NumpydocDocstringConverter())
|
|
130
140
|
>>> visitor.process_file()
|
|
@@ -9,7 +9,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
9
9
|
|
|
10
10
|
```yaml
|
|
11
11
|
- repo: https://github.com/stefmolin/docstringify
|
|
12
|
-
rev: 0.
|
|
12
|
+
rev: 0.2.0
|
|
13
13
|
hooks:
|
|
14
14
|
- id: docstringify
|
|
15
15
|
```
|
|
@@ -18,22 +18,32 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
18
18
|
|
|
19
19
|
```yaml
|
|
20
20
|
- repo: https://github.com/stefmolin/docstringify
|
|
21
|
-
rev: 0.
|
|
21
|
+
rev: 0.2.0
|
|
22
22
|
hooks:
|
|
23
23
|
- id: docstringify
|
|
24
24
|
args: [--threshold=0.75]
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument. By default, these will be [numpydoc-style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html#)
|
|
27
|
+
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument. By default, these will be [numpydoc-style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html#):
|
|
28
28
|
|
|
29
29
|
```yaml
|
|
30
30
|
- repo: https://github.com/stefmolin/docstringify
|
|
31
|
-
rev: 0.
|
|
31
|
+
rev: 0.2.0
|
|
32
32
|
hooks:
|
|
33
33
|
- id: docstringify
|
|
34
34
|
args: [--suggest-changes]
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
For [Google-style docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html), specify `--style google`:
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
- repo: https://github.com/stefmolin/docstringify
|
|
41
|
+
rev: 0.2.0
|
|
42
|
+
hooks:
|
|
43
|
+
- id: docstringify
|
|
44
|
+
args: [--suggest-changes, --style=google]
|
|
45
|
+
```
|
|
46
|
+
|
|
37
47
|
Be sure to check out the [pre-commit documentation](https://pre-commit.com/#pre-commit-configyaml---hooks) for additional configuration options.
|
|
38
48
|
|
|
39
49
|
### Command line
|
|
@@ -73,7 +83,7 @@ test.say_hello is missing a docstring
|
|
|
73
83
|
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide a converter:
|
|
74
84
|
|
|
75
85
|
```pycon
|
|
76
|
-
>>> from docstringify.converters
|
|
86
|
+
>>> from docstringify.converters import NumpydocDocstringConverter
|
|
77
87
|
>>> from docstringify.visitor import DocstringVisitor
|
|
78
88
|
>>> visitor = DocstringVisitor('test.py', converter=NumpydocDocstringConverter())
|
|
79
89
|
>>> visitor.process_file()
|
|
@@ -5,7 +5,7 @@ import sys
|
|
|
5
5
|
from typing import Sequence
|
|
6
6
|
|
|
7
7
|
from . import __version__
|
|
8
|
-
from .converters
|
|
8
|
+
from .converters import GoogleDocstringConverter, NumpydocDocstringConverter
|
|
9
9
|
from .visitor import DocstringVisitor
|
|
10
10
|
|
|
11
11
|
PROG = __package__
|
|
@@ -25,11 +25,11 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
25
25
|
parser.add_argument(
|
|
26
26
|
'--suggest-changes',
|
|
27
27
|
action='store_true',
|
|
28
|
-
help='Whether to
|
|
28
|
+
help='Whether to print out docstring templates for items missing docstrings',
|
|
29
29
|
)
|
|
30
30
|
parser.add_argument(
|
|
31
31
|
'--style',
|
|
32
|
-
choices=['numpydoc'],
|
|
32
|
+
choices=['google', 'numpydoc'],
|
|
33
33
|
default='numpydoc',
|
|
34
34
|
help='The style of docstring to use (only used when --suggest-changes is passed)',
|
|
35
35
|
)
|
|
@@ -43,6 +43,8 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
43
43
|
|
|
44
44
|
if args.style is None or not args.suggest_changes:
|
|
45
45
|
converter = None
|
|
46
|
+
elif args.style == 'google':
|
|
47
|
+
converter = GoogleDocstringConverter()
|
|
46
48
|
elif args.style == 'numpydoc':
|
|
47
49
|
converter = NumpydocDocstringConverter()
|
|
48
50
|
else:
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Docstring converters."""
|
|
2
|
+
|
|
3
|
+
from .base import DocstringConverter
|
|
4
|
+
from .google import GoogleDocstringConverter
|
|
5
|
+
from .numpydoc import NumpydocDocstringConverter
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'DocstringConverter',
|
|
9
|
+
'GoogleDocstringConverter',
|
|
10
|
+
'NumpydocDocstringConverter',
|
|
11
|
+
]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Google-style docstring converter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ..components import DESCRIPTION_PLACEHOLDER, NO_DEFAULT, Function, Parameter
|
|
6
|
+
from .base import DocstringConverter
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GoogleDocstringConverter(DocstringConverter):
|
|
10
|
+
def __init__(self) -> None:
|
|
11
|
+
super().__init__(
|
|
12
|
+
parameters_section_template='Args:\n{parameters}',
|
|
13
|
+
returns_section_template='Returns:\n {returns}',
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
def to_function_docstring(self, function: Function) -> str:
|
|
17
|
+
# TODO: the visitor needs the triple quotes but the transformer does not
|
|
18
|
+
docstring = [f'"""{DESCRIPTION_PLACEHOLDER}']
|
|
19
|
+
|
|
20
|
+
if parameters_section := self.parameters_section(function.parameters):
|
|
21
|
+
docstring.extend(['', parameters_section])
|
|
22
|
+
|
|
23
|
+
if returns_section := self.returns_section(function.return_type):
|
|
24
|
+
docstring.extend(['', returns_section])
|
|
25
|
+
|
|
26
|
+
sep = '' if len(docstring) == 1 else '\n'
|
|
27
|
+
|
|
28
|
+
return sep.join([*docstring, '"""'])
|
|
29
|
+
|
|
30
|
+
def format_parameter(self, parameter: Parameter) -> str:
|
|
31
|
+
category = f'{f", {parameter.category}" if parameter.category else ""}'
|
|
32
|
+
return (
|
|
33
|
+
f' {parameter.name} ({parameter.type_}{category}): {DESCRIPTION_PLACEHOLDER} '
|
|
34
|
+
f'{f" Defaults to {parameter.default}." if parameter.default != NO_DEFAULT else ""}'
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def format_return(self, return_type: str | None) -> str:
|
|
38
|
+
if return_type:
|
|
39
|
+
return f'{return_type}: {DESCRIPTION_PLACEHOLDER}'
|
|
40
|
+
return ''
|
|
41
|
+
|
|
42
|
+
def to_module_docstring(self, module_name: str) -> str:
|
|
43
|
+
return f'"""{DESCRIPTION_PLACEHOLDER}"""'
|
|
44
|
+
|
|
45
|
+
def to_class_docstring(self, class_name: str) -> str:
|
|
46
|
+
return f'"""{DESCRIPTION_PLACEHOLDER}"""'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstringify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Flag missing docstrings and, optionally, generate them from signatures and type annotations.
|
|
5
5
|
Author-email: Stefanie Molin <docstringify@stefaniemolin.com>
|
|
6
6
|
License: MIT License
|
|
@@ -28,7 +28,7 @@ License: MIT License
|
|
|
28
28
|
Project-URL: Documentation, https://github.com/stefmolin/docstringify
|
|
29
29
|
Project-URL: Homepage, https://github.com/stefmolin/docstringify
|
|
30
30
|
Project-URL: Source, https://github.com/stefmolin/docstringify
|
|
31
|
-
Keywords: ast,docstring generation,numpydoc-style docstring,pre-commit
|
|
31
|
+
Keywords: ast,docstring generation,google-style docstring,numpydoc-style docstring,pre-commit
|
|
32
32
|
Classifier: Development Status :: 3 - Alpha
|
|
33
33
|
Classifier: License :: OSI Approved :: MIT License
|
|
34
34
|
Classifier: Programming Language :: Python
|
|
@@ -60,7 +60,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
60
60
|
|
|
61
61
|
```yaml
|
|
62
62
|
- repo: https://github.com/stefmolin/docstringify
|
|
63
|
-
rev: 0.
|
|
63
|
+
rev: 0.2.0
|
|
64
64
|
hooks:
|
|
65
65
|
- id: docstringify
|
|
66
66
|
```
|
|
@@ -69,22 +69,32 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
69
69
|
|
|
70
70
|
```yaml
|
|
71
71
|
- repo: https://github.com/stefmolin/docstringify
|
|
72
|
-
rev: 0.
|
|
72
|
+
rev: 0.2.0
|
|
73
73
|
hooks:
|
|
74
74
|
- id: docstringify
|
|
75
75
|
args: [--threshold=0.75]
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument. By default, these will be [numpydoc-style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html#)
|
|
78
|
+
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument. By default, these will be [numpydoc-style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html#):
|
|
79
79
|
|
|
80
80
|
```yaml
|
|
81
81
|
- repo: https://github.com/stefmolin/docstringify
|
|
82
|
-
rev: 0.
|
|
82
|
+
rev: 0.2.0
|
|
83
83
|
hooks:
|
|
84
84
|
- id: docstringify
|
|
85
85
|
args: [--suggest-changes]
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
+
For [Google-style docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html), specify `--style google`:
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
- repo: https://github.com/stefmolin/docstringify
|
|
92
|
+
rev: 0.2.0
|
|
93
|
+
hooks:
|
|
94
|
+
- id: docstringify
|
|
95
|
+
args: [--suggest-changes, --style=google]
|
|
96
|
+
```
|
|
97
|
+
|
|
88
98
|
Be sure to check out the [pre-commit documentation](https://pre-commit.com/#pre-commit-configyaml---hooks) for additional configuration options.
|
|
89
99
|
|
|
90
100
|
### Command line
|
|
@@ -124,7 +134,7 @@ test.say_hello is missing a docstring
|
|
|
124
134
|
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide a converter:
|
|
125
135
|
|
|
126
136
|
```pycon
|
|
127
|
-
>>> from docstringify.converters
|
|
137
|
+
>>> from docstringify.converters import NumpydocDocstringConverter
|
|
128
138
|
>>> from docstringify.visitor import DocstringVisitor
|
|
129
139
|
>>> visitor = DocstringVisitor('test.py', converter=NumpydocDocstringConverter())
|
|
130
140
|
>>> visitor.process_file()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"""Docstring converters."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|