rn-forge-cli 0.2.0__tar.gz → 0.2.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: rn-forge-cli
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: The shared command-line layer for rn-forge applications: Typer app factory, standard options, console and exit codes
5
5
  Author: Rohit Narayanan
6
6
  Author-email: Rohit Narayanan <rohit.nn@gmail.com>
@@ -15,8 +15,8 @@ Classifier: Programming Language :: Python :: 3.14
15
15
  Classifier: Typing :: Typed
16
16
  Requires-Dist: rn-forge-commons>=0.8.0,<0.11
17
17
  Requires-Dist: rich>=15.0.0
18
- Requires-Dist: typer>=0.26.8
19
- Requires-Dist: assertpy>=2.35 ; extra == 'testing'
18
+ Requires-Dist: typer>=0.29.1
19
+ Requires-Dist: assertpy>=2.36.0 ; extra == 'testing'
20
20
  Requires-Dist: pytest>=9.1.1 ; extra == 'testing'
21
21
  Requires-Python: >=3.14
22
22
  Project-URL: Documentation, https://rn-forge.github.io/pykit/packages/rn-forge-cli/latest/
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rn-forge-cli"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "The shared command-line layer for rn-forge applications: Typer app factory, standard options, console and exit codes"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -18,7 +18,7 @@ requires-python = ">=3.14"
18
18
  dependencies = [
19
19
  "rn-forge-commons>=0.8.0,<0.11",
20
20
  "rich>=15.0.0",
21
- "typer>=0.26.8",
21
+ "typer>=0.29.1",
22
22
  ]
23
23
 
24
24
  [[project.authors]]
@@ -27,7 +27,7 @@ email = "rohit.nn@gmail.com"
27
27
 
28
28
  [project.optional-dependencies]
29
29
  testing = [
30
- "assertpy>=2.35",
30
+ "assertpy>=2.36.0",
31
31
  "pytest>=9.1.1",
32
32
  ]
33
33
 
@@ -64,17 +64,17 @@ markers = ["scaffold: installs built wheels into a scaffolded application (slow)
64
64
 
65
65
  [dependency-groups]
66
66
  dev = [
67
- "assertpy>=2.35",
67
+ "assertpy>=2.36.0",
68
68
  "pyright>=1.1.411",
69
- "pytest>=9.1.1",
69
+ "pytest>=9.2.0",
70
70
  "pytest-cov>=7.1.0",
71
71
  "pytest-randomly>=4.1.0",
72
72
  "rn-forge-cli",
73
- "ruff>=0.15.21",
73
+ "ruff>=0.17.4",
74
74
  ]
75
75
  docs = [
76
76
  "mkdocs>=1.6.1",
77
- "mkdocs-material>=9.7.6",
78
- "mkdocstrings[python]>=1.0.6",
77
+ "mkdocs-material>=9.8.1",
78
+ "mkdocstrings[python]>=1.0.8",
79
79
  "rn-forge-cli",
80
80
  ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rn-forge-cli"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "The shared command-line layer for rn-forge applications: Typer app factory, standard options, console and exit codes"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Rohit Narayanan", email = "rohit.nn@gmail.com" }]
@@ -20,11 +20,11 @@ requires-python = ">=3.14"
20
20
  dependencies = [
21
21
  "rn-forge-commons>=0.8.0,<0.11",
22
22
  "rich>=15.0.0",
23
- "typer>=0.26.8",
23
+ "typer>=0.29.1",
24
24
  ]
25
25
 
26
26
  [project.optional-dependencies]
27
- testing = ["assertpy>=2.35", "pytest>=9.1.1"]
27
+ testing = ["assertpy>=2.36.0", "pytest>=9.1.1"]
28
28
 
29
29
  [project.urls]
30
30
  Documentation = "https://rn-forge.github.io/pykit/packages/rn-forge-cli/latest/"
@@ -59,17 +59,17 @@ markers = [
59
59
 
60
60
  [dependency-groups]
61
61
  dev = [
62
- "assertpy>=2.35",
62
+ "assertpy>=2.36.0",
63
63
  "pyright>=1.1.411",
64
- "pytest>=9.1.1",
64
+ "pytest>=9.2.0",
65
65
  "pytest-cov>=7.1.0",
66
66
  "pytest-randomly>=4.1.0",
67
67
  "rn-forge-cli",
68
- "ruff>=0.15.21",
68
+ "ruff>=0.17.4",
69
69
  ]
70
70
  docs = [
71
71
  "mkdocs>=1.6.1",
72
- "mkdocs-material>=9.7.6",
73
- "mkdocstrings[python]>=1.0.6",
72
+ "mkdocs-material>=9.8.1",
73
+ "mkdocstrings[python]>=1.0.8",
74
74
  "rn-forge-cli",
75
75
  ]
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import importlib.metadata
5
6
  import inspect
6
7
  import re
7
8
  from collections.abc import Mapping, Sequence
@@ -176,6 +177,7 @@ class CliApp(typer.Typer):
176
177
  help: str | None = None,
177
178
  *,
178
179
  default_log_level: LogLevel = LogLevel.VERBOSE,
180
+ version: str | None = None,
179
181
  **typer_kwargs: Any,
180
182
  ) -> None:
181
183
  """Initialize the application and register its root callback.
@@ -188,6 +190,8 @@ class CliApp(typer.Typer):
188
190
  ``_``) as the root logger name.
189
191
  help: The app's ``--help`` description.
190
192
  default_log_level: Default value for ``--log-level``.
193
+ version: The version ``--version`` prints as ``<name> <version>``.
194
+ Without one the app has no ``--version`` option.
191
195
  **typer_kwargs: Forwarded to the :class:`typer.Typer` constructor.
192
196
  """
193
197
  typer_kwargs.setdefault("no_args_is_help", True)
@@ -195,7 +199,6 @@ class CliApp(typer.Typer):
195
199
  super().__init__(name=name, help=help, **typer_kwargs)
196
200
  self._logger_name = name.replace(" ", "_").lower()
197
201
 
198
- @self.callback()
199
202
  def _root(
200
203
  ctx: typer.Context,
201
204
  log_level: LogLevelOption = default_log_level,
@@ -219,6 +222,35 @@ class CliApp(typer.Typer):
219
222
  force_reconfigure=explicit,
220
223
  )
221
224
 
225
+ if version is None:
226
+ self.callback()(_root)
227
+ return
228
+
229
+ def _show_version(requested: bool) -> None:
230
+ if requested:
231
+ typer.echo(f"{name} {version}")
232
+ raise typer.Exit(ExitCode.OK)
233
+
234
+ # A default-value Option, not Annotated: with postponed annotations the
235
+ # local `_show_version` would not resolve. Eager, so it runs before the
236
+ # command is resolved and before `_root`.
237
+ @self.callback()
238
+ def _root_with_version(
239
+ ctx: typer.Context,
240
+ log_level: LogLevelOption = default_log_level,
241
+ log_file: LogFileOption = None,
242
+ quiet: QuietOption = False,
243
+ json_output: JsonOption = False,
244
+ show_version: bool = typer.Option(
245
+ False,
246
+ "--version",
247
+ callback=_show_version,
248
+ is_eager=True,
249
+ help="Show the version and exit.",
250
+ ),
251
+ ) -> None:
252
+ _root(ctx, log_level, log_file, quiet, json_output)
253
+
222
254
  @classmethod
223
255
  def from_config(
224
256
  cls,
@@ -243,7 +275,21 @@ class CliApp(typer.Typer):
243
275
 
244
276
  @classmethod
245
277
  def from_surface(cls, surface: CliSurface, **typer_kwargs: Any) -> Self:
246
- """Build the application an already-parsed *surface* describes."""
278
+ """Build the application an already-parsed *surface* describes.
279
+
280
+ Raises:
281
+ AppException: ``surface.distribution`` is not an installed
282
+ distribution, or a command's target cannot be imported.
283
+ """
284
+ if surface.distribution is not None:
285
+ try:
286
+ typer_kwargs["version"] = importlib.metadata.version(
287
+ surface.distribution
288
+ )
289
+ except importlib.metadata.PackageNotFoundError as error:
290
+ raise AppException(
291
+ "Distribution {!r} is not installed", surface.distribution
292
+ ) from error
247
293
  app = cls(
248
294
  surface.name,
249
295
  _escape_markup(surface.help) if surface.help else surface.help,
@@ -49,6 +49,8 @@ class CliSurface(StrictDataclassMixin):
49
49
  help: The application's ``--help`` description.
50
50
  default_log_level: The default value of ``--log-level``.
51
51
  commands: The commands and namespaces the app exposes.
52
+ distribution: The installed distribution whose version ``--version``
53
+ prints. Without one the app has no ``--version``.
52
54
  """
53
55
 
54
56
  name: str
@@ -57,10 +59,13 @@ class CliSurface(StrictDataclassMixin):
57
59
  commands: tuple[CommandSurface, ...] = field(
58
60
  default_factory=tuple[CommandSurface, ...]
59
61
  )
62
+ distribution: str | None = None
60
63
 
61
64
  def __post_init__(self) -> None:
62
65
  if not self.name.strip():
63
66
  raise AppException("A declared CLI needs a name")
67
+ if self.distribution is not None and not self.distribution.strip():
68
+ raise AppException("A declared CLI's distribution cannot be blank")
64
69
  duplicates = _duplicates(command.name for command in self.commands)
65
70
  if duplicates:
66
71
  raise AppException("Duplicate command name(s): {}", ", ".join(duplicates))
File without changes
File without changes