usecli 0.2.3__tar.gz → 0.2.5__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.
Files changed (87) hide show
  1. {usecli-0.2.3 → usecli-0.2.5}/PKG-INFO +1 -1
  2. {usecli-0.2.3 → usecli-0.2.5}/pyproject.toml +1 -1
  3. {usecli-0.2.3 → usecli-0.2.5}/pyproject.toml.orig +1 -1
  4. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/__init__.py +12 -2
  5. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/base/about_command.py +25 -2
  6. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/base/internal/interactive_command.py +42 -39
  7. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/_typer_compat.py +21 -0
  8. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/exceptions/usage.py +32 -3
  9. {usecli-0.2.3 → usecli-0.2.5}/LICENSE +0 -0
  10. {usecli-0.2.3 → usecli-0.2.5}/README.md +0 -0
  11. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/bundler/__init__.py +0 -0
  12. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/bundler/__main__.py +0 -0
  13. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/__init__.py +0 -0
  14. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/README.md +0 -0
  15. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/__init__.py +0 -0
  16. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/custom/README.md +0 -0
  17. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/custom/__init__.py +0 -0
  18. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/__init__.py +0 -0
  19. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/base/__init__.py +0 -0
  20. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/base/help_command.py +0 -0
  21. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/base/inspire_command.py +0 -0
  22. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/base/internal/__init__.py +0 -0
  23. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/base/upgrade_command.py +0 -0
  24. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/core/__init__.py +0 -0
  25. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/core/utils.py +0 -0
  26. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/make/__init__.py +0 -0
  27. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/make/make_bundle_command.py +0 -0
  28. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/make/make_command.py +0 -0
  29. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/defaults/make/make_theme_command.py +0 -0
  30. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/commands/init_command.py +0 -0
  31. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/config/__init__.py +0 -0
  32. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/config/colors.py +0 -0
  33. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/__init__.py +0 -0
  34. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/base_command.py +0 -0
  35. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/error/__init__.py +0 -0
  36. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/error/handler.py +0 -0
  37. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/error/utils.py +0 -0
  38. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/exceptions/__init__.py +0 -0
  39. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/exceptions/base.py +0 -0
  40. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/exceptions/config.py +0 -0
  41. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/exceptions/validation.py +0 -0
  42. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/runtime.py +0 -0
  43. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/ui/__init__.py +0 -0
  44. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/ui/list.py +0 -0
  45. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/ui/title.py +0 -0
  46. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/ui/title.txt +0 -0
  47. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/validators/__init__.py +0 -0
  48. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/validators/network.py +0 -0
  49. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/validators/numeric.py +0 -0
  50. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/validators/path.py +0 -0
  51. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/core/validators/string.py +0 -0
  52. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/services/__init__.py +0 -0
  53. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/services/command_service.py +0 -0
  54. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/templates/command.py.j2 +0 -0
  55. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/templates/theme.toml.j2 +0 -0
  56. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/templates/usecli.config.toml.j2 +0 -0
  57. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/ayu_dark.toml +0 -0
  58. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/catppuccin_frappe.toml +0 -0
  59. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/catppuccin_latte.toml +0 -0
  60. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/catppuccin_macchiato.toml +0 -0
  61. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/catppuccin_mocha.toml +0 -0
  62. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/default.toml +0 -0
  63. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/dracula.toml +0 -0
  64. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/gruvbox_dark.toml +0 -0
  65. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/nord.toml +0 -0
  66. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/themes/tokyo_night.toml +0 -0
  67. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/utils/__init__.py +0 -0
  68. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/utils/interactive/__init__.py +0 -0
  69. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/utils/interactive/prompt_input.py +0 -0
  70. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/cli/utils/interactive/terminal_menu.py +0 -0
  71. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/entry.py +0 -0
  72. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/menu.py +0 -0
  73. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/params.py +0 -0
  74. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/progress.py +0 -0
  75. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/__init__.py +0 -0
  76. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/config/__init__.py +0 -0
  77. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/config/globals.py +0 -0
  78. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/config/manager.py +0 -0
  79. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/upgrades/__init__.py +0 -0
  80. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/upgrades/checker.py +0 -0
  81. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/upgrades/discovery.py +0 -0
  82. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/upgrades/installer.py +0 -0
  83. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/upgrades/pyproject.py +0 -0
  84. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/upgrades/service.py +0 -0
  85. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/shared/upgrades/settings.py +0 -0
  86. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/ui.py +0 -0
  87. {usecli-0.2.3 → usecli-0.2.5}/src/usecli/usecli.config.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usecli
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: A powerful Python CLI framework for building beautiful, developer-friendly command-line tools.
5
5
  Author: Edward Boswell
6
6
  Author-email: Edward Boswell <thememium@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "usecli"
3
- version = "0.2.3"
3
+ version = "0.2.5"
4
4
  description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "usecli"
3
- version = "0.2.3"
3
+ version = "0.2.5"
4
4
  description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Edward Boswell", email = "thememium@gmail.com" }]
@@ -297,7 +297,12 @@ def _ensure_cli_initialized() -> None:
297
297
  except _TyperBadParameter as e:
298
298
  from usecli.cli.core.exceptions import UsecliBadParameter
299
299
 
300
- styled_error = UsecliBadParameter(e.message, ctx=e.ctx, param=e.param)
300
+ styled_error = UsecliBadParameter(
301
+ e.message,
302
+ ctx=e.ctx,
303
+ param=e.param,
304
+ formatted_message=e.format_message(),
305
+ )
301
306
  styled_error.show()
302
307
  sys.exit(styled_error.exit_code)
303
308
  except _TyperUsageError as e:
@@ -627,7 +632,12 @@ def main() -> None:
627
632
  except _TyperBadParameter as e:
628
633
  from usecli.cli.core.exceptions import UsecliBadParameter
629
634
 
630
- styled_error = UsecliBadParameter(e.message, ctx=e.ctx, param=e.param)
635
+ styled_error = UsecliBadParameter(
636
+ e.message,
637
+ ctx=e.ctx,
638
+ param=e.param,
639
+ formatted_message=e.format_message(),
640
+ )
631
641
  styled_error.show()
632
642
  sys.exit(styled_error.exit_code)
633
643
  except _TyperUsageError as e:
@@ -1,9 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
+ import re
4
5
  import sys
5
6
  import tomllib
6
7
  from importlib.metadata import PackageNotFoundError
8
+ from importlib.metadata import version as get_version
7
9
  from pathlib import Path
8
10
 
9
11
  from usecli.cli.config.colors import COLOR
@@ -66,6 +68,22 @@ def _parse_dependency_requirement(req: str) -> tuple[str, str | None]:
66
68
  return name, remainder
67
69
 
68
70
 
71
+ def _is_extra_requirement(req: str) -> bool:
72
+ """True when the requirement's marker gates it behind an optional extra."""
73
+ _, sep, marker = req.partition(";")
74
+ if not sep:
75
+ return False
76
+ return re.search(r"\bextra\b", marker) is not None
77
+
78
+
79
+ def _is_dependency_installed(name: str) -> bool:
80
+ try:
81
+ get_version(name)
82
+ except (PackageNotFoundError, OSError):
83
+ return False
84
+ return True
85
+
86
+
69
87
  def _get_console_script_distribution(command_name: str | None):
70
88
  if not command_name:
71
89
  return None
@@ -81,8 +99,13 @@ def _get_package_dependencies_from_distribution(dist) -> list[tuple[str, str | N
81
99
  if not isinstance(req, str):
82
100
  continue
83
101
  name, spec = _parse_dependency_requirement(req)
84
- if name and not req.startswith("("):
85
- result.append((name, spec))
102
+ if not name or req.startswith("("):
103
+ continue
104
+ # ``dist.requires`` includes extra-gated requirements. Those are
105
+ # optional, so only list them when they are actually installed.
106
+ if _is_extra_requirement(req) and not _is_dependency_installed(name):
107
+ continue
108
+ result.append((name, spec))
86
109
  return result
87
110
 
88
111
 
@@ -283,6 +283,33 @@ def _get_group_subcommands(
283
283
  return subcommands
284
284
 
285
285
 
286
+ def _prompt_for_text(prompt_text: str, empty_message: str) -> str:
287
+ """Read a non-empty value through rich's prompt-toolkit input seam.
288
+
289
+ ``console.input`` is patched by
290
+ :func:`usecli.cli.utils.interactive.prompt_input.install_prompt_input`, so
291
+ cursor keys, editing and history work instead of reaching a raw
292
+ ``input()``.
293
+ """
294
+ value = ""
295
+ while not value:
296
+ try:
297
+ value = console.input(
298
+ f"[bold {COLOR.SECONDARY}]{prompt_text}[/bold {COLOR.SECONDARY}]\n"
299
+ f"[bold {COLOR.SECONDARY}]└─> [/bold {COLOR.SECONDARY}]"
300
+ ).strip()
301
+ except EOFError:
302
+ value = ""
303
+ except KeyboardInterrupt:
304
+ ErrorHandler.display_warning("Cancelled by user")
305
+ raise typer.Exit(code=0)
306
+
307
+ if not value:
308
+ console.print(f"[{COLOR.ERROR}]{empty_message}[/{COLOR.ERROR}]")
309
+
310
+ return value
311
+
312
+
286
313
  def run_interactive(
287
314
  app: typer.Typer,
288
315
  cmd_parts: list[str] | None = None,
@@ -457,28 +484,13 @@ def run_interactive(
457
484
  )
458
485
  value = str(int_value)
459
486
  else:
460
- value = ""
461
- while not value:
462
- prompt_text = f"Enter value for '{arg_name}'"
463
- if arg_help:
464
- prompt_text += f" ({arg_help})"
465
- prompt_text += ":"
466
- console.print(f"[bold {COLOR.SECONDARY}]{prompt_text}")
467
- console.print(f"[bold {COLOR.SECONDARY}]└─> ", end="")
468
-
469
- try:
470
- user_input = input()
471
- value = user_input.strip()
472
- except EOFError:
473
- value = ""
474
- except KeyboardInterrupt:
475
- ErrorHandler.display_warning("Cancelled by user")
476
- raise typer.Exit(code=0)
477
-
478
- if not value:
479
- console.print(
480
- f"[{COLOR.ERROR}]Value is required. Please enter a value.[/{COLOR.ERROR}]"
481
- )
487
+ prompt_text = f"Enter value for '{arg_name}'"
488
+ if arg_help:
489
+ prompt_text += f" ({arg_help})"
490
+ prompt_text += ":"
491
+ value = _prompt_for_text(
492
+ prompt_text, "Value is required. Please enter a value."
493
+ )
482
494
 
483
495
  if " " in value:
484
496
  value = f'"{value}"'
@@ -555,23 +567,14 @@ def run_interactive(
555
567
  )
556
568
  option_values.append(f"{first_flag} {int_value}")
557
569
  else:
558
- opt_value = ""
559
- while not opt_value:
560
- prompt_text = f"[bold {COLOR.SECONDARY}]Value for {first_flag}"
561
- if help_text:
562
- prompt_text += f" ({help_text})"
563
- prompt_text += ":"
564
- console.print(prompt_text)
565
- console.print(f"[bold {COLOR.SECONDARY}]└─> ", end="")
566
- try:
567
- opt_value = input().strip()
568
- except KeyboardInterrupt:
569
- ErrorHandler.display_warning("Cancelled by user")
570
- raise typer.Exit(code=0)
571
- if not opt_value:
572
- console.print(
573
- f"[{COLOR.ERROR}]Value is required. Please enter a value or press Ctrl+C to cancel.[/{COLOR.ERROR}]"
574
- )
570
+ prompt_text = f"Value for {first_flag}"
571
+ if help_text:
572
+ prompt_text += f" ({help_text})"
573
+ prompt_text += ":"
574
+ opt_value = _prompt_for_text(
575
+ prompt_text,
576
+ "Value is required. Please enter a value or press Ctrl+C to cancel.",
577
+ )
575
578
  if " " in opt_value:
576
579
  opt_value = f'"{opt_value}"'
577
580
  option_values.append(f"{first_flag} {opt_value}")
@@ -3,10 +3,15 @@
3
3
  Typer >= 0.28 replaced ``TyperOption``'s ``type`` argument with a required
4
4
  ``type_descriptor``. usecli builds options directly to inject framework-wide
5
5
  flags, so it must support both layouts.
6
+
7
+ Typer also vendors its own click, whose parameter classes predate click's
8
+ ``get_error_hint(ctx)`` signature. usecli formats typer parameters with
9
+ click's exception classes, so the hint methods are adapted below.
6
10
  """
7
11
 
8
12
  from __future__ import annotations
9
13
 
14
+ import functools
10
15
  import inspect
11
16
  from typing import Any
12
17
 
@@ -17,6 +22,22 @@ _HAS_TYPE_DESCRIPTOR = (
17
22
  )
18
23
 
19
24
 
25
+ def _accept_click_ctx(method: Any) -> Any:
26
+ """Let click pass its context to a typer parameter's error hint method."""
27
+ if "ctx" in inspect.signature(method).parameters:
28
+ return method
29
+
30
+ @functools.wraps(method)
31
+ def get_error_hint(self: Any, ctx: Any = None) -> str:
32
+ return method(self)
33
+
34
+ return get_error_hint
35
+
36
+
37
+ TyperArgument.get_error_hint = _accept_click_ctx(TyperArgument.get_error_hint)
38
+ TyperOption.get_error_hint = _accept_click_ctx(TyperOption.get_error_hint)
39
+
40
+
20
41
  def _type_descriptor(annotation: type, *, argument: bool = False) -> Any:
21
42
  from typer._coercion import resolve_type_descriptor
22
43
  from typer.models import ArgumentInfo, OptionInfo
@@ -3,9 +3,11 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import sys
6
+ from collections.abc import Sequence
6
7
  from typing import IO
7
8
 
8
9
  from click.core import Context as ClickContext
10
+ from click.core import Parameter as ClickParameter
9
11
  from click.exceptions import BadParameter, Exit, UsageError
10
12
  from rich.console import Console
11
13
 
@@ -67,7 +69,8 @@ class UsecliUsageError(UsageError):
67
69
  if self.ctx:
68
70
  console.print()
69
71
  help_text = _get_help_text_with_command_name(self.ctx)
70
- console.print(help_text)
72
+ if help_text:
73
+ console.print(help_text)
71
74
 
72
75
 
73
76
  class UsecliBadParameter(BadParameter):
@@ -77,6 +80,30 @@ class UsecliBadParameter(BadParameter):
77
80
  Provides highlighted error boxes and command help on validation failures.
78
81
  """
79
82
 
83
+ def __init__(
84
+ self,
85
+ message: str,
86
+ ctx: ClickContext | None = None,
87
+ param: ClickParameter | None = None,
88
+ param_hint: str | Sequence[str] | None = None,
89
+ formatted_message: str | None = None,
90
+ ) -> None:
91
+ """Initialize the styled parameter error.
92
+
93
+ Args:
94
+ message: Raw error reason (Click's ``BadParameter.message``).
95
+ ctx: Click context used to render command help.
96
+ param: Parameter the error refers to.
97
+ param_hint: Explicit hint replacing the parameter-derived hint.
98
+ formatted_message: Fully formatted message to render instead of
99
+ rebuilding one from ``message``. Wrappers use this to keep
100
+ the original exception's wording (for example Click's
101
+ ``MissingParameter``, whose reason lives only in
102
+ ``format_message``).
103
+ """
104
+ super().__init__(message, ctx=ctx, param=param, param_hint=param_hint)
105
+ self.formatted_message = formatted_message
106
+
80
107
  def show(self, file: IO[str] | None = None) -> None:
81
108
  """Display styled parameter error with command help.
82
109
 
@@ -88,12 +115,14 @@ class UsecliBadParameter(BadParameter):
88
115
 
89
116
  console.print()
90
117
 
118
+ message = self.formatted_message or self.format_message()
91
119
  error_prefix = (
92
120
  f"[bold black on {COLOR.ERROR}] ERROR [/bold black on {COLOR.ERROR}]"
93
121
  )
94
- error_msg = f"[bold {COLOR.ERROR}]{self.format_message()}[/bold {COLOR.ERROR}]"
122
+ error_msg = f"[bold {COLOR.ERROR}]{message}[/bold {COLOR.ERROR}]"
95
123
  console.print(f"{error_prefix} {error_msg}")
96
124
 
97
125
  if self.ctx:
98
126
  help_text = _get_help_text_with_command_name(self.ctx)
99
- console.print(help_text)
127
+ if help_text:
128
+ console.print(help_text)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes