interpreter: use typed_pos_args for func_import

and make the helper method private
pull/8950/head
Dylan Baker 3 years ago
parent 6337e40115
commit 351a1e9ec9
  1. 34
      mesonbuild/interpreter/interpreter.py

@ -601,35 +601,33 @@ class Interpreter(InterpreterBase, HoldableObject):
dep = df.lookup(kwargs, force_fallback=True)
self.build.stdlibs[for_machine][l] = dep
def import_module(self, modname):
if modname in self.modules:
return
try:
module = importlib.import_module('mesonbuild.modules.' + modname)
except ImportError:
raise InvalidArguments(f'Module "{modname}" does not exist')
ext_module = module.initialize(self)
assert isinstance(ext_module, ModuleObject)
self.modules[modname] = ext_module
@stringArgs
@typed_pos_args('import', str)
@noKwargs
def func_import(self, node, args, kwargs):
if len(args) != 1:
raise InvalidCode('Import takes one argument.')
def func_import(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs) -> ModuleObject:
modname = args[0]
if modname.startswith('unstable-'):
plainname = modname.split('-', 1)[1]
try:
# check if stable module exists
self.import_module(plainname)
self._import_module(plainname)
mlog.warning(f'Module {modname} is now stable, please use the {plainname} module instead.')
modname = plainname
except InvalidArguments:
mlog.warning('Module %s has no backwards or forwards compatibility and might not exist in future releases.' % modname, location=node)
modname = 'unstable_' + plainname
self.import_module(modname)
return self.modules[modname]
if modname in self.modules:
return self.modules[modname]
try:
module = importlib.import_module('mesonbuild.modules.' + modname)
except ImportError:
raise InvalidArguments(f'Module "{modname}" does not exist')
ext_module = module.initialize(self)
assert isinstance(ext_module, ModuleObject)
self.modules[modname] = ext_module
return ext_module
@stringArgs
@noKwargs

Loading…
Cancel
Save