diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-09-06 00:42:21 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2022-09-19 21:13:37 -0400 |
commit | eb69fed2f64a20fa3098dc47aa4a64fb68ba7c35 (patch) | |
tree | 9db2338d7e57560e457121ff72666fa6e22d3c3d | |
parent | b8e53ed5ea9c2a3eec19396233e646d4c1f667ae (diff) | |
download | meson-eb69fed2f64a20fa3098dc47aa4a64fb68ba7c35.zip meson-eb69fed2f64a20fa3098dc47aa4a64fb68ba7c35.tar.gz meson-eb69fed2f64a20fa3098dc47aa4a64fb68ba7c35.tar.bz2 |
python module: allow specifying the pure kwarg in the installation object
Fixes #10523
-rw-r--r-- | docs/markdown/snippets/python-installation-pure.md | 8 | ||||
-rw-r--r-- | mesonbuild/modules/python.py | 17 | ||||
-rw-r--r-- | test cases/python/7 install path/meson.build | 8 | ||||
-rw-r--r-- | test cases/python/7 install path/test.json | 8 |
4 files changed, 36 insertions, 5 deletions
diff --git a/docs/markdown/snippets/python-installation-pure.md b/docs/markdown/snippets/python-installation-pure.md new file mode 100644 index 0000000..905c7b8 --- /dev/null +++ b/docs/markdown/snippets/python-installation-pure.md @@ -0,0 +1,8 @@ +## python.find_installation() now accepts pure argument + +The default value of `pure:` for `py.install_sources()` and +`py.get_install_dir()` can now be changed by explicitly passing a `pure:` kwarg +to `find_installation()`. + +This can be used to ensure that multiple `install_sources()` invocations do not +forget to specify the kwarg each time. diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 6c5fcfe..84ec524 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -14,6 +14,7 @@ from __future__ import annotations from pathlib import Path +import copy import functools import json import os @@ -67,7 +68,7 @@ if T.TYPE_CHECKING: class PyInstallKw(TypedDict): - pure: bool + pure: T.Optional[bool] subdir: str install_tag: T.Optional[str] @@ -75,6 +76,7 @@ if T.TYPE_CHECKING: disabler: bool modules: T.List[str] + pure: T.Optional[bool] _Base = ExternalDependency else: @@ -409,6 +411,7 @@ class PythonExternalProgram(ExternalProgram): 'variables': {}, 'version': '0.0', } + self.pure: bool = True def _check_version(self, version: str) -> bool: if self.name == 'python2': @@ -472,7 +475,7 @@ class PythonExternalProgram(ExternalProgram): return rel_path -_PURE_KW = KwargInfo('pure', bool, default=True) +_PURE_KW = KwargInfo('pure', (bool, NoneType)) _SUBDIR_KW = KwargInfo('subdir', str, default='') @@ -485,6 +488,7 @@ class PythonInstallation(ExternalProgramHolder): self.variables = info['variables'] self.suffix = info['suffix'] self.paths = info['paths'] + self.pure = python.pure self.platlib_install_path = os.path.join(prefix, python.platlib) self.purelib_install_path = os.path.join(prefix, python.purelib) self.version = info['version'] @@ -599,7 +603,8 @@ class PythonInstallation(ExternalProgramHolder): def install_sources_method(self, args: T.Tuple[T.List[T.Union[str, mesonlib.File]]], kwargs: 'PyInstallKw') -> 'Data': tag = kwargs['install_tag'] or 'runtime' - install_dir = self._get_install_dir_impl(kwargs['pure'], kwargs['subdir']) + pure = kwargs['pure'] if kwargs['pure'] is not None else self.pure + install_dir = self._get_install_dir_impl(pure, kwargs['subdir']) return self.interpreter.install_data_impl( self.interpreter.source_strings_to_files(args[0]), install_dir, @@ -610,7 +615,8 @@ class PythonInstallation(ExternalProgramHolder): @noPosargs @typed_kwargs('python_installation.install_dir', _PURE_KW, _SUBDIR_KW) def get_install_dir_method(self, args: T.List['TYPE_var'], kwargs: 'PyInstallKw') -> str: - return self._get_install_dir_impl(kwargs['pure'], kwargs['subdir']) + pure = kwargs['pure'] if kwargs['pure'] is not None else self.pure + return self._get_install_dir_impl(pure, kwargs['subdir']) def _get_install_dir_impl(self, pure: bool, subdir: str) -> P_OBJ.OptionString: if pure: @@ -733,6 +739,7 @@ class PythonModule(ExtensionModule): KwargInfo('required', (bool, UserFeatureOption), default=True), KwargInfo('disabler', bool, default=False, since='0.49.0'), KwargInfo('modules', ContainerTypeInfo(list, str), listify=True, default=[], since='0.51.0'), + _PURE_KW.evolve(default=True, since='0.64.0'), ) def find_installation(self, state: 'ModuleState', args: T.Tuple[T.Optional[str]], kwargs: 'FindInstallationKw') -> ExternalProgram: @@ -797,6 +804,8 @@ class PythonModule(ExtensionModule): raise mesonlib.MesonException('{} is missing modules: {}'.format(name_or_path or 'python', ', '.join(missing_modules))) return NonExistingExternalProgram() else: + python = copy.copy(python) + python.pure = kwargs['pure'] return python raise mesonlib.MesonBugException('Unreachable code was reached (PythonModule.find_installation).') diff --git a/test cases/python/7 install path/meson.build b/test cases/python/7 install path/meson.build index 5f0f7df..1075c1b 100644 --- a/test cases/python/7 install path/meson.build +++ b/test cases/python/7 install path/meson.build @@ -8,5 +8,13 @@ project('install path', py = import('python').find_installation() py.install_sources('test.py') py.install_sources('test.py', pure: false) +install_data('test.py', install_dir: py.get_install_dir() / 'data') +install_data('test.py', install_dir: py.get_install_dir(pure: false) / 'data') + +py_plat = import('python').find_installation(pure: false) +py_plat.install_sources('test.py', subdir: 'kw') +py_plat.install_sources('test.py', pure: true, subdir: 'kwrevert') +install_data('test.py', install_dir: py_plat.get_install_dir() / 'kw/data') +install_data('test.py', install_dir: py_plat.get_install_dir(pure: true) / 'kwrevert/data') subdir('structured') diff --git a/test cases/python/7 install path/test.json b/test cases/python/7 install path/test.json index 9b05b66..cf8e7a9 100644 --- a/test cases/python/7 install path/test.json +++ b/test cases/python/7 install path/test.json @@ -6,7 +6,13 @@ {"type": "file", "file": "pure/alpha/two.py"}, {"type": "file", "file": "pure/alpha/three.py"}, {"type": "file", "file": "pure/beta/one.py"}, + {"type": "file", "file": "plat/kw/test.py"}, + {"type": "file", "file": "pure/kwrevert/test.py"}, {"type": "file", "file": "plat/test.py"}, - {"type": "file", "file": "pure/test.py"} + {"type": "file", "file": "pure/test.py"}, + {"type": "file", "file": "plat/data/test.py"}, + {"type": "file", "file": "pure/data/test.py"}, + {"type": "file", "file": "plat/kw/data/test.py"}, + {"type": "file", "file": "pure/kwrevert/data/test.py"} ] } |