docsig 0.44.3__tar.gz → 0.46.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.44.3
3
+ Version: 0.46.0
4
4
  Summary: Check signature params for proper documentation
5
5
  Home-page: https://pypi.org/project/docsig/
6
6
  License: MIT
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
20
  Requires-Dist: Pygments (>=2.13.0,<3.0.0)
21
21
  Requires-Dist: Sphinx (>=7.0.0,<8.0.0)
22
- Requires-Dist: arcon (>=0.3.1,<0.4.0)
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
25
  Requires-Dist: typing-extensions (>=4.8.0,<5.0.0)
@@ -106,8 +106,8 @@ Commandline
106
106
 
107
107
  .. code-block:: console
108
108
 
109
- usage: docsig [-h] [-v] [-l] [-c | -C] [-D] [-m] [-o] [-p] [-P] [-i] [-a] [-k]
110
- [-n] [-S] [-s STR] [-d LIST] [-t LIST]
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]
111
111
  [path [path ...]]
112
112
 
113
113
  Check signature params for proper documentation
@@ -117,7 +117,7 @@ Commandline
117
117
 
118
118
  optional arguments:
119
119
  -h, --help show this help message and exit
120
- -v, --version show program's version number and exit
120
+ -V, --version show program's version number and exit
121
121
  -l, --list-checks display a list of all checks and their messages
122
122
  -c, --check-class check class docstrings
123
123
  -C, --check-class-constructor check __init__ methods. Note: mutually
@@ -134,9 +134,12 @@ Commandline
134
134
  -k, --ignore-kwargs ignore kwargs prefixed with two asterisks
135
135
  -n, --no-ansi disable ansi output
136
136
  -S, --summary print a summarised report
137
+ -v, --verbose increase output verbosity
137
138
  -s STR, --string STR string to parse instead of files
138
139
  -d LIST, --disable LIST comma separated list of rules to disable
139
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
142
+ from checks
140
143
 
141
144
  Options can also be configured with the pyproject.toml file
142
145
 
@@ -229,7 +232,7 @@ It can be added to your .pre-commit-config.yaml as follows:
229
232
 
230
233
  repos:
231
234
  - repo: https://github.com/jshwi/docsig
232
- rev: v0.44.3
235
+ rev: v0.46.0
233
236
  hooks:
234
237
  - id: docsig
235
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] [-s STR] [-d LIST] [-t LIST]
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]
82
82
  [path [path ...]]
83
83
 
84
84
  Check signature params for proper documentation
@@ -88,7 +88,7 @@ Commandline
88
88
 
89
89
  optional arguments:
90
90
  -h, --help show this help message and exit
91
- -v, --version show program's version number and exit
91
+ -V, --version show program's version number and exit
92
92
  -l, --list-checks display a list of all checks and their messages
93
93
  -c, --check-class check class docstrings
94
94
  -C, --check-class-constructor check __init__ methods. Note: mutually
@@ -105,9 +105,12 @@ Commandline
105
105
  -k, --ignore-kwargs ignore kwargs prefixed with two asterisks
106
106
  -n, --no-ansi disable ansi output
107
107
  -S, --summary print a summarised report
108
+ -v, --verbose increase output verbosity
108
109
  -s STR, --string STR string to parse instead of files
109
110
  -d LIST, --disable LIST comma separated list of rules to disable
110
111
  -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
+ from checks
111
114
 
112
115
  Options can also be configured with the pyproject.toml file
113
116
 
@@ -200,7 +203,7 @@ It can be added to your .pre-commit-config.yaml as follows:
200
203
 
201
204
  repos:
202
205
  - repo: https://github.com/jshwi/docsig
203
- rev: v0.44.3
206
+ rev: v0.46.0
204
207
  hooks:
205
208
  - id: docsig
206
209
  args:
@@ -23,6 +23,7 @@ class Parser(_ArgumentParser):
23
23
  prog, max_help_position=45
24
24
  ),
25
25
  description="Check signature params for proper documentation",
26
+ version_short_form="-V",
26
27
  )
27
28
  self._add_arguments()
28
29
  self.args = self.parse_args()
@@ -114,6 +115,12 @@ class Parser(_ArgumentParser):
114
115
  action="store_true",
115
116
  help="print a summarised report",
116
117
  )
118
+ self.add_argument(
119
+ "-v",
120
+ "--verbose",
121
+ action="store_true",
122
+ help="increase output verbosity",
123
+ )
117
124
  self.add_argument(
118
125
  "-s",
119
126
  "--string",
@@ -133,3 +140,8 @@ class Parser(_ArgumentParser):
133
140
  metavar="LIST",
134
141
  help="comma separated list of rules to target",
135
142
  )
143
+ self.add_argument(
144
+ "-e",
145
+ "--exclude",
146
+ help="regular expression of files or dirs to exclude from checks",
147
+ )
@@ -19,6 +19,25 @@ from ._report import generate_report as _generate_report
19
19
  from .messages import TEMPLATE as _TEMPLATE
20
20
  from .messages import E as _E
21
21
 
22
+ _DEFAULT_EXCLUDES = """\
23
+ (?x)^(
24
+ |\\.?venv
25
+ |\\.git
26
+ |\\.hg
27
+ |\\.idea
28
+ |\\.mypy_cache
29
+ |\\.nox
30
+ |\\.pytest_cache
31
+ |\\.svn
32
+ |\\.tox
33
+ |\\.vscode
34
+ |_?build
35
+ |__pycache__
36
+ |dist
37
+ |node_modules
38
+ )$
39
+ """
40
+
22
41
 
23
42
  def _print_checks() -> None:
24
43
  for msg in _E.values():
@@ -80,8 +99,10 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
80
99
  ignore_kwargs: bool = False,
81
100
  no_ansi: bool = False,
82
101
  summary: bool = False,
102
+ verbose: bool = False,
83
103
  targets: list[_Message] | None = None,
84
104
  disable: list[_Message] | None = None,
105
+ exclude: str | None = None,
85
106
  ) -> int:
86
107
  """Package's core functionality.
87
108
 
@@ -110,20 +131,29 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
110
131
  :param ignore_kwargs: Ignore kwargs prefixed with two asterisks.
111
132
  :param no_ansi: Disable ANSI output.
112
133
  :param summary: Print a summarised report.
134
+ :param verbose: increase output verbosity.
113
135
  :param targets: List of errors to target.
114
136
  :param disable: List of errors to disable.
137
+ :param exclude: Regular expression of files and dirs to exclude from
138
+ checks.
115
139
  :return: Exit status for whether test failed or not.
116
140
  """
117
141
  if list_checks:
118
142
  return int(bool(_print_checks())) # type: ignore
119
143
 
144
+ excludes = [_DEFAULT_EXCLUDES]
145
+ if exclude is not None:
146
+ excludes.append(exclude)
147
+
120
148
  modules = _Modules(
121
149
  *tuple(_Path(i) for i in path),
122
150
  disable=disable or [],
123
151
  string=string,
152
+ excludes=excludes,
124
153
  ignore_args=ignore_args,
125
154
  ignore_kwargs=ignore_kwargs,
126
155
  check_class_constructor=check_class_constructor,
156
+ verbose=verbose,
127
157
  )
128
158
  display = _Display(no_ansi)
129
159
  for module in modules:
@@ -319,7 +319,9 @@ class Function: # pylint: disable=too-many-arguments
319
319
  def _decorated_with(self, name: str) -> bool:
320
320
  if self._node.decorators is not None:
321
321
  for dec in self._node.decorators.nodes:
322
- return isinstance(dec, _ast.Name) and dec.name == name
322
+ return (isinstance(dec, _ast.Name) and dec.name == name) or (
323
+ isinstance(dec, _ast.Attribute) and dec.attrname == name
324
+ )
323
325
 
324
326
  return False
325
327
 
@@ -333,11 +335,6 @@ class Function: # pylint: disable=too-many-arguments
333
335
  """Boolean value for whether function is a property."""
334
336
  valid_properties = [
335
337
  "property",
336
- # todo: this should be inferred as various import styles or
337
- # todo: aliases won't be recognised
338
- # todo:
339
- # todo: it appears overloaded is inferred, if it isn't, look
340
- # todo: at that too
341
338
  "cached_property",
342
339
  ]
343
340
  return self.ismethod and any(
@@ -39,6 +39,8 @@ def main() -> str | int:
39
39
  ignore_kwargs=parser.args.ignore_kwargs,
40
40
  no_ansi=parser.args.no_ansi,
41
41
  summary=parser.args.summary,
42
+ verbose=parser.args.verbose,
42
43
  targets=parser.args.target,
43
44
  disable=parser.args.disable,
45
+ exclude=parser.args.exclude,
44
46
  )
@@ -5,15 +5,20 @@ docsig._module
5
5
 
6
6
  from __future__ import annotations as _
7
7
 
8
+ import re as _re
8
9
  import typing as _t
9
10
  from pathlib import Path as _Path
10
11
 
11
12
  import astroid as _ast
13
+ from astroid import AstroidSyntaxError as _AstroidSyntaxError
12
14
 
13
15
  from ._directives import Directives as _Directives
14
16
  from ._function import Function as _Function
15
17
  from ._message import Message as _Message
16
18
  from ._utils import isprotected as _isprotected
19
+ from ._utils import vprint as _vprint
20
+
21
+ _FILE_INFO = "{path}: {msg}"
17
22
 
18
23
 
19
24
  class Parent(_t.List[_Function]):
@@ -128,37 +133,87 @@ class Modules(_t.List[_Module]):
128
133
 
129
134
  :param paths: Path(s) to parse ``Module``(s) from.
130
135
  :param disable: List of checks to disable.
136
+ :param excludes: List pf regular expression of files and dirs to
137
+ exclude from checks.
131
138
  :param string: String to parse if provided.
132
139
  :param ignore_args: Ignore args prefixed with an asterisk.
133
140
  :param ignore_kwargs: Ignore kwargs prefixed with two asterisks.
134
141
  :param check_class_constructor: Check the class constructor's
135
142
  docstring. Otherwise, expect the constructor's documentation to
136
143
  be on the class level docstring.
