diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2020-07-15 10:45:58 +0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-07-19 17:53:32 +0300 |
commit | 1c945511eb50134974192a34e06bac7f3ce7a74b (patch) | |
tree | 88f81f42848614d01cf7eb989a626d9375c00b5c | |
parent | aa0d75deaee925b9ceb3d98ef8f5de0167587c71 (diff) | |
download | meson-1c945511eb50134974192a34e06bac7f3ce7a74b.zip meson-1c945511eb50134974192a34e06bac7f3ce7a74b.tar.gz meson-1c945511eb50134974192a34e06bac7f3ce7a74b.tar.bz2 |
Print a warning when importing a stabilized module
-rw-r--r-- | mesonbuild/interpreter.py | 24 | ||||
-rw-r--r-- | test cases/keyval/1 basic/meson.build | 2 | ||||
-rw-r--r-- | test cases/keyval/1 basic/test.json | 7 |
3 files changed, 26 insertions, 7 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 11dac38..24c2cc8 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2559,6 +2559,15 @@ class Interpreter(InterpreterBase): except InvalidArguments: pass + def import_module(self, modname): + if modname in self.modules: + return + try: + module = importlib.import_module('mesonbuild.modules.' + modname) + except ImportError: + raise InvalidArguments('Module "%s" does not exist' % (modname, )) + self.modules[modname] = module.initialize(self) + @stringArgs @noKwargs def func_import(self, node, args, kwargs): @@ -2567,14 +2576,15 @@ class Interpreter(InterpreterBase): modname = args[0] if modname.startswith('unstable-'): plainname = modname.split('-', 1)[1] - mlog.warning('Module %s has no backwards or forwards compatibility and might not exist in future releases.' % modname, location=node) - modname = 'unstable_' + plainname - if modname not in self.modules: try: - module = importlib.import_module('mesonbuild.modules.' + modname) - except ImportError: - raise InvalidArguments('Module "%s" does not exist' % (modname, )) - self.modules[modname] = module.initialize(self) + # check if stable module exists + self.import_module(plainname) + mlog.warning('Module %s is now stable, please use the %s module instead.' % (modname, plainname)) + 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 ModuleHolder(modname, self.modules[modname], self) @stringArgs diff --git a/test cases/keyval/1 basic/meson.build b/test cases/keyval/1 basic/meson.build index c3e4466..4207b8e 100644 --- a/test cases/keyval/1 basic/meson.build +++ b/test cases/keyval/1 basic/meson.build @@ -14,3 +14,5 @@ endif if conf.get('CONFIG_VAL_VAL').to_int() != 4 error('Expected CONFIG_VAL_VAL to be 4') endif + +k = import('unstable-keyval') diff --git a/test cases/keyval/1 basic/test.json b/test cases/keyval/1 basic/test.json new file mode 100644 index 0000000..dbdc5af --- /dev/null +++ b/test cases/keyval/1 basic/test.json @@ -0,0 +1,7 @@ +{ + "stdout": [ + { + "line": "WARNING: Module unstable-keyval is now stable, please use the keyval module instead." + } + ] +} |