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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fluffless
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Simple, light Python framework for building CLI apps
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -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
- _BASE_PARSER = cli.create_subparser(command="grouped_parsers", has_subparsers=True)
6
- _PARSER = _BASE_PARSER.add_parser("awoo", parents=[cli.base_leaf_parser()])
5
+ PARSER = _BASE_PARSER.add_parser("awoo")
7
6
 
8
- @entrypoint(_PARSER)
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 base_leaf_parser() -> argparse.ArgumentParser:
86
- """ Bottom level parser base template with standardised behaviour.
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
- Intended to be added only as a parent on parsers tied to runner functions.
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(add_help=False, formatter_class=CustomRichHelpFormatter)
92
- parser.add_argument("-v", "--verbose", action="count", default=0, help="Increase verbosity of logger output.")
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 create_subparser(command: str, has_subparsers: bool = False, *args, **kwargs) -> argparse.ArgumentParser:
97
- """ Create and add subparser within the root parser.
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
- command (str): Command to invoke the subparser.
101
- has_subparsers (bool): True if the subparser will have nested subparsers, False otherwise. Defaults to False.
102
- *args: Additional positional arguments to pass to `add_parser()`.
103
- **kwargs: Additional keyword arguments to pass to `add_parser()`.
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: Subparser created from the arguments.
136
+ argparse.ArgumentParser: The created parser from the given arguments.
107
137
  """
108
- return ROOT_SUBPARSERS.add_parser(
109
- command,
110
- *args,
111
- **kwargs,
112
- formatter_class=RichHelpFormatter,
113
- # Only lowest level subparsers should inherit from the parser template.
114
- parents=[base_leaf_parser()] if not has_subparsers else [],
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[[RunnerFunction], RunnerFunction]:
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. """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fluffless
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Simple, light Python framework for building CLI apps
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -11,4 +11,5 @@ src/fluffless/models/base_model.py
11
11
  src/fluffless/utils/__init__.py
12
12
  src/fluffless/utils/cli.py
13
13
  src/fluffless/utils/console.py
14
- src/fluffless/utils/logging.py
14
+ src/fluffless/utils/logging.py
15
+ tests/test_placeholder.py
@@ -0,0 +1,5 @@
1
+ """ Placeholder tests. """
2
+
3
+
4
+ def test_placeholder() -> None:
5
+ """ Placeholder test. """
File without changes
File without changes