From ae3fd3d4ea516bb3b0b51693e453f4d53e09a14e Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 14 Jul 2026 12:21:20 -0700 Subject: [PATCH] fix(rawcli): friendly message when prompt_toolkit isn't installed `pm3py rawcli` lives behind the optional [rawcli] extra; a plain install of pm3py doesn't pull prompt_toolkit. Catch the ModuleNotFoundError and print an install hint (pip install 'pm3py[rawcli]') with exit code 2, instead of dumping a traceback. Co-Authored-By: Claude Opus 4.8 --- pm3py/cli/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pm3py/cli/main.py b/pm3py/cli/main.py index 72b0b9b..125d969 100644 --- a/pm3py/cli/main.py +++ b/pm3py/cli/main.py @@ -6,6 +6,7 @@ is left for ``flash`` (wrapping pm3flash) and a future ``client`` command CLI. from __future__ import annotations import argparse +import sys def build_parser() -> argparse.ArgumentParser: @@ -20,6 +21,16 @@ def main(argv: list[str] | None = None) -> int: parser = build_parser() args = parser.parse_args(argv) if args.command == "rawcli": + try: + import prompt_toolkit # noqa: F401 + except ModuleNotFoundError: + print( + "pm3py rawcli needs prompt_toolkit, which isn't installed.\n" + " install it with: pip install 'pm3py[rawcli]'\n" + " or directly: pip install prompt_toolkit", + file=sys.stderr, + ) + return 2 from pm3py.cli.rawcli.app import run return run(port=args.port) parser.print_help()