click-extended 0.2.1__tar.gz → 0.3.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.
- {click_extended-0.2.1/click_extended.egg-info → click_extended-0.3.0}/PKG-INFO +1 -1
- {click_extended-0.2.1 → click_extended-0.3.0}/click_extended/errors.py +78 -2
- {click_extended-0.2.1 → click_extended-0.3.0/click_extended.egg-info}/PKG-INFO +1 -1
- {click_extended-0.2.1 → click_extended-0.3.0}/pyproject.toml +2 -1
- {click_extended-0.2.1 → click_extended-0.3.0}/AUTHORS.md +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/LICENSE +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/README.md +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/click_extended/__init__.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/click_extended/types.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/click_extended.egg-info/SOURCES.txt +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/click_extended.egg-info/dependency_links.txt +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/click_extended.egg-info/requires.txt +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/click_extended.egg-info/top_level.txt +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/setup.cfg +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_argument.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_child_node.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_command.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_env.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_global_node.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_group.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_option.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_parent_node.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_root_node.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_tag.py +0 -0
- {click_extended-0.2.1 → click_extended-0.3.0}/tests/test_tree.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: click_extended
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: An extension to Click with additional features like automatic async support, aliasing and a modular decorator system.
|
|
5
5
|
Author-email: Marcus Fredriksson <marcus@marcusfredriksson.com>
|
|
6
6
|
License: MIT License
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
# pylint: disable=too-many-arguments
|
|
4
4
|
# pylint: disable=too-many-positional-arguments
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import inspect
|
|
7
|
+
from typing import IO, Any
|
|
7
8
|
|
|
8
9
|
import click
|
|
9
10
|
from click import ClickException
|
|
@@ -17,6 +18,7 @@ class ClickExtendedError(Exception):
|
|
|
17
18
|
"""Base exception for exceptions defined in the `click_extended` library."""
|
|
18
19
|
|
|
19
20
|
|
|
21
|
+
# Catchable errors
|
|
20
22
|
class CatchableError(ClickExtendedError):
|
|
21
23
|
"""Base exception for exceptions raised inside a child node.
|
|
22
24
|
|
|
@@ -34,6 +36,72 @@ class CatchableError(ClickExtendedError):
|
|
|
34
36
|
super().__init__(message)
|
|
35
37
|
|
|
36
38
|
|
|
39
|
+
class ChildNodeProcessError(CatchableError):
|
|
40
|
+
"""
|
|
41
|
+
Base class for exceptions which must be raised inside
|
|
42
|
+
the `process()` method of a `ChildNode`.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, message: str, **kwargs: str) -> None:
|
|
46
|
+
"""
|
|
47
|
+
Initialize a new `ChildNodeProcessError` instance.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
message (str):
|
|
51
|
+
The error message. If child_name is found, it will be
|
|
52
|
+
prefixed automatically. Subclasses can access child_name
|
|
53
|
+
via self.child_name to format custom messages.
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
RuntimeError:
|
|
57
|
+
If raised outside a ChildNode context.
|
|
58
|
+
"""
|
|
59
|
+
self.child_name: str | None = None
|
|
60
|
+
frame = inspect.currentframe()
|
|
61
|
+
|
|
62
|
+
if frame:
|
|
63
|
+
current_frame = frame.f_back
|
|
64
|
+
depth = 0
|
|
65
|
+
max_depth = 10
|
|
66
|
+
|
|
67
|
+
while current_frame and depth < max_depth:
|
|
68
|
+
caller_locals = current_frame.f_locals
|
|
69
|
+
if "self" in caller_locals:
|
|
70
|
+
self_obj = caller_locals["self"]
|
|
71
|
+
if hasattr(self_obj, "name") and hasattr(
|
|
72
|
+
self_obj, "process"
|
|
73
|
+
):
|
|
74
|
+
self.child_name = self_obj.name
|
|
75
|
+
break
|
|
76
|
+
current_frame = current_frame.f_back
|
|
77
|
+
depth += 1
|
|
78
|
+
|
|
79
|
+
if not self.child_name:
|
|
80
|
+
raise RuntimeError(
|
|
81
|
+
f"{self.__class__.__name__} must be raised from within a "
|
|
82
|
+
f"ChildNode.process() method. The exception was raised outside "
|
|
83
|
+
f"a valid ChildNode context."
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
formatted_message = message.format(name=self.child_name, **kwargs)
|
|
87
|
+
super().__init__(formatted_message)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class UnhandledValueError(ChildNodeProcessError):
|
|
91
|
+
"""Exception raised when a value in the `process()` method is unexpected."""
|
|
92
|
+
|
|
93
|
+
def __init__(self, value: Any) -> None:
|
|
94
|
+
"""
|
|
95
|
+
Initialize a new `UnhandledValueError` instance.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
value (Any):
|
|
99
|
+
The unexpected value.
|
|
100
|
+
"""
|
|
101
|
+
message = "Received unexpected value for '{name}' of type '{type}'"
|
|
102
|
+
super().__init__(message, type=type(value).__name__)
|
|
103
|
+
|
|
104
|
+
|
|
37
105
|
class ValidationError(CatchableError):
|
|
38
106
|
"""Exception raised when validation fails in a child node."""
|
|
39
107
|
|
|
@@ -42,6 +110,13 @@ class TransformError(CatchableError):
|
|
|
42
110
|
"""Exception raised when transformation fails in a child node."""
|
|
43
111
|
|
|
44
112
|
|
|
113
|
+
class UnknownError(ChildNodeProcessError):
|
|
114
|
+
"""
|
|
115
|
+
Exception raised when an unexpected error occurs or parts of code
|
|
116
|
+
which is unhandled.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
|
|
45
120
|
class ParameterError(ClickException):
|
|
46
121
|
"""Exception raised when parameter validation or transformation fails.
|
|
47
122
|
|
|
@@ -78,7 +153,7 @@ class ParameterError(ClickException):
|
|
|
78
153
|
return f"({self.param_hint}): {self.message}"
|
|
79
154
|
return self.message
|
|
80
155
|
|
|
81
|
-
def show(self, file:
|
|
156
|
+
def show(self, file: IO[Any] | None = None) -> None:
|
|
82
157
|
"""Display the error with usage information (like Click does)."""
|
|
83
158
|
if file is None:
|
|
84
159
|
file = get_text_stderr()
|
|
@@ -102,6 +177,7 @@ class ParameterError(ClickException):
|
|
|
102
177
|
echo(f"Error {self.format_message()}", file=file, color=color)
|
|
103
178
|
|
|
104
179
|
|
|
180
|
+
# Node errors
|
|
105
181
|
class NoParentError(ClickExtendedError):
|
|
106
182
|
"""Exception raised when no `ParentNode` has been defined."""
|
|
107
183
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: click_extended
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: An extension to Click with additional features like automatic async support, aliasing and a modular decorator system.
|
|
5
5
|
Author-email: Marcus Fredriksson <marcus@marcusfredriksson.com>
|
|
6
6
|
License: MIT License
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "click_extended"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "An extension to Click with additional features like automatic async support, aliasing and a modular decorator system."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Marcus Fredriksson", email = "marcus@marcusfredriksson.com" },
|
|
@@ -61,6 +61,7 @@ packages = ["click_extended"]
|
|
|
61
61
|
|
|
62
62
|
[tool.pyright]
|
|
63
63
|
reportUnnecessaryIsInstance = "none"
|
|
64
|
+
typeCheckingMode = "strict"
|
|
64
65
|
|
|
65
66
|
[tool.pylint.master]
|
|
66
67
|
ignore = [
|
|
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
|
|
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
|