fluffless 0.0.1__tar.gz → 0.0.2__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.
- {fluffless-0.0.1/src/fluffless.egg-info → fluffless-0.0.2}/PKG-INFO +1 -1
- {fluffless-0.0.1 → fluffless-0.0.2}/pyproject.toml +2 -1
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless/utils/cli.py +57 -26
- {fluffless-0.0.1 → fluffless-0.0.2/src/fluffless.egg-info}/PKG-INFO +1 -1
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless.egg-info/SOURCES.txt +2 -1
- fluffless-0.0.2/tests/test_placeholder.py +5 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/LICENSE +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/setup.cfg +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless/models/__init__.py +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless/models/base_model.py +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless/utils/__init__.py +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless/utils/console.py +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless/utils/logging.py +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless.egg-info/dependency_links.txt +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless.egg-info/entry_points.txt +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless.egg-info/requires.txt +0 -0
- {fluffless-0.0.1 → fluffless-0.0.2}/src/fluffless.egg-info/top_level.txt +0 -0
|
@@ -37,8 +37,9 @@ fluffless = "fluffless.main:main"
|
|
|
37
37
|
requires = ["setuptools>=80.9.0", "versioningit>=3.3.0"]
|
|
38
38
|
build-backend = "setuptools.build_meta"
|
|
39
39
|
|
|
40
|
-
[tool.versioningit]
|
|
40
|
+
[tool.versioningit.vcs]
|
|
41
41
|
method = "git"
|
|
42
|
+
default-tag = "0.0.0"
|
|
42
43
|
|
|
43
44
|
[tool.setuptools.packages.find]
|
|
44
45
|
where = ["src"]
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Example usage of CLI entrypoints:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
_PARSER = _BASE_PARSER.add_parser("awoo", parents=[cli.base_leaf_parser()])
|
|
5
|
+
PARSER = _BASE_PARSER.add_parser("awoo")
|
|
7
6
|
|
|
8
|
-
@entrypoint(
|
|
7
|
+
@entrypoint(PARSER)
|
|
9
8
|
def awoo() -> None:
|
|
10
9
|
print("Awoo!")
|
|
11
10
|
|
|
@@ -15,7 +14,7 @@ import argparse
|
|
|
15
14
|
import importlib
|
|
16
15
|
import pkgutil
|
|
17
16
|
from types import ModuleType
|
|
18
|
-
from typing import Callable
|
|
17
|
+
from typing import Any, Callable
|
|
19
18
|
|
|
20
19
|
from rich_argparse import _lazy_rich, RichHelpFormatter
|
|
21
20
|
|
|
@@ -82,37 +81,69 @@ ROOT_SUBPARSERS = ROOT_PARSER.add_subparsers(required=True)
|
|
|
82
81
|
ROOT_PARSER.set_defaults(_entry_func=None) # Defaults to None, until overridden by the chosen runner function.
|
|
83
82
|
|
|
84
83
|
|
|
85
|
-
def
|
|
86
|
-
|
|
84
|
+
def base_parser(
|
|
85
|
+
is_leaf: bool, formatter_class: type[argparse.HelpFormatter] = CustomRichHelpFormatter,
|
|
86
|
+
) -> argparse.ArgumentParser:
|
|
87
|
+
""" Baseline parser to provide standard arguments to all parsers using it as a parent.
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
For non-leaf parsers, only the `--help` action is added, as they are not intended to be invoked directly.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
is_leaf (bool): If the parser should be invoked directly or not, and thus have the appropriate arguments added.
|
|
93
|
+
formatter_class (type[argparse.HelpFormatter], optional): Formatter class to use for help blocks. \
|
|
94
|
+
Defaults to `CustomRichHelpFormatter`.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
argparse.ArgumentParser: Argument parser to be used as a parent, providing standardised arguments.
|
|
89
98
|
"""
|
|
90
|
-
# Do not add default help, defer to the runner to define it.
|
|
91
|
-
parser = argparse.ArgumentParser(
|
|
92
|
-
parser.add_argument(
|
|
99
|
+
# Do not add a default help string, defer to the specific runner to define it.
|
|
100
|
+
parser = argparse.ArgumentParser(formatter_class=formatter_class, add_help=False)
|
|
101
|
+
parser.add_argument(
|
|
102
|
+
"-h", "--help", action="help", default=argparse.SUPPRESS, help="Show this help message and exit.",
|
|
103
|
+
)
|
|
104
|
+
if is_leaf:
|
|
105
|
+
parser.add_argument("-v", "--verbose", action="count", default=0, help="Increase verbosity of logger output.")
|
|
106
|
+
|
|
93
107
|
return parser
|
|
94
108
|
|
|
95
109
|
|
|
96
|
-
def
|
|
97
|
-
|
|
110
|
+
def add_parser(
|
|
111
|
+
name: str,
|
|
112
|
+
subparsers: argparse._SubParsersAction | None = None,
|
|
113
|
+
parents: list[argparse.ArgumentParser] | None = None,
|
|
114
|
+
is_leaf: bool = True,
|
|
115
|
+
formatter_class: type[argparse.HelpFormatter] = CustomRichHelpFormatter,
|
|
116
|
+
**kwargs,
|
|
117
|
+
) -> argparse.ArgumentParser:
|
|
118
|
+
""" Create a parser under a given subparsers group, or the root subparsers group if one is not provided.
|
|
119
|
+
|
|
120
|
+
If a description was not provided for the subparser, uses the help string as a description.
|
|
98
121
|
|
|
99
122
|
Args:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
123
|
+
name (str): The name of the command to use when invoking the parser.
|
|
124
|
+
subparsers (argparse._SubParsersAction | None, optional): Subparsers group to add the new parser to. \
|
|
125
|
+
Defaults to None, where the root subparser \
|
|
126
|
+
group will be used by default.
|
|
127
|
+
parents (list[argparse.ArgumentParser] | None, optional): List of parent parsers to inherit from. \
|
|
128
|
+
Defaults to None, where `base_parser` will be used.
|
|
129
|
+
is_leaf (bool): If the parser should be invoked directly or not, and thus have the appropriate arguments added.
|
|
130
|
+
formatter_class (type[argparse.HelpFormatter], optional): Formatter class to use for help blocks. \
|
|
131
|
+
Defaults to `CustomRichHelpFormatter`.
|
|
132
|
+
**kwargs: Additional keyword arguments to pass to `subparser.add_parser()`.
|
|
133
|
+
|
|
104
134
|
|
|
105
135
|
Returns:
|
|
106
|
-
argparse.ArgumentParser:
|
|
136
|
+
argparse.ArgumentParser: The created parser from the given arguments.
|
|
107
137
|
"""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
138
|
+
add_parser_kwargs: dict[str, Any] = {
|
|
139
|
+
"name": name,
|
|
140
|
+
"parents": parents or [base_parser(is_leaf, formatter_class)],
|
|
141
|
+
"formatter_class": formatter_class,
|
|
142
|
+
"description": kwargs.get("description") or kwargs.get("help"),
|
|
143
|
+
"add_help": False,
|
|
144
|
+
}
|
|
145
|
+
add_parser_kwargs.update(kwargs)
|
|
146
|
+
return (subparsers or ROOT_SUBPARSERS).add_parser(**add_parser_kwargs) # type: ignore[invalid-argument-type]
|
|
116
147
|
|
|
117
148
|
|
|
118
149
|
def parse_args(*args, **kwargs) -> argparse.Namespace:
|
|
@@ -128,7 +159,7 @@ def run(args: argparse.Namespace, config: BaseModel) -> None:
|
|
|
128
159
|
ROOT_PARSER.print_help()
|
|
129
160
|
|
|
130
161
|
|
|
131
|
-
def entrypoint(parser: argparse.ArgumentParser) -> Callable
|
|
162
|
+
def entrypoint(parser: argparse.ArgumentParser) -> Callable:
|
|
132
163
|
""" Decorate a function as the main runner function for a given parser. """
|
|
133
164
|
def entrypoint_decorator(runner_function: RunnerFunction) -> RunnerFunction:
|
|
134
165
|
""" Set default entry function for the parser. """
|
|
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
|