From e55f2de016d98bc94c8c8966931267c7fdc0121b Mon Sep 17 00:00:00 2001 From: Marco Rebhan Date: Sat, 11 Jan 2025 23:41:32 +0100 Subject: [PATCH] Show real error if module exists but import failed --- mesonbuild/interpreter/interpreter.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 02a59e3986d5..806a737ea673 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -5,6 +5,7 @@ from __future__ import annotations import hashlib +import traceback from .. import mparser from .. import environment @@ -622,8 +623,18 @@ def func_import(self, node: mparser.BaseNode, args: T.Tuple[str], if real_modname in self.modules: return self.modules[real_modname] try: - module = importlib.import_module(f'mesonbuild.modules.{real_modname}') - except ImportError: + full_module_path = f'mesonbuild.modules.{real_modname}' + module = importlib.import_module(full_module_path) + except ImportError as e: + if e.name != full_module_path: + if required: + raise e + + mlog.warning(f'Module "{modname}" exists but failed to import.') + + for line in traceback.format_exception(e): + mlog.debug(line) + if required: raise InvalidArguments(f'Module "{modname}" does not exist') ext_module = NotFoundExtensionModule(real_modname)