Skip to content

Commit ba81495

Browse files
committed
Refactor
1 parent 99f5bcf commit ba81495

4 files changed

Lines changed: 37 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project are documented here.
77
### Added
88

99
- Add optional 3MF post-processing script checks. By default, the bridge notifies the user, writes the script text to the log, and then continues opening the file.
10+
- Add `post_process_action` config support with `warn`, `block`, and `ignore` modes.
1011

1112
### Fixed
1213

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)
66
[![Platform: Windows | macOS | Linux](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey.svg)]()
77

8+
[Installation](#installation) · [Security Model](#security-model) · [Changelog](CHANGELOG.md)
9+
810
Slicer URI Bridge helps open 3D model links from websites in Bambu Studio, including sites that do not provide a native Bambu Studio button or where that integration is not available.
911

1012
https://github.com/user-attachments/assets/32b1fd48-4498-42de-81d6-629b452712b9

src/slicer_uri_bridge/cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import subprocess
77
import sys
88
import tomllib
9-
from importlib.metadata import version as package_version
9+
from importlib.metadata import PackageNotFoundError, version as package_version
1010
from pathlib import Path
1111

1212
from .config import config_matches_default, init_user_config, user_config_path
1313
from .manager import main as manager_main
1414

1515

16+
PACKAGE_NAME = "slicer-uri-bridge"
1617
YES_VALUES = {"y", "yes"}
1718
NO_VALUES = {"n", "no"}
1819
IS_WINDOWS = sys.platform == "win32"
@@ -27,6 +28,13 @@ def eprint(message: str) -> None:
2728
print(message, file=sys.stderr)
2829

2930

31+
def metadata_version() -> str:
32+
try:
33+
return package_version(PACKAGE_NAME)
34+
except PackageNotFoundError:
35+
return "unknown"
36+
37+
3038
def build_parser() -> argparse.ArgumentParser:
3139
parser = argparse.ArgumentParser(
3240
prog="slicer-uri-bridge",
@@ -35,7 +43,7 @@ def build_parser() -> argparse.ArgumentParser:
3543
parser.add_argument(
3644
"--version",
3745
action="version",
38-
version=f"%(prog)s {package_version('slicer-uri-bridge')}",
46+
version=f"%(prog)s {metadata_version()}",
3947
)
4048

4149
subparsers = parser.add_subparsers(dest="command", required=True)

tests/test_cli.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ def isatty(self) -> bool:
3333
return True
3434

3535

36+
class CliVersionTests(unittest.TestCase):
37+
def test_version_action_uses_fallback_when_package_metadata_is_absent(self) -> None:
38+
with (
39+
patch("slicer_uri_bridge.cli.package_version", side_effect=cli.PackageNotFoundError),
40+
patch("sys.stdout", new_callable=StringIO) as stdout,
41+
):
42+
parser = cli.build_parser()
43+
with self.assertRaises(SystemExit) as exit_context:
44+
parser.parse_args(["--version"])
45+
46+
self.assertEqual(exit_context.exception.code, 0)
47+
self.assertIn("slicer-uri-bridge unknown", stdout.getvalue())
48+
49+
def test_subcommands_do_not_require_package_metadata(self) -> None:
50+
with (
51+
patch("slicer_uri_bridge.cli.package_version", side_effect=cli.PackageNotFoundError),
52+
patch("slicer_uri_bridge.cli.user_config_path", return_value=Path("config.toml")),
53+
patch("sys.stdout", new_callable=StringIO) as stdout,
54+
):
55+
self.assertEqual(cli.main(["config-path"]), 0)
56+
57+
self.assertIn("config.toml", stdout.getvalue())
58+
59+
3660
class InteractiveOnboardingTests(unittest.TestCase):
3761
def test_package_can_run_as_python_module(self) -> None:
3862
completed = subprocess.run(

0 commit comments

Comments
 (0)