docsig 0.46.0__tar.gz → 0.48.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: docsig
3
- Version: 0.46.0
3
+ Version: 0.48.0
4
4
  Summary: Check signature params for proper documentation
5
5
  Home-page: https://pypi.org/project/docsig/
6
6
  License: MIT
@@ -22,7 +22,6 @@ Requires-Dist: Sphinx (>=7.0.0,<8.0.0)
22
22
  Requires-Dist: arcon (>=0.4.0)
23
23
  Requires-Dist: astroid (>=3.0.1,<4.0.0)
24
24
  Requires-Dist: object-colors (>=2.1.0,<3.0.0)
25
- Requires-Dist: typing-extensions (>=4.8.0,<5.0.0)
26
25
  Project-URL: Documentation, https://docsig.readthedocs.io/en/latest
27
26
  Project-URL: Repository, https://github.com/jshwi/docsig
28
27
  Description-Content-Type: text/x-rst
@@ -106,8 +105,8 @@ Commandline
106
105
 
107
106
  .. code-block:: console
108
107
 
109
- usage: docsig [-h] [-V] [-l] [-c | -C] [-D] [-m] [-o] [-p] [-P] [-i] [-a] [-k]
110
- [-n] [-S] [-v] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
108
+ usage: docsig [-h] [-V] [-l] [-c | -C] [-D] [-m] [-N] [-o] [-p] [-P] [-i] [-a]
109
+ [-k] [-n] [-S] [-v] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
111
110
  [path [path ...]]
112
111
 
113
112
  Check signature params for proper documentation
@@ -125,6 +124,7 @@ Commandline
125
124
  -D, --check-dunders check dunder methods
126
125
  -m, --check-protected-class-methods check public methods belonging to protected
127
126
  classes
127
+ -N, --check-nested check nested functions and classes
128
128
  -o, --check-overridden check overridden methods
129
129
  -p, --check-protected check protected functions and classes
130
130
  -P, --check-property-returns check property return values
@@ -138,7 +138,7 @@ Commandline
138
138
  -s STR, --string STR string to parse instead of files
139
139
  -d LIST, --disable LIST comma separated list of rules to disable
140
140
  -t LIST, --target LIST comma separated list of rules to target
141
- -e EXCLUDE, --exclude EXCLUDE regular expression of files or dirs to exclude
141
+ -e PATTERN, --exclude PATTERN regular expression of files or dirs to exclude
142
142
  from checks
143
143
 
144
144
  Options can also be configured with the pyproject.toml file
@@ -181,7 +181,7 @@ API
181
181
  ... :param param3: About param3.
182
182
  ... '''
183
183
  ... """
184
- >>> docsig(string=string)
184
+ >>> docsig(string=string, no_ansi=True)
185
185
  0
186
186
 
187
187
  .. code-block:: python
@@ -195,7 +195,7 @@ API
195
195
  ... :param param3: About param3.
196
196
  ... '''
197
197
  ... """
198
- >>> docsig(string=string)
198
+ >>> docsig(string=string, no_ansi=True)
199
199
  2
200
200
  -
201
201
  def function(✓param1, ✓param2, ✖None) -> ✓None:
@@ -232,7 +232,7 @@ It can be added to your .pre-commit-config.yaml as follows:
232
232
 
233
233
  repos:
234
234
  - repo: https://github.com/jshwi/docsig
235
- rev: v0.46.0
235
+ rev: v0.48.0
236
236
  hooks:
237
237
  - id: docsig
238
238
  args:
@@ -77,8 +77,8 @@ Commandline
77
77
 
78
78
  .. code-block:: console
79
79
 
80
- usage: docsig [-h] [-V] [-l] [-c | -C] [-D] [-m] [-o] [-p] [-P] [-i] [-a] [-k]
81
- [-n] [-S] [-v] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
80
+ usage: docsig [-h] [-V] [-l] [-c | -C] [-D] [-m] [-N] [-o] [-p] [-P] [-i] [-a]
81
+ [-k] [-n] [-S] [-v] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
82
82
  [path [path ...]]
83
83
 
84
84
  Check signature params for proper documentation
@@ -96,6 +96,7 @@ Commandline
96
96
  -D, --check-dunders check dunder methods
97
97
  -m, --check-protected-class-methods check public methods belonging to protected
98
98
  classes
99
+ -N, --check-nested check nested functions and classes
99
100
  -o, --check-overridden check overridden methods
100
101
  -p, --check-protected check protected functions and classes
101
102
  -P, --check-property-returns check property return values
@@ -109,7 +110,7 @@ Commandline
109
110
  -s STR, --string STR string to parse instead of files
110
111
  -d LIST, --disable LIST comma separated list of rules to disable
111
112
  -t LIST, --target LIST comma separated list of rules to target
112
- -e EXCLUDE, --exclude EXCLUDE regular expression of files or dirs to exclude
113
+ -e PATTERN, --exclude PATTERN regular expression of files or dirs to exclude
113
114
  from checks
114
115
 
115
116
  Options can also be configured with the pyproject.toml file
@@ -152,7 +153,7 @@ API
152
153
  ... :param param3: About param3.
153
154
  ... '''
154
155
  ... """
