Skip to content

Commit

Permalink
Show real error if module exists but import failed
Browse files Browse the repository at this point in the history
  • Loading branch information
2xsaiko committed Jan 11, 2025
1 parent 6b99eeb commit e55f2de
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import hashlib
import traceback

from .. import mparser
from .. import environment
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e55f2de

Please sign in to comment.