docsig 0.42.1__tar.gz → 0.44.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.42.1
3
+ Version: 0.44.0
4
4
  Summary: Check signature params for proper documentation
5
5
  Home-page: https://pypi.org/project/docsig/
6
6
  License: MIT
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.9
17
17
  Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
19
  Requires-Dist: Pygments (>=2.13.0,<3.0.0)
20
- Requires-Dist: Sphinx (>=4.3.2,<7.0.0)
20
+ Requires-Dist: Sphinx (>=7.0.0,<8.0.0)
21
21
  Requires-Dist: arcon (>=0.3.1,<0.4.0)
22
22
  Requires-Dist: astroid (>=3.0.1,<4.0.0)
23
23
  Requires-Dist: object-colors (>=2.1.0,<3.0.0)
@@ -105,9 +105,9 @@ Commandline
105
105
 
106
106
  .. code-block:: console
107
107
 
108
- usage: docsig [-h] [-v] [-c | -C] [-D] [-m] [-o] [-p] [-P] [-i] [-a] [-k] [-n]
109
- [-S] [-s STR] [-d LIST] [-t LIST]
110
- path [path ...]
108
+ usage: docsig [-h] [-v] [-l] [-c | -C] [-D] [-m] [-o] [-p] [-P] [-i] [-a] [-k]
109
+ [-n] [-S] [-s STR] [-d LIST] [-t LIST]
110
+ [path [path ...]]
111
111
 
112
112
  Check signature params for proper documentation
113
113
 
@@ -117,6 +117,7 @@ Commandline
117
117
  optional arguments:
118
118
  -h, --help show this help message and exit
119
119
  -v, --version show program's version number and exit
120
+ -l, --list-checks display a list of all checks and their messages
120
121
  -c, --check-class check class docstrings
121
122
  -C, --check-class-constructor check __init__ methods. Note: mutually
122
123
  incompatible with -c
@@ -539,7 +540,7 @@ It can be added to your .pre-commit-config.yaml as follows:
539
540
 
540
541
  repos:
541
542
  - repo: https://github.com/jshwi/docsig
542
- rev: v0.42.1
543
+ rev: v0.44.0
543
544
  hooks:
544
545
  - id: docsig
545
546
  args:
@@ -77,9 +77,9 @@ Commandline
77
77
 
78
78
  .. code-block:: console
79
79
 
80
- usage: docsig [-h] [-v] [-c | -C] [-D] [-m] [-o] [-p] [-P] [-i] [-a] [-k] [-n]
81
- [-S] [-s STR] [-d LIST] [-t LIST]
82
- path [path ...]
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]
82
+ [path [path ...]]
83
83
 
84
84
  Check signature params for proper documentation
85
85
 
@@ -89,6 +89,7 @@ Commandline
89
89
  optional arguments:
90
90
  -h, --help show this help message and exit
91
91
  -v, --version show program's version number and exit
92
+ -l, --list-checks display a list of all checks and their messages
92
93
  -c, --check-class check class docstrings
93
94
  -C, --check-class-constructor check __init__ methods. Note: mutually
94
95
  incompatible with -c
@@ -511,7 +512,7 @@ It can be added to your .pre-commit-config.yaml as follows:
511
512
 
512
513
  repos:
513
514
  - repo: https://github.com/jshwi/docsig
514
- rev: v0.42.1
515
+ rev: v0.44.0
515
516
  hooks:
516
517
  - id: docsig
517
518
  args:
@@ -29,11 +29,17 @@ class Parser(_ArgumentParser):
29
29
  def _add_arguments(self) -> None:
30
30
  self.add_argument(
31
31
  "path",
32
- nargs="+",
32
+ nargs="*",
33
33
  action="store",
34
34
  type=_Path,
35
35
  help="directories or files to check",
36
36
  )
37
+ self.add_argument(
38
+ "-l",
39
+ "--list-checks",
40
+ action="store_true",
41
+ help="display a list of all checks and their messages",
42
+ )
37
43
  group = self.add_mutually_exclusive_group(required=False)