155
- >>> docsig(string=string)
156
+ >>> docsig(string=string, no_ansi=True)
156
157
  0
157
158
 
158
159
  .. code-block:: python
@@ -166,7 +167,7 @@ API
166
167
  ... :param param3: About param3.
167
168
  ... '''
168
169
  ... """
169
- >>> docsig(string=string)
170
+ >>> docsig(string=string, no_ansi=True)
170
171
  2
171
172
  -
172
173
  def function(✓param1, ✓param2, ✖None) -> ✓None:
@@ -203,7 +204,7 @@ It can be added to your .pre-commit-config.yaml as follows:
203
204
 
204
205
  repos:
205
206
  - repo: https://github.com/jshwi/docsig
206
- rev: v0.46.0
207
+ rev: v0.48.0
207
208
  hooks:
208
209
  - id: docsig
209
210
  args:
@@ -67,6 +67,12 @@ class Parser(_ArgumentParser):
67
67
  action="store_true",
68
68
  help="check public methods belonging to protected classes",
69
69
  )
70
+ self.add_argument(
71
+ "-N",
72
+ "--check-nested",
73
+ action="store_true",
74
+ help="check nested functions and classes",
75
+ )
70
76
  self.add_argument(
71
77
  "-o",
72
78
  "--check-overridden",
@@ -143,5 +149,6 @@ class Parser(_ArgumentParser):
143
149
  self.add_argument(
144
150
  "-e",
145
151
  "--exclude",
152
+ metavar="PATTERN",
146
153
  help="regular expression of files or dirs to exclude from checks",
147
154
  )
@@ -13,9 +13,10 @@ from ._display import Failure as _Failure
13
13
  from ._display import Failures as _Failures
14
14
  from ._display import FuncStr as _FuncStr
15
15
  from ._message import Message as _Message
16
+ from ._module import Function as _Function
16
17
  from ._module import Modules as _Modules
17
18
  from ._module import Parent as _Parent
18
- from ._report import generate_report as _generate_report
19
+ from ._report import Report as _Report
19
20
  from .messages import TEMPLATE as _TEMPLATE
20
21
  from .messages import E as _E
21
22
 
@@ -45,40 +46,75 @@ def _print_checks() -> None:
45
46
 
46
47
 
47
48
  def _run_check( # pylint: disable=too-many-arguments
49
+ child: _Parent,
48
50
  parent: _Parent,
49
51
  check_class: bool,
50
52
  check_class_constructor: bool,
51
53
  check_dunders: bool,
54
+ check_nested: bool,
52
55
  check_overridden: bool,
53
56
  check_protected: bool,
54
57
  check_property_returns: bool,
55
58
  ignore_no_params: bool,
56
59
  no_ansi: bool,
57
60
  targets: list[_Message],
58
- ) -> _Failures:
59
- failures = _Failures()
60
- for func in parent:
61
- if not (func.isoverridden and not check_overridden) and (
62
- not (func.isprotected and not check_protected)
61
+ failures: _Failures,
62
+ ) -> None:
63
+ if isinstance(child, _Function):
64
+ if not (child.isoverridden and not check_overridden) and (
65
+ not (child.isprotected and not check_protected)
63
66
  and not (
64
- func.isinit
67
+ child.isinit
65
68
  and not (
66
69
  (check_class or check_class_constructor)
67
70
  and not (parent.isprotected and not check_protected)
68
71
  )
69
72
  )
70
- and not (func.isdunder and not check_dunders)
71
- and not (func.docstring.bare and ignore_no_params)
73
+ and not (child.isdunder and not check_dunders)
74
+ and not (child.docstring.bare and ignore_no_params)
72
75
  ):
73
- report = _generate_report(
74
- func, targets, func.disabled, check_property_returns
76
+ report = _Report(
77
+ child, targets, child.disabled, check_property_returns
75
78
  )
76
79
  if report:
77
80
  failures.append(
78
- _Failure(func, _FuncStr(func, no_ansi), report)
81
+ _Failure(child, _FuncStr(child, no_ansi), report)
79
82
  )
80
83
 
81
- return failures
84
+ if check_nested:
85
+ for func in child:
86
+ _run_check(
87
+ func,
88
+ child,
89
+ check_class,
90
+ check_class_constructor,
91
+ check_dunders,
92
+ check_nested,
93
+ check_overridden,
94
+ check_protected,
95
+ check_property_returns,
96
+ ignore_no_params,
97
+ no_ansi,
98
+ targets,
99
+ failures,
100
+ )
101
+ else:
102
+ for func in child:
103
+ _run_check(
104
+ func,
105
+ child,
106
+ check_class,
107
+ check_class_constructor,
108
+ check_dunders,
109
+ check_nested,
110
+ check_overridden,
111
+ check_protected,
112
+ check_property_returns,
113
+ ignore_no_params,
114
+ no_ansi,
115
+ targets,
116
+ failures,
117
+ )
82
118
 
83
119
 
84
120
  @_decorators.parse_msgs
@@ -91,6 +127,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
91
127
  check_class_constructor: bool = False,
92
128
  check_dunders: bool = False,
93
129
  check_protected_class_methods: bool = False,
130
+ check_nested: bool = False,
94
131
  check_overridden: bool = False,
95
132
  check_protected: bool = False,
96
133
  check_property_returns: bool = False,
@@ -122,6 +159,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
122
159
  :param check_dunders: Check dunder methods
123
160
  :param check_protected_class_methods: Check public methods belonging
124
161
  to protected classes.
162
+ :param check_nested: Check nested functions and classes.
125
163
  :param check_overridden: Check overridden methods
126
164
  :param check_protected: Check protected functions and classes.
127
165
  :param check_property_returns: Run return checks on properties.
@@ -163,17 +201,21 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
163
201
  or check_protected
164
202
  or check_protected_class_methods
165
203
  ):
166
- failures = _run_check(
204
+ failures = _Failures()
205
+ _run_check(
167
206
  top_level,
207
+ module,
168
208
  check_class,
169
209
  check_class_constructor,
170
210
  check_dunders,
211
+ check_nested,
171
212
  check_overridden,
172
213
  check_protected,
173
214
  check_property_returns,
174
215
  ignore_no_params,
175
216
  no_ansi,
176
217
  targets or [],
218
+ failures,
177
219
  )
178
220
  if failures:
179
221
  display[top_level.path].append(failures)
@@ -59,7 +59,7 @@ def validate_args(func: _FuncType) -> _WrappedFuncType:
59
59
  for message in kwargs.get("targets") or []:
60
60
  if not message.isknown:
61
61
  stderr.append(
62
- f"unknown option to target '{message.description}'",
62
+ f"unknown option to target '{message.description}'"
63
63
  )
64
64
 
65
65
  if kwargs.get("check_class") and kwargs.get(
@@ -10,8 +10,6 @@ import tokenize as _tokenize
10
10
  import typing as _t
11
11
  from io import StringIO as _StringIO
12
12
 
13
- from typing_extensions import Self as _Self
14
-
15
13
  from ._message import Message as _Message
16
14
  from .messages import E as _E
17
15
 
@@ -96,7 +94,7 @@ class Directive:
96
94
  return self._kind == self._valid_kinds[1]
97
95
 
98
96
  @classmethod
99
- def parse(cls, comment: str, col: int) -> _Self | None:
97
+ def parse(cls, comment: str, col: int) -> Directive | None:
100
98
  """Parse string into directive object if possible.
101
99
 
102
100
  :param comment: Comment to parse.
@@ -17,11 +17,11 @@ from pygments.formatters.terminal256 import (
17
17
  # noinspection PyUnresolvedReferences
18
18
  from pygments.lexers.python import PythonLexer as _PythonLexer
19
19
 
20
- from ._function import ARG as _ARG
21
- from ._function import KEY as _KEY
22
- from ._function import Function as _Function
23
- from ._function import Param as _Param
20
+ from ._module import Function as _Function
24
21
  from ._report import Report as _Report
22
+ from ._stub import ARG as _ARG
23
+ from ._stub import KEY as _KEY
24
+ from ._stub import Param as _Param
25
25
 
26
26
  color = _Color()
27
27
 
@@ -209,15 +209,7 @@ class Failures(_t.List[Failure]):
209
209
  """Sequence of failed functions."""
210
210
 
211
211
 
212
- class _DisplaySequence(_t.Dict[str, _t.List[Failures]]):
213
- def __getitem__(self, key: str) -> list[Failures]:
214
- if key not in super().__iter__():
215
- super().__setitem__(key, [])
216
-
217
- return super().__getitem__(key)
218
-
219
-
220
- class Display(_DisplaySequence):
212
+ class Display(_t.Dict[str, _t.List[Failures]]):
221
213
  """Collect and display report.
222
214
 
223
215
  :param no_ansi: Disable ANSI output.
@@ -227,6 +219,12 @@ class Display(_DisplaySequence):
227
219
  super().__init__()
228
220
  self._ansi = _ANSI(no_ansi)
229
221
 
222
+ def __getitem__(self, key: str) -> list[Failures]:
223
+ if key not in super().__iter__():
224
+ super().__setitem__(key, [])
225
+
226
+ return super().__getitem__(key)
227
+
230
228
  def report(self) -> None:
231
229
  """Display report if any checks have failed."""
232
230
  for key, value in self.items():
@@ -253,8 +251,8 @@ class Display(_DisplaySequence):
253
251
 
254
252
  header += f" in {function}"
255
253
  print(
256
- "{}\n\t{}".format(
254
+ "{}\n {}".format(
257
255
  self._ansi.color(header, color.magenta),
258
- failure.report.get_report("\t").strip(),
256
+ failure.report.get_report(" ").strip(),
259
257
  )
260
258
  )
@@ -0,0 +1,45 @@
1
+ """
2
+ docsig._main
3
+ ============
4
+
5
+ Contains package entry point.
6
+ """
7
+
8
+ from __future__ import annotations as _
9
+
10
+ from ._config import Parser as _Parser
11
+ from ._core import docsig as _docsig
12
+ from ._hooks import pretty_print_error as _pretty_print_error
13
+
14
+
15
+ def main() -> str | int:
16
+ """Main function for package.
17
+
18
+ Collect config and arguments for the commandline.
19
+
20
+ :return: Exit status for whether test failed or not.
21
+ """
22
+ p = _Parser()
23
+ _pretty_print_error()
24
+ return _docsig(
25
+ *p.args.path,
26
+ string=p.args.string,
27
+ list_checks=p.args.list_checks,
28
+ check_class=p.args.check_class,
29
+ check_class_constructor=p.args.check_class_constructor,
30
+ check_dunders=p.args.check_dunders,
31
+ check_protected_class_methods=p.args.check_protected_class_methods,
32
+ check_nested=p.args.check_nested,
33
+ check_overridden=p.args.check_overridden,
34
+ check_protected=p.args.check_protected,
35
+ check_property_returns=p.args.check_property_returns,
36
+ ignore_no_params=p.args.ignore_no_params,
37
+ ignore_args=p.args.ignore_args,
38
+ ignore_kwargs=p.args.ignore_kwargs,
39
+ no_ansi=p.args.no_ansi,
40
+ summary=p.args.summary,
41
+ verbose=p.args.verbose,
42
+ targets=p.args.target,
43
+ disable=p.args.disable,
44
+ exclude=p.args.exclude,
45
+ )