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 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user