From f8c04678c73d4a7871bb9da5a4686e91da082e39 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 29 Jul 2026 13:03:15 +0200 Subject: [PATCH] musrview_check: report missing Pillow/numpy explicitly If Pillow or numpy aren't importable, fail fast with a clear **ERROR** message and pip-install hint instead of a bare traceback from inside pixel_diff(). Co-Authored-By: Claude Sonnet 5 --- tests/musrview_check/musrview_check.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/musrview_check/musrview_check.py b/tests/musrview_check/musrview_check.py index b35db96b..d09c0d3a 100644 --- a/tests/musrview_check/musrview_check.py +++ b/tests/musrview_check/musrview_check.py @@ -25,6 +25,22 @@ import tempfile import time +def check_python_deps(): + """Make sure Pillow and numpy are importable; print a clear, actionable + error message (rather than a bare traceback) if they are not.""" + missing = [] + for module, pip_name in (("PIL", "Pillow"), ("numpy", "numpy")): + try: + __import__(module) + except ImportError: + missing.append(pip_name) + if missing: + print(f"**ERROR** missing required python package(s): {', '.join(missing)}") + print(f" install with: {sys.executable} -m pip install {' '.join(missing)}") + return False + return True + + def pixel_diff(img_a_path, img_b_path): """Return the mean absolute pixel difference normalised to [0, 1].""" from PIL import Image @@ -54,6 +70,9 @@ def main(): # everything after the known args is forwarded to musrview args, musrview_opts = parser.parse_known_args() + if not args.generate and not check_python_deps(): + return 1 + msr_basename = os.path.splitext(os.path.basename(args.msr_file))[0] ref_subdir = os.path.join(args.ref_dir, args.test_name)