38
44
  group.add_argument(
39
45
  "-c",
@@ -4,28 +4,24 @@ docsig._core
4
4
  """
5
5
  from __future__ import annotations as _
6
6
 
7
- import sys as _sys
8
- from os import environ as _e
9
7
  from pathlib import Path as _Path
10
8
 
9
+ from . import _decorators
11
10
  from ._display import Display as _Display
12
11
  from ._display import Failure as _Failure
13
12
  from ._display import Failures as _Failures
14
13
  from ._display import FuncStr as _FuncStr
15
- from ._display import color as _color
16
14
  from ._message import Message as _Message
17
15
  from ._module import Modules as _Modules
18
16
  from ._module import Parent as _Parent
19
17
  from ._report import generate_report as _generate_report
18
+ from .messages import TEMPLATE as _TEMPLATE
20
19
  from .messages import E as _E
21
20
 
22
21
 
23
- def pretty_print_error() -> None:
24
- """Print user friendly commandline error if debug not enabled."""
25
- if _e.get("DOCSIG_DEBUG", None) != "1":
26
- _sys.excepthook = lambda x, y, _: print(
27
- f"{_color.red.bold.get(x.__name__)}: {y}"
28
- )
22
+ def _print_checks() -> None:
23
+ for msg in _E.values():
24
+ print(msg.fstring(_TEMPLATE))
29
25
 
30
26
 
31
27
  def _run_check( # pylint: disable=too-many-arguments
@@ -65,9 +61,12 @@ def _run_check( # pylint: disable=too-many-arguments
65
61
  return failures
66
62
 
67
63
 
64
+ @_decorators.parse_msgs
65
+ @_decorators.validate_args
68
66
  def docsig( # pylint: disable=too-many-locals,too-many-arguments
69
- *path: _Path,
67
+ *path: str | _Path,
70
68
  string: str | None = None,
69
+ list_checks: bool = False,
71
70
  check_class: bool = False,
72
71
  check_class_constructor: bool = False,
73
72
  check_dunders: bool = False,
@@ -80,8 +79,8 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
80
79
  ignore_kwargs: bool = False,
81
80
  no_ansi: bool = False,
82
81
  summary: bool = False,
83
- targets: list[str] | None = None,
84
- disable: list[str] | None = None,
82
+ targets: list[_Message] | None = None,
83
+ disable: list[_Message] | None = None,
85
84
  ) -> int:
86
85
  """Package's core functionality.
87
86
 
@@ -94,6 +93,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
94
93
 
95
94
  :param path: Path(s) to check.
96
95
  :param string: String to check.
96
+ :param list_checks: Display a list of all checks and their messages.
97
97
  :param check_class: Check class docstrings.
98
98
  :param check_class_constructor: Check ``__init__`` methods. Note that this
99
99
  is mutually incompatible with check_class.
@@ -113,23 +113,12 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
113
113
  :param disable: List of errors to disable.
114
114
  :return: Exit status for whether test failed or not.
115
115
  """
116
- disabled_args = list(_E.fromcodes(disable or []))
117
- target_args = list(_E.fromcodes(targets or []))
118
- for message in disabled_args:
119
- if not message.isknown:
120
- raise ValueError(
121
- f"unknown option to disable '{message.description}'",
122
- )
123
-
124
- for message in target_args:
125
- if not message.isknown:
126
- raise ValueError(
127
- f"unknown option to target '{message.description}'",
128
- )
116
+ if list_checks:
117
+ return int(bool(_print_checks())) # type: ignore
129
118
 
130
119
  modules = _Modules(
131
- *path,
132
- disable=disabled_args,
120
+ *tuple(_Path(i) for i in path),
121
+ disable=disable or [],
133
122
  string=string,
134
123
  ignore_args=ignore_args,
135
124
  ignore_kwargs=ignore_kwargs,
@@ -153,7 +142,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
153
142
  check_property_returns,
154
143
  ignore_no_params,
155
144
  no_ansi,
156
- target_args,
145
+ targets or [],
157
146
  )
158
147
  if failures:
159
148
  display[top_level.path].append(failures)
@@ -0,0 +1,81 @@
1
+ """
2
+ docsig._decorators
3
+ ==================
4
+ """
5
+ from __future__ import annotations as _
6
+
7
+ import sys as _sys
8
+ import typing as _t
9
+ from pathlib import Path as _Path
10
+
11
+ from .messages import E as _E
12
+
13
+ _FuncType = _t.Callable[..., _t.Union[int]]
14
+ _WrappedFuncType = _t.Callable[..., _t.Union[str, int]]
15
+
16
+
17
+ def parse_msgs(func: _WrappedFuncType) -> _WrappedFuncType:
18
+ """Parse error codes or symbolic messages into message objects.
19
+
20
+ :param func: Function to wrap.
21
+ :return: Wrapped function.
22
+ """
23
+
24
+ def _wrapper(*args: str | _Path, **kwargs: _t.Any) -> str | int:
25
+ disable = list(_E.fromcodes(kwargs.get("disable", []))) or None
26
+ targets = list(_E.fromcodes(kwargs.get("targets", []))) or None
27
+ kwargs["disable"] = disable
28
+ kwargs["targets"] = targets
29
+ return func(*args, **kwargs)
30
+
31
+ return _wrapper
32
+
33
+
34
+ def validate_args(func: _FuncType) -> _WrappedFuncType:
35
+ """Confirm args passed to function are valid.
36
+
37
+ :param func: Function to wrap.
38
+ :return: Wrapped function.
39
+ """
40
+
41
+ def _wrapper(*args: str | _Path, **kwargs: _t.Any) -> str | int:
42
+ stderr = []
43
+ if not kwargs.get("list_checks", False):
44
+ if not args and not kwargs.get("string"):
45
+ stderr.append(
46
+ "the following arguments are required: path(s) or string"
47
+ )
48
+
49
+ for message in kwargs.get("disable") or []:
50
+ if not message.isknown:
51
+ stderr.append(
52
+ f"unknown option to disable '{message.description}'"
53
+ )
54
+
55
+ for message in kwargs.get("targets") or []:
56
+ if not message.isknown:
57
+ stderr.append(
58
+ f"unknown option to target '{message.description}'",
59
+ )
60
+
61
+ if kwargs.get("check_class") and kwargs.get(
62
+ "check_class_constructor"
63
+ ):
64
+ stderr.append(
65
+ "argument to check class constructor not allowed with"
66
+ " argument to check class"
67
+ )
68
+ # if we don't make it past this condition then we are
69
+ # running this using the python interpreter
70
+ if _sys.stdin and _sys.stdin.isatty():
71
+ # otherwise, it is impossible to reach here by
72
+ # passing both commandline args as argparse won't
73
+ # allow it, therefore, this must be an issue with
74
+ # the pyproject.toml configuration
75
+ stderr.append(
76
+ "please check your pyproject.toml configuration"
77
+ )
78
+
79
+ return "\n".join(stderr) if stderr else func(*args, **kwargs)
80
+
81
+ return _wrapper
@@ -0,0 +1,16 @@
1
+ """
2
+ docsig._hooks
3
+ =============
4
+ """
5
+ import sys as _sys
6
+ from os import environ as _e
7
+
8
+ from ._display import color as _color
9
+
10
+
11
+ def pretty_print_error() -> None:
12
+ """Print user friendly commandline error if debug not enabled."""
13
+ if _e.get("DOCSIG_DEBUG", None) != "1":
14
+ _sys.excepthook = lambda x, y, _: print(
15
+ f"{_color.red.bold.get(x.__name__)}: {y}"
16
+ )
@@ -4,12 +4,14 @@ docsig._main
4
4
 
5
5
  Contains package entry point.
6
6
  """
7
+ from __future__ import annotations as _
8
+
7
9
  from ._config import Parser as _Parser
8
10
  from ._core import docsig as _docsig
9
- from ._core import pretty_print_error as _pretty_print_error
11
+ from ._hooks import pretty_print_error as _pretty_print_error
10
12
 
11
13
 
12
- def main() -> int:
14
+ def main() -> str | int:
13
15
  """Main function for package.
14
16
 
15
17
  Collect config and arguments for the commandline.
@@ -21,6 +23,7 @@ def main() -> int:
21
23
  return _docsig(
22
24
  *parser.args.path,
23
25
  string=parser.args.string,
26
+ list_checks=parser.args.list_checks,
24
27
  check_class=parser.args.check_class,
25
28
  check_class_constructor=parser.args.check_class_constructor,
26
29
  check_dunders=parser.args.check_dunders,
@@ -36,5 +39,5 @@ def main() -> int:
36
39
  no_ansi=parser.args.no_ansi,
37
40
  summary=parser.args.summary,
38
41
  targets=parser.args.target,
39
- disable=parser.args.disable
42
+ disable=parser.args.disable,
40
43
  )
@@ -7,4 +7,4 @@ Contains the version of this package.
7
7
  Allows for access to the version internally without cyclic imports
8
8
  caused by accessing it through __init__.
9
9
  """
10
- __version__ = "0.42.1"
10
+ __version__ = "0.44.0"
@@ -134,7 +134,7 @@ E = _Messages(
134
134
  204: _Message(
135
135
  "E204",
136
136
  "unknown inline comment option for {directive} '{option}'",
137
- "unknown-module-directive-option",
137
+ "unknown-inline-directive-option",
138
138
  ),
139
139
  }
140
140
  )
@@ -18,8 +18,10 @@ line-length = 79
18
18
 
19
19
  [tool.constcheck]
20
20
  ignore_strings = [
21
+ "disable",
21
22
  "store",
22
23
  "store_true",
24
+ "targets",
23
25
  "utf-8"
24
26
  ]
25
27
 
@@ -70,11 +72,11 @@ maintainers = [
70
72
  name = "docsig"
71
73
  readme = "README.rst"
72
74
  repository = "https://github.com/jshwi/docsig"
73
- version = "0.42.1"
75
+ version = "0.44.0"
74
76
 
75
77
  [tool.poetry.dependencies]
76
78
  Pygments = "^2.13.0"
77
- Sphinx = ">=4.3.2,<7.0.0"
79
+ Sphinx = "^7.0.0"
78
80
  arcon = "^0.3.1"
79
81
  astroid = "^3.0.1"
80
82
  object-colors = "^2.1.0"
@@ -86,7 +88,7 @@ bump2version = "^1.0.1"
86
88
  deptry = "^0.12.0"
87
89
  ipython = "^8.12.0"
88
90
  pre-commit = "^3.3.3"
89
- pyaud = "^7.2.0"
91
+ pyaud = "^7.3.0"
90
92
  pytest = "^7.4.0"
91
93
  pytest-randomly = "^3.13.0"
92
94
  pytest-sugar = "^0.9.6"
@@ -111,7 +113,6 @@ audit = [
111
113
  "format-str",
112
114
  "imports",
113
115
  "lint",
114
- "params",
115
116
  "test",
116
117
  "typecheck",
117
118
  "unused"
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