diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2022-07-14 13:12:25 -0700 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2022-08-17 16:25:36 -0400 |
commit | a78992dd81b4bd1673e4815ff26acd694ff77f68 (patch) | |
tree | 80c6dfddc3a1c8cfa45903d23c3ff01b3862051a | |
parent | c32f83a829b6b10a0cbc191c1368b563d4582c28 (diff) | |
download | meson-a78992dd81b4bd1673e4815ff26acd694ff77f68.zip meson-a78992dd81b4bd1673e4815ff26acd694ff77f68.tar.gz meson-a78992dd81b4bd1673e4815ff26acd694ff77f68.tar.bz2 |
interpreter: move handling of module stability to interpreter
Thanks to `ModuleInfo`, all modules are just named `foo.py` instead of
`unstable_foo.py`, which simplifies the import method a bit. This also
allows for accurate FeatureNew/FeatureDeprecated use, as we know when
the module was added and if/when it was stabilized.
15 files changed, 74 insertions, 38 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index fef8f4b..9cf88d7 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -599,26 +599,6 @@ class Interpreter(InterpreterBase, HoldableObject): dep = df.lookup(kwargs, force_fallback=True) self.build.stdlibs[for_machine][l] = dep - def _import_module(self, modname: str, required: bool, node: mparser.BaseNode) -> NewExtensionModule: - if modname in self.modules: - return self.modules[modname] - try: - module = importlib.import_module('mesonbuild.modules.' + modname) - except ImportError: - if required: - raise InvalidArguments(f'Module "{modname}" does not exist') - ext_module = NotFoundExtensionModule(modname) - else: - ext_module = module.initialize(self) - assert isinstance(ext_module, (ExtensionModule, NewExtensionModule)) - self.build.modules.append(modname) - if ext_module.INFO.added: - FeatureNew.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.added, self.subproject, location=node) - if ext_module.INFO.deprecated: - FeatureDeprecated.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.deprecated, self.subproject, location=node) - self.modules[modname] = ext_module - return ext_module - @typed_pos_args('import', str) @typed_kwargs( 'import', @@ -633,17 +613,56 @@ class Interpreter(InterpreterBase, HoldableObject): if disabled: return NotFoundExtensionModule(modname) - if modname.startswith('unstable-'): - plainname = modname.split('-', 1)[1] - try: - # check if stable module exists - mod = self._import_module(plainname, required, node) - mlog.warning(f'Module {modname} is now stable, please use the {plainname} module instead.') - return mod - except InvalidArguments: - mlog.warning(f'Module {modname} has no backwards or forwards compatibility and might not exist in future releases.', location=node) - modname = 'unstable_' + plainname - return self._import_module(modname, required, node) + expect_unstable = False + # Some tests use "unstable_" instead of "unstable-", and that happens to work because + # of implementation details + if modname.startswith(('unstable-', 'unstable_')): + real_modname = modname[len('unstable') + 1:] # + 1 to handle the - or _ + expect_unstable = True + else: + real_modname = modname + + if real_modname in self.modules: + return self.modules[real_modname] + try: + module = importlib.import_module(f'mesonbuild.modules.{real_modname}') + except ImportError: + if required: + raise InvalidArguments(f'Module "{modname}" does not exist') + ext_module = NotFoundExtensionModule(real_modname) + else: + ext_module = module.initialize(self) + assert isinstance(ext_module, (ExtensionModule, NewExtensionModule)) + self.build.modules.append(real_modname) + if ext_module.INFO.added: + FeatureNew.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.added, self.subproject, location=node) + if ext_module.INFO.deprecated: + FeatureDeprecated.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.deprecated, self.subproject, location=node) + if expect_unstable and not ext_module.INFO.unstable and ext_module.INFO.stabilized is None: + raise InvalidArguments(f'Module {ext_module.INFO.name} has never been unstable, remove "unstable-" prefix.') + if ext_module.INFO.stabilized is not None: + if expect_unstable: + FeatureDeprecated.single_use( + f'module {ext_module.INFO.name} has been stabilized', + ext_module.INFO.stabilized, self.subproject, + 'drop "unstable-" prefix from the module name', + location=node) + else: + FeatureNew.single_use( + f'module {ext_module.INFO.name} as stable module', + ext_module.INFO.stabilized, self.subproject, + f'Consider either adding "unstable-" to the module name, or updating the meson required version to ">= {ext_module.INFO.stabilized}"', + location=node) + elif ext_module.INFO.unstable: + if not expect_unstable: + if required: + raise InvalidArguments(f'Module "{ext_module.INFO.name}" has not been stabilized, and must be imported as unstable-{ext_module.INFO.name}') + ext_module = NotFoundExtensionModule(real_modname) + else: + mlog.warning(f'Module {ext_module.INFO.name} has no backwards or forwards compatibility and might not exist in future releases.', location=node) + + self.modules[real_modname] = ext_module + return ext_module @typed_pos_args('files', varargs=str) @noKwargs diff --git a/mesonbuild/modules/unstable_cuda.py b/mesonbuild/modules/cuda.py index b31459f..b31459f 100644 --- a/mesonbuild/modules/unstable_cuda.py +++ b/mesonbuild/modules/cuda.py diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/external_project.py index 1fd4911..1fd4911 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/external_project.py diff --git a/mesonbuild/modules/unstable_icestorm.py b/mesonbuild/modules/icestorm.py index c579148..c579148 100644 --- a/mesonbuild/modules/unstable_icestorm.py +++ b/mesonbuild/modules/icestorm.py diff --git a/mesonbuild/modules/unstable_rust.py b/mesonbuild/modules/rust.py index 792195e..792195e 100644 --- a/mesonbuild/modules/unstable_rust.py +++ b/mesonbuild/modules/rust.py diff --git a/mesonbuild/modules/unstable_simd.py b/mesonbuild/modules/simd.py index a33022d..a33022d 100644 --- a/mesonbuild/modules/unstable_simd.py +++ b/mesonbuild/modules/simd.py diff --git a/mesonbuild/modules/unstable_wayland.py b/mesonbuild/modules/wayland.py index aab07d4..aab07d4 100644 --- a/mesonbuild/modules/unstable_wayland.py +++ b/mesonbuild/modules/wayland.py diff --git a/run_mypy.py b/run_mypy.py index f5f8301..a5fc944 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -40,18 +40,18 @@ modules = [ 'mesonbuild/mintro.py', 'mesonbuild/mlog.py', 'mesonbuild/msubprojects.py', + 'mesonbuild/modules/external_project.py', 'mesonbuild/modules/fs.py', 'mesonbuild/modules/gnome.py', 'mesonbuild/modules/i18n.py', + 'mesonbuild/modules/icestorm.py', 'mesonbuild/modules/java.py', 'mesonbuild/modules/keyval.py', 'mesonbuild/modules/modtest.py', 'mesonbuild/modules/qt.py', + 'mesonbuild/modules/rust.py', 'mesonbuild/modules/sourceset.py', - 'mesonbuild/modules/unstable_external_project.py', - 'mesonbuild/modules/unstable_icestorm.py', - 'mesonbuild/modules/unstable_rust.py', - 'mesonbuild/modules/unstable_wayland.py', + 'mesonbuild/modules/wayland.py', 'mesonbuild/modules/windows.py', 'mesonbuild/mparser.py', 'mesonbuild/msetup.py', diff --git a/test cases/common/253 module warnings/meson.build b/test cases/common/253 module warnings/meson.build index 543a700..8397930 100644 --- a/test cases/common/253 module warnings/meson.build +++ b/test cases/common/253 module warnings/meson.build @@ -2,3 +2,7 @@ project('module warnings', meson_version : '>= 0.56') import('python3') # deprecated module import('java') # new module +import('unstable-keyval') # module that has been stabilized, import with unstable- + +ice = import('icestorm', required : false) +assert(not ice.found(), 'unstable-icestorm module should not be importable as `simd`') diff --git a/test cases/common/253 module warnings/test.json b/test cases/common/253 module warnings/test.json index 8833da2..ec861cc 100644 --- a/test cases/common/253 module warnings/test.json +++ b/test cases/common/253 module warnings/test.json @@ -5,6 +5,9 @@ }, { "line": "test cases/common/253 module warnings/meson.build:4: WARNING: Project targets '>= 0.56' but uses feature introduced in '0.60.0': module java." + }, + { + "line": "test cases/common/253 module warnings/meson.build:5: WARNING: Project targets '>= 0.56' but uses feature deprecated since '0.56.0': module keyval has been stabilized. drop \"unstable-\" prefix from the module name" } ] } diff --git a/test cases/keyval/1 basic/meson.build b/test cases/keyval/1 basic/meson.build index 4207b8e..a6e023e 100644 --- a/test cases/keyval/1 basic/meson.build +++ b/test cases/keyval/1 basic/meson.build @@ -1,4 +1,4 @@ -project('keyval basic test') +project('keyval basic test', meson_version : '>= 0.55') k = import('keyval') conf = k.load('.config') diff --git a/test cases/keyval/1 basic/test.json b/test cases/keyval/1 basic/test.json index dbdc5af..1f8fd9b 100644 --- a/test cases/keyval/1 basic/test.json +++ b/test cases/keyval/1 basic/test.json @@ -1,7 +1,7 @@ { "stdout": [ { - "line": "WARNING: Module unstable-keyval is now stable, please use the keyval module instead." + "line": "test cases/keyval/1 basic/meson.build:3: WARNING: Project targets '>= 0.55' but uses feature introduced in '0.56.0': module keyval as stable module. Consider either adding \"unstable-\" to the module name, or updating the meson required version to \">= 0.56.0\"" } ] } diff --git a/test cases/warning/7 module without unstable/meson.build b/test cases/warning/7 module without unstable/meson.build new file mode 100644 index 0000000..409a236 --- /dev/null +++ b/test cases/warning/7 module without unstable/meson.build @@ -0,0 +1,3 @@ +project('module import without unstable', meson_version : '>= 0.55') + +import('keyval') diff --git a/test cases/warning/7 module without unstable/test.json b/test cases/warning/7 module without unstable/test.json new file mode 100644 index 0000000..62b8aa1 --- /dev/null +++ b/test cases/warning/7 module without unstable/test.json @@ -0,0 +1,7 @@ +{ + "stdout": [ + { + "line": "test cases/warning/7 module without unstable/meson.build:3: WARNING: Project targets '>= 0.55' but uses feature introduced in '0.56.0': module keyval as stable module. Consider either adding \"unstable-\" to the module name, or updating the meson required version to \">= 0.56.0\"" + } + ] +} diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 745e67b..3238a39 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -1929,7 +1929,7 @@ class AllPlatformTests(BasePlatformTests): r'sub' + os.path.sep + r'meson.build:3: WARNING: Keyword argument "link_with" defined multiple times.', r'meson.build:6: WARNING: a warning of some sort', r'sub' + os.path.sep + r'meson.build:4: WARNING: subdir warning', - r'meson.build:7: WARNING: Module unstable-simd has no backwards or forwards compatibility and might not exist in future releases.', + r'meson.build:7: WARNING: Module SIMD has no backwards or forwards compatibility and might not exist in future releases.', r"meson.build:11: WARNING: The variable(s) 'MISSING' in the input file 'conf.in' are not present in the given configuration data.", ]: with self.subTest(expected): |