144
+ :param verbose: increase output verbosity.
137
145
  """
138
146
 
147
+ # handle errors here before appending a module
148
+ def _add_module( # pylint: disable=too-many-arguments
149
+ self,
150
+ disable: list[_Message],
151
+ string: str | None = None,
152
+ root: _Path | None = None,
153
+ ignore_args: bool = False,
154
+ ignore_kwargs: bool = False,
155
+ check_class_constructor: bool = False,
156
+ ) -> None:
157
+ try:
158
+ if root is not None:
159
+ string = root.read_text(encoding="utf-8")
160
+
161
+ self.append(
162
+ _Module(
163
+ # empty string won't happen but keeps the
164
+ # typechecker happy
165
+ string or "",
166
+ disable,
167
+ root,
168
+ ignore_args,
169
+ ignore_kwargs,
170
+ check_class_constructor,
171
+ )
172
+ )
173
+ except (_AstroidSyntaxError, UnicodeDecodeError) as err:
174
+ if root is not None and root.name.endswith(".py"):
175
+ # keep raising errors for .py files as was done prior to
176
+ # this change
177
+ # pass by silently for files that do not end with .py,
178
+ # which were not checked at all prior (these may result
179
+ # in a 123 syntax error exit status in the future)
180
+ # with this there should be no breaking change, and
181
+ # files that are supposed to be python, files evident by
182
+ # their suffix, will continue to fail
183
+ raise err
184
+
185
+ _vprint(
186
+ _FILE_INFO.format(
187
+ path=root or "stdin", msg=str(err).replace("\n", " ")
188
+ ),
189
+ self._verbose,
190
+ )
191
+
139
192
  def __init__( # pylint: disable=too-many-arguments
140
193
  self,
141
194
  *paths: _Path,
142
195
  disable: list[_Message],
196
+ excludes: list[str],
143
197
  string: str | None = None,
144
198
  ignore_args: bool = False,
145
199
  ignore_kwargs: bool = False,
146
200
  check_class_constructor: bool = False,
201
+ verbose: bool = False,
147
202
  ) -> None:
148
203
  super().__init__()
149
204
  self._disable = disable
205
+ self._excludes = excludes
150
206
  self._ignore_args = ignore_args
151
207
  self._ignore_kwargs = ignore_kwargs
152
208
  self.check_class_constructor = check_class_constructor
209
+ self._verbose = verbose
153
210
  if string is not None:
154
- self.append(
155
- _Module(
156
- string,
157
- disable,
158
- ignore_args=ignore_args,
159
- ignore_kwargs=ignore_kwargs,
160
- check_class_constructor=check_class_constructor,
161
- )
211
+ self._add_module(
212
+ disable,
213
+ string=string,
214
+ ignore_args=ignore_args,
215
+ ignore_kwargs=ignore_kwargs,
216
+ check_class_constructor=check_class_constructor,
162
217
  )
163
218
  else:
164
219
  for path in paths:
@@ -168,16 +223,22 @@ class Modules(_t.List[_Module]):
168
223
  if not root.exists():
169
224
  raise FileNotFoundError(root)
170
225
 
171
- if root.is_file() and root.name.endswith(".py"):
172
- self.append(
173
- _Module(
174
- root.read_text(encoding="utf-8"),
175
- self._disable,
176
- root,
177
- self._ignore_args,
178
- self._ignore_kwargs,
179
- self.check_class_constructor,
180
- )
226
+ if str(root) != "." and any(
227
+ _re.match(i, root.name) for i in self._excludes
228
+ ):
229
+ _vprint(
230
+ _FILE_INFO.format(path=root, msg="in exclude list, skipping"),
231
+ self._verbose,
232
+ )
233
+ return
234
+
235
+ if root.is_file():
236
+ self._add_module(
237
+ self._disable,
238
+ root=root,
239
+ ignore_args=self._ignore_args,
240
+ ignore_kwargs=self._ignore_kwargs,
241
+ check_class_constructor=self.check_class_constructor,
181
242
  )
182
243
 
183
244
  if root.is_dir():
@@ -28,3 +28,13 @@ def almost_equal(str1: str, str2: str, mini: float, maxi: float) -> bool:
28
28
  :return: Boolean result for whether both strings are almost equal.
29
29
  """
30
30
  return mini < _SequenceMatcher(a=str1, b=str2).ratio() < maxi
31
+
32
+
33
+ def vprint(msg: str, verbose: bool = False) -> None:
34
+ """Print messages only if verbose is true.
35
+
36
+ :param msg: Message to print.
37
+ :param verbose: Whether verbose mode is enabled.
38
+ """
39
+ if verbose:
40
+ print(msg)
@@ -8,4 +8,4 @@ Allows for access to the version internally without cyclic imports
8
8
  caused by accessing it through __init__.
9
9
  """
10
10
 
11
- __version__ = "0.44.3"
11
+ __version__ = "0.46.0"
@@ -72,12 +72,12 @@ maintainers = [
72
72
  name = "docsig"
73
73
  readme = "README.rst"
74
74
  repository = "https://github.com/jshwi/docsig"
75
- version = "0.44.3"
75
+ version = "0.46.0"
76
76
 
77
77
  [tool.poetry.dependencies]
78
78
  Pygments = "^2.13.0"
79
79
  Sphinx = "^7.0.0"
80
- arcon = "^0.3.1"
80
+ arcon = ">=0.4.0"
81
81
  astroid = "^3.0.1"
82
82
  object-colors = "^2.1.0"
83
83
  python = "^3.8"
@@ -85,7 +85,7 @@ typing-extensions = "^4.8.0"
85
85
 
86
86
  [tool.poetry.dev-dependencies]
87
87
  bump2version = "^1.0.1"
88
- deptry = "^0.14.2"
88
+ deptry = "^0.16.1"
89
89
  ipython = "^8.12.0"
90
90
  pre-commit = "^3.3.3"
91
91
  pyaud = "^7.5.0"
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