diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-10-21 13:58:03 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-12-17 10:27:54 -0800 |
| commit | f3d9a71a1bea661495c1d3c6004b26b4497fb1c9 (patch) | |
| tree | 8cdea7b6d898a6f54a56dcefd3965d1effcf214f | |
| parent | 52974210d5225825bf13a997941120b6c224bd9f (diff) | |
| download | meson-f3d9a71a1bea661495c1d3c6004b26b4497fb1c9.tar.gz | |
modules/python: use typed_kwargs for `install_dir`
This `install_dir` is slightly different than the one in `BuildTarget`
(though I'd like to make them the same in the future). It is only
allowed to be `str | bool | None`, and the implementation has always
assumed this, it would have broken with an array value.
| -rw-r--r-- | docs/markdown/Python-module.md | 3 | ||||
| -rw-r--r-- | mesonbuild/modules/python.py | 17 |
2 files changed, 16 insertions, 4 deletions
diff --git a/docs/markdown/Python-module.md b/docs/markdown/Python-module.md index 66081762d..8fa99fba7 100644 --- a/docs/markdown/Python-module.md +++ b/docs/markdown/Python-module.md @@ -130,6 +130,9 @@ the addition of the following: Additionally, the following diverge from [[shared_module]]'s default behavior: +- `install_dir` may only be a string, boolean, or unset, but an `array` is not + allowed. + - `gnu_symbol_visibility`: if unset, it will default to `'hidden'` on versions of Python that support this (the python headers define `PyMODINIT_FUNC` has default visibility). diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 3d8969f41..78798e5c0 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -22,7 +22,7 @@ from ..interpreterbase import ( InvalidArguments, typed_pos_args, typed_kwargs, KwargInfo, FeatureNew, disablerIfNotFound, InterpreterObject ) -from ..mesonlib import MachineChoice, listify +from ..mesonlib import MachineChoice from ..options import OptionKey from ..programs import ExternalProgram, NonExistingExternalProgram @@ -51,6 +51,8 @@ if T.TYPE_CHECKING: class ExtensionModuleKw(SharedModuleKw): + # Yes, these are different between SharedModule and ExtensionModule + install_dir: T.Union[str, bool, None] # type: ignore[misc] subdir: NotRequired[T.Optional[str]] MaybePythonProg = T.Union[NonExistingExternalProgram, 'PythonExternalProgram'] @@ -140,14 +142,21 @@ class PythonInstallation(_ExternalProgramHolder['PythonExternalProgram']): @permittedKwargs(mod_kwargs) @typed_pos_args('python.extension_module', str, varargs=(str, mesonlib.File, CustomTarget, CustomTargetIndex, GeneratedList, StructuredSources, ExtractedObjects, BuildTarget)) - @typed_kwargs('python.extension_module', *_MOD_KWARGS, _DEFAULTABLE_SUBDIR_KW, _LIMITED_API_KW, allow_unknown=True) + @typed_kwargs( + 'python.extension_module', + *_MOD_KWARGS, + _DEFAULTABLE_SUBDIR_KW, + _LIMITED_API_KW, + KwargInfo('install_dir', (str, bool, NoneType)), + allow_unknown=True + ) @InterpreterObject.method('extension_module') def extension_module_method(self, args: T.Tuple[str, T.List[BuildTargetSource]], kwargs: ExtensionModuleKw) -> 'SharedModule': - if 'install_dir' in kwargs: + if kwargs['install_dir'] is not None: if kwargs['subdir'] is not None: raise InvalidArguments('"subdir" and "install_dir" are mutually exclusive') # the build_target() method now expects this to be correct. - kwargs['install_dir'] = listify(kwargs['install_dir']) + kwargs['install_dir'] = [kwargs['install_dir']] else: # We want to remove 'subdir', but it may be None and we want to replace it with '' # It must be done this way since we don't allow both `install_dir` |
