docsig 0.49.2__tar.gz → 0.50.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.49.2
3
+ Version: 0.50.0
4
4
  Summary: Check signature params for proper documentation
5
5
  Home-page: https://pypi.org/project/docsig/
6
6
  License: MIT
@@ -223,7 +223,7 @@ It can be added to your .pre-commit-config.yaml as follows:
223
223
 
224
224
  repos:
225
225
  - repo: https://github.com/jshwi/docsig
226
- rev: v0.49.2
226
+ rev: v0.50.0
227
227
  hooks:
228
228
  - id: docsig
229
229
  args:
@@ -195,7 +195,7 @@ It can be added to your .pre-commit-config.yaml as follows:
195
195
 
196
196
  repos:
197
197
  - repo: https://github.com/jshwi/docsig
198
- rev: v0.49.2
198
+ rev: v0.50.0
199
199
  hooks:
200
200
  - id: docsig
201
201
  args:
@@ -191,6 +191,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
191
191
  ignore_args=ignore_args,
192
192
  ignore_kwargs=ignore_kwargs,
193
193
  check_class_constructor=check_class_constructor,
194
+ no_ansi=no_ansi,
194
195
  verbose=verbose,
195
196
  )
196
197
  display = _Display(no_ansi)
@@ -225,4 +226,4 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
225
226
  else:
226
227
  display.report()
227
228
 
228
- return int(bool(display))
229
+ return max(int(bool(display)), modules.retcode)
@@ -0,0 +1,20 @@
1
+ """
2
+ docsig._hooks
3
+ =============
4
+ """
5
+
6
+ import sys as _sys
7
+ from os import environ as _e
8
+
9
+ from ._utils import pretty_print_error
10
+
11
+
12
+ def excepthook(no_ansi: bool = False) -> None:
13
+ """Print user friendly commandline error if debug not enabled.
14
+
15
+ :param no_ansi: Disable ANSI output.
16
+ """
17
+ if _e.get("DOCSIG_DEBUG", None) != "1":
18
+ _sys.excepthook = lambda x, y, _: pretty_print_error(
19
+ x, str(y), no_ansi
20
+ )
@@ -9,7 +9,7 @@ from __future__ import annotations as _
9
9
 
10
10
  from ._config import Parser as _Parser
11
11
  from ._core import docsig as _docsig
12
- from ._hooks import pretty_print_error as _pretty_print_error
12
+ from ._hooks import excepthook as _excepthook
13
13
 
14
14
 
15
15
  def main() -> str | int:
@@ -20,7 +20,7 @@ def main() -> str | int:
20
20
  :return: Exit status for whether test failed or not.
21
21
  """
22
22
  p = _Parser()
23
- _pretty_print_error(p.args.no_ansi)
23
+ _excepthook(p.args.no_ansi)
24
24
  return _docsig(
25
25
  *p.args.path,
26
26
  string=p.args.string,
@@ -10,6 +10,7 @@ import typing as _t
10
10
  from pathlib import Path as _Path
11
11
 
12
12
  import astroid as _ast
13
+ import click as _click
13
14
  from astroid import AstroidSyntaxError as _AstroidSyntaxError
14
15
 
15
16
  from ._directives import Directive as _Directive
@@ -17,6 +18,7 @@ from ._directives import Directives as _Directives
17
18
  from ._message import Message as _Message
18
19
  from ._stub import Docstring as _Docstring
19
20
  from ._stub import Signature as _Signature
21
+ from ._utils import pretty_print_error
20
22
  from ._utils import vprint as _vprint
21
23
 
22
24
  _FILE_INFO = "{path}: {msg}"
@@ -304,7 +306,7 @@ class Function(Parent):
304
306
  return self._directives
305
307
 
306
308
 
307
- class Modules(_t.List[Parent]):
309
+ class Modules(_t.List[Parent]): # pylint: disable=too-many-instance-attributes
308
310
  """Sequence of ``Module`` objects parsed from Python modules or str.
309
311
 
310
312
  Recursively collect Python files from within all dirs that exist
@@ -322,6 +324,7 @@ class Modules(_t.List[Parent]):
322
324
  :param check_class_constructor: Check the class constructor's
323
325
  docstring. Otherwise, expect the constructor's documentation to
324
326
  be on the class level docstring.
327
+ :param no_ansi: Disable ANSI output.
325
328
  :param verbose: increase output verbosity.
326
329
  """
327
330
 
@@ -352,22 +355,24 @@ class Modules(_t.List[Parent]):
352
355
  check_class_constructor,
353
356
  )
354
357
  )
358
+ _vprint(
359
+ _FILE_INFO.format(
360
+ path=root or "stdin", msg="Parsing Python code successful"
361
+ ),
362
+ self._verbose,
363
+ )
355
364
  except (_AstroidSyntaxError, UnicodeDecodeError) as err:
365
+ msg = str(err).replace("\n", " ")
356
366
  if root is not None and root.name.endswith(".py"):
357
- # keep raising errors for .py files as was done prior to
358
- # this change
359
367
  # pass by silently for files that do not end with .py,
360
- # which were not checked at all prior (these may result
361
- # in a 123 syntax error exit status in the future)
362
- # with this there should be no breaking change, and
363
- # files that are supposed to be python, files evident by
364
- # their suffix, will continue to fail
365
- raise err
368
+ # may result in a 123 syntax error exit status in the
369
+ # future
370
+ _click.echo(root)
371
+ pretty_print_error(type(err), msg, no_ansi=self._no_ansi)
372
+ self._retcode = 1
366
373
 
367
374
  _vprint(
368
- _FILE_INFO.format(
369
- path=root or "stdin", msg=str(err).replace("\n", " ")
370
- ),
375
+ _FILE_INFO.format(path=root or "stdin", msg=msg),
371
376
  self._verbose,
372
377
  )
373
378
 
@@ -380,6 +385,7 @@ class Modules(_t.List[Parent]):
380
385
  ignore_args: bool = False,
381
386
  ignore_kwargs: bool = False,
382
387
  check_class_constructor: bool = False,
388
+ no_ansi: bool = False,
383
389
  verbose: bool = False,
384
390
  ) -> None:
385
391
  super().__init__()
@@ -388,7 +394,9 @@ class Modules(_t.List[Parent]):
388
394
  self._ignore_args = ignore_args
389
395
  self._ignore_kwargs = ignore_kwargs
390
396
  self.check_class_constructor = check_class_constructor
397
+ self._no_ansi = no_ansi
391
398
  self._verbose = verbose
399
+ self._retcode = 0
392
400
  if string is not None:
393
401
  self._add_module(
394
402
  disable,
@@ -426,3 +434,8 @@ class Modules(_t.List[Parent]):
426
434
  if root.is_dir():
427
435
  for path in root.iterdir():
428
436
  self._populate(path)
437
+
438
+ @property
439
+ def retcode(self) -> int:
440
+ """Return code to propagate to main."""
441
+ return self._retcode
@@ -5,6 +5,8 @@ docsig._utils
5
5
 
6
6
  from __future__ import annotations as _
7
7
 
8
+ import sys as _sys
9
+ import typing as _t
8
10
  from difflib import SequenceMatcher as _SequenceMatcher
9
11
 
10
12
  import click as _click
@@ -31,3 +33,19 @@ def vprint(msg: str, verbose: bool = False) -> None:
31
33
  """
32
34
  if verbose:
33
35
  _click.echo(msg)
36
+
37
+
38
+ def pretty_print_error(
39
+ exception_type: _t.Type[BaseException], msg: str, no_ansi: bool
40
+ ) -> None:
41
+ """Print user-friendly exception.
42
+
43
+ :param exception_type: Type of the exception.
44
+ :param msg: The exception message.
45
+ :param no_ansi: Whether to in ANSI escape codes.
46
+ """
47
+ _click.echo(
48
+ f"{_click.style(exception_type.__name__, fg='red', bold=True)}: {msg}",
49
+ file=_sys.stderr,
50
+ color=not no_ansi and _sys.stderr.isatty(),
51
+ )
@@ -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.49.2"
11
+ __version__ = "0.50.0"
@@ -16,16 +16,6 @@ exclude = '''
16
16
  '''
17
17
  line-length = 79
18
18
 
19
- [tool.constcheck]
20
- ignore_strings = [
21
- "disable",
22
- "red",
23
- "store",
24
- "store_true",
25
- "targets",
26
- "utf-8"
27
- ]
28
-
29
19
  [tool.coverage.report]
30
20
  exclude_lines = [
31
21
  "@_t.overload"
@@ -73,7 +63,7 @@ maintainers = [
73
63
  name = "docsig"
74
64
  readme = "README.rst"
75
65
  repository = "https://github.com/jshwi/docsig"
76
- version = "0.49.2"
66
+ version = "0.50.0"
77
67
 
78
68
  [tool.poetry.dependencies]
79
69
  Pygments = "^2.13.0"
@@ -104,7 +94,6 @@ docsig = "docsig.__main__:main"
104
94
  audit = [
105
95
  "about-tests",
106
96
  "commit-policy",
107
- "const",
108
97
  "copyright-year",
109
98
  "docs",
110
99
  "files",
@@ -1,22 +0,0 @@
1
- """
2
- docsig._hooks
3
- =============
4
- """
5
-
6
- import sys as _sys
7
- from os import environ as _e
8
-
9
- import click as _click
10
-
11
-
12
- def pretty_print_error(no_ansi: bool = False) -> None:
13
- """Print user friendly commandline error if debug not enabled.
14
-
15
- :param no_ansi: Disable ANSI output.
16
- """
17
- if _e.get("DOCSIG_DEBUG", None) != "1":
18
- _sys.excepthook = lambda x, y, _: _click.echo(
19
- f"{_click.style(x.__name__, fg='red', bold=True)}: {y}",
20
- file=_sys.stderr,
21
- color=not no_ansi and _sys.stderr.isatty(),
22
- )
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