Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/272.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `uv tool install bambox` / `pip install bambox` producing a CLI that crashed with `ModuleNotFoundError: No module named 'click'` on typer 0.25+, which vendors its own copy of Click.
8 changes: 6 additions & 2 deletions src/bambox/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
from pathlib import Path
from typing import Annotated, Optional

import click
import typer
from rich.markup import escape

try: # typer >= 0.25 vendors its own copy of Click
from typer._click.exceptions import UsageError
except ImportError: # typer < 0.25 depends on the click package
from click.exceptions import UsageError # type: ignore[assignment]

from bambox import ui
from bambox.cura import (
PRINTER_MODEL_IDS,
Expand Down Expand Up @@ -453,6 +457,6 @@ def validate(
def main(argv: list[str] | None = None) -> None:
try:
app(argv, standalone_mode=False)
except click.UsageError as exc:
except UsageError as exc:
ui.error(str(exc))
sys.exit(2)
20 changes: 20 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,23 @@ def test_no_command_shows_help(self, capsys: pytest.CaptureFixture[str]) -> None
def test_no_command_with_flag_only(self) -> None:
with pytest.raises(SystemExit, match="2"):
main(["--nonexistent-flag"])


# ---------------------------------------------------------------------------
# Entry point exception handling
# ---------------------------------------------------------------------------


class TestUsageErrorHandling:
def test_usage_error_matches_installed_typer(self) -> None:
"""main() must catch the UsageError class the installed typer raises.

typer >= 0.25 vendors its own copy of Click, so importing
``click.UsageError`` from the standalone package would silently stop
matching (and the click package is no longer installed at all).
"""
import typer

from bambox.cli import UsageError

assert issubclass(typer.BadParameter, UsageError)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading