docsig 0.44.3__tar.gz → 0.45.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.45.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.3.1)
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)
@@ -107,7 +107,7 @@ Commandline
107
107
  .. code-block:: console
108
108
 
109
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]
110
+ [-n] [-S] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
111
111
  [path [path ...]]
112
112
 
113
113
  Check signature params for proper documentation
@@ -137,6 +137,8 @@ Commandline
137
137
  -s STR, --string STR string to parse instead of files
138
138
  -d LIST, --disable LIST comma separated list of rules to disable
139
139
  -t LIST, --target LIST comma separated list of rules to target
140
+ -e EXCLUDE, --exclude EXCLUDE regular expression of files or dirs to exclude
141
+ from checks
140
142
 
141
143
  Options can also be configured with the pyproject.toml file
142
144
 
@@ -229,7 +231,7 @@ It can be added to your .pre-commit-config.yaml as follows:
229
231
 
230
232
  repos:
231
233
  - repo: https://github.com/jshwi/docsig
232
- rev: v0.44.3
234
+ rev: v0.45.0
233
235
  hooks:
234
236
  - id: docsig
235
237
  args:
@@ -78,7 +78,7 @@ Commandline
78
78
  .. code-block:: console
79
79
 
80
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]
81
+ [-n] [-S] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
82
82
  [path [path ...]]
83
83
 
84
84
  Check signature params for proper documentation
@@ -108,6 +108,8 @@ Commandline
108
108
  -s STR, --string STR string to parse instead of files
109
109
  -d LIST, --disable LIST comma separated list of rules to disable
110
110
  -t LIST, --target LIST comma separated list of rules to target
111
+ -e EXCLUDE, --exclude EXCLUDE regular expression of files or dirs to exclude
112
+ from checks
111
113
 
112
114
  Options can also be configured with the pyproject.toml file
113
115
 
@@ -200,7 +202,7 @@ It can be added to your .pre-commit-config.yaml as follows:
200
202
 
201
203
  repos:
202
204
  - repo: https://github.com/jshwi/docsig
203
- rev: v0.44.3
205
+ rev: v0.45.0
204
206
  hooks:
205
207
  - id: docsig
206
208
  args:
@@ -133,3 +133,8 @@ class Parser(_ArgumentParser):
133
133
  metavar="LIST",
134
134
  help="comma separated list of rules to target",
135
135
  )
136
+ self.add_argument(
137
+ "-e",
138
+ "--exclude",
139
+ help="regular expression of files or dirs to exclude from checks",
140
+ )
@@ -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():
@@ -82,6 +101,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
82
101
  summary: bool = False,
83
102
  targets: list[_Message] | None = None,
84
103
  disable: list[_Message] | None = None,
104
+ exclude: str | None = None,
85
105
  ) -> int:
86
106
  """Package's core functionality.
87
107
 
@@ -112,15 +132,22 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
112
132
  :param summary: Print a summarised report.
113
133
  :param targets: List of errors to target.
114
134
  :param disable: List of errors to disable.
135
+ :param exclude: Regular expression of files and dirs to exclude from
136
+ checks.
115
137
  :return: Exit status for whether test failed or not.
116
138
  """
117
139
  if list_checks:
118
140
  return int(bool(_print_checks())) # type: ignore
119
141
 
142
+ excludes = [_DEFAULT_EXCLUDES]
143
+ if exclude is not None:
144
+ excludes.append(exclude)
145
+
120
146
  modules = _Modules(
121
147
  *tuple(_Path(i) for i in path),
122
148
  disable=disable or [],
123
149
  string=string,
150
+ excludes=excludes,
124
151
  ignore_args=ignore_args,
125
152
  ignore_kwargs=ignore_kwargs,
126
153
  check_class_constructor=check_class_constructor,
@@ -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(
@@ -41,4 +41,5 @@ def main() -> str | int:
41
41
  summary=parser.args.summary,
42
42
  targets=parser.args.target,
43
43
  disable=parser.args.disable,
44
+ exclude=parser.args.exclude,
44
45
  )
@@ -5,10 +5,12 @@ 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
@@ -128,6 +130,8 @@ class Modules(_t.List[_Module]):
128
130
 
129
131
  :param paths: Path(s) to parse ``Module``(s) from.
130
132
  :param disable: List of checks to disable.
133
+ :param excludes: List pf regular expression of files and dirs to
134
+ exclude from checks.
131
135
  :param string: String to parse if provided.
132
136
  :param ignore_args: Ignore args prefixed with an asterisk.
133
137
  :param ignore_kwargs: Ignore kwargs prefixed with two asterisks.
@@ -136,10 +140,49 @@ class Modules(_t.List[_Module]):
136
140
  be on the class level docstring.
137
141
  """
138
142
 
143
+ # handle errors here before appending a module
144
+ def _add_module( # pylint: disable=too-many-arguments
145
+ self,
146
+ disable: list[_Message],
147
+ string: str | None = None,
148
+ root: _Path | None = None,
149
+ ignore_args: bool = False,
150
+ ignore_kwargs: bool = False,
151
+ check_class_constructor: bool = False,
152
+ ) -> None:
153
+ try:
154
+ if root is not None:
155
+ string = root.read_text(encoding="utf-8")
156
+
157
+ self.append(
158
+ _Module(
159
+ # empty string won't happen but keeps the
160
+ # typechecker happy
161
+ string or "",
162
+ disable,
163
+ root,
164
+ ignore_args,
165
+ ignore_kwargs,
166
+ check_class_constructor,
167
+ )
168
+ )
169
+ except (_AstroidSyntaxError, UnicodeDecodeError) as err:
170
+ if root is not None and root.name.endswith(".py"):
171
+ # keep raising errors for .py files as was done prior to
172
+ # this change
173
+ # pass by silently for files that do not end with .py,
174
+ # which were not checked at all prior (these may result
175
+ # in a 123 syntax error exit status in the future)
176
+ # with this there should be no breaking change, and
177
+ # files that are supposed to be python, files evident by
178
+ # their suffix, will continue to fail
179
+ raise err
180
+
139
181
  def __init__( # pylint: disable=too-many-arguments
140
182
  self,
141
183
  *paths: _Path,
142
184
  disable: list[_Message],
185
+ excludes: list[str],
143
186
  string: str | None = None,
144
187
  ignore_args: bool = False,
145
188
  ignore_kwargs: bool = False,
@@ -147,18 +190,17 @@ class Modules(_t.List[_Module]):
147
190
  ) -> None:
148
191
  super().__init__()
149
192
  self._disable = disable
193
+ self._excludes = excludes
150
194
  self._ignore_args = ignore_args
151
195
  self._ignore_kwargs = ignore_kwargs
152
196
  self.check_class_constructor = check_class_constructor
153
197
  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
- )
198
+ self._add_module(
199
+ disable,
200
+ string=string,
201
+ ignore_args=ignore_args,
202
+ ignore_kwargs=ignore_kwargs,
203
+ check_class_constructor=check_class_constructor,
162
204
  )
163
205
  else:
164
206
  for path in paths:
@@ -168,16 +210,18 @@ class Modules(_t.List[_Module]):
168
210
  if not root.exists():
169
211
  raise FileNotFoundError(root)
170
212
 
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
- )
213
+ if str(root) != "." and any(
214
+ _re.match(i, root.name) for i in self._excludes
215
+ ):
216
+ return
217
+
218
+ if root.is_file():
219
+ self._add_module(
220
+ self._disable,
221
+ root=root,
222
+ ignore_args=self._ignore_args,
223
+ ignore_kwargs=self._ignore_kwargs,
224
+ check_class_constructor=self.check_class_constructor,
181
225
  )
182
226
 
183
227
  if root.is_dir():
@@ -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.45.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.45.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.3.1"
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
File without changes