diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2023-07-25 09:41:53 -0700 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-07-28 17:27:21 -0400 |
commit | 848614ababa9d10a3285029acf6635aeaad8567a (patch) | |
tree | eb60df1662876ab3ec65cdca629c6efc5b046045 /mesonbuild | |
parent | a8cba0768700916c4fc73aaa9b003cc9f1c713df (diff) | |
download | meson-848614ababa9d10a3285029acf6635aeaad8567a.zip meson-848614ababa9d10a3285029acf6635aeaad8567a.tar.gz meson-848614ababa9d10a3285029acf6635aeaad8567a.tar.bz2 |
modules/python: typed_kwargs for subdir
We cannot re-use the existing KwargInfo, since we need to know if the
keyword was set explicitly or not, since it conflicts with `install_dir`
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/modules/python.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 3ac4c87..cec9894 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -36,7 +36,7 @@ from ..mesonlib import MachineChoice from ..programs import ExternalProgram, NonExistingExternalProgram if T.TYPE_CHECKING: - from typing_extensions import TypedDict + from typing_extensions import TypedDict, NotRequired from . import ModuleState from ..build import Build, SharedModule, Data @@ -59,7 +59,7 @@ if T.TYPE_CHECKING: class ExtensionModuleKw(SharedModuleKw): - pass + subdir: NotRequired[T.Optional[str]] mod_kwargs = {'subdir'} @@ -111,7 +111,7 @@ class PythonExternalProgram(BasicPythonExternalProgram): _PURE_KW = KwargInfo('pure', (bool, NoneType)) _SUBDIR_KW = KwargInfo('subdir', str, default='') - +_DEFAULTABLE_SUBDIR_KW = KwargInfo('subdir', (str, NoneType)) class PythonInstallation(ExternalProgramHolder): def __init__(self, python: 'PythonExternalProgram', interpreter: 'Interpreter'): @@ -144,15 +144,16 @@ class PythonInstallation(ExternalProgramHolder): }) @permittedKwargs(mod_kwargs) - @typed_kwargs('python.extension_module', *_MOD_KWARGS, allow_unknown=True) + @typed_kwargs('python.extension_module', *_MOD_KWARGS, _DEFAULTABLE_SUBDIR_KW, allow_unknown=True) def extension_module_method(self, args: T.List['TYPE_var'], kwargs: ExtensionModuleKw) -> 'SharedModule': if 'install_dir' in kwargs: - if 'subdir' in kwargs: + if kwargs['subdir'] is not None: raise InvalidArguments('"subdir" and "install_dir" are mutually exclusive') else: - subdir = kwargs.pop('subdir', '') - if not isinstance(subdir, str): - raise InvalidArguments('"subdir" argument must be a string.') + # 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` + # and `subdir` to be set at the same time + subdir = kwargs.pop('subdir') or '' kwargs['install_dir'] = self._get_install_dir_impl(False, subdir) |