diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-07-13 14:58:23 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-07-13 16:43:14 -0700 |
commit | b4e826bff3c9e72230634fb0f7f10904b777d795 (patch) | |
tree | 34f463ae39f8810c5d4c930edcef7d112867b55f /mesonbuild/modules/python.py | |
parent | dd97ec607d9ae073cb5d07da5b7e476afbfc0a0d (diff) | |
download | meson-b4e826bff3c9e72230634fb0f7f10904b777d795.zip meson-b4e826bff3c9e72230634fb0f7f10904b777d795.tar.gz meson-b4e826bff3c9e72230634fb0f7f10904b777d795.tar.bz2 |
modules/python: fix up a few simply typing warnings/errors
These were spotted by mypy and pyright. One is a string where a Path is
expected, another other is a possibly unbound variable, and the third is
bound but unused variables.
Diffstat (limited to 'mesonbuild/modules/python.py')
-rw-r--r-- | mesonbuild/modules/python.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index e267500..450991b 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -22,13 +22,14 @@ import typing as T from . import ExtensionModule from .. import mesonlib from .. import mlog +from ..coredata import UserFeatureOption from ..build import known_shmod_kwargs from ..dependencies import DependencyMethods, PkgConfigDependency, NotFoundDependency, SystemDependency, ExtraFrameworkDependency from ..dependencies.base import process_method_kw from ..environment import detect_cpu_family from ..interpreter import ExternalProgramHolder, extract_required_kwarg, permitted_dependency_kwargs from ..interpreterbase import ( - noPosargs, noKwargs, permittedKwargs, + noPosargs, noKwargs, permittedKwargs, ContainerTypeInfo, InvalidArguments, typed_pos_args, typed_kwargs, KwargInfo, FeatureNew, FeatureNewKwargs, disablerIfNotFound ) @@ -157,7 +158,7 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase): else: comp = self.get_compiler() if comp.id == "gcc": - libpath = f'python{vernum}.dll' + libpath = Path(f'python{vernum}.dll') else: libpath = Path('libs') / f'python{vernum}.lib' lib = Path(self.variables.get('base')) / libpath @@ -167,6 +168,9 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase): else: libname = self.variables.get('LDLIBRARY') lib = Path(self.variables.get('LIBDIR')) / libname + else: + raise mesonlib.MesonBugException( + 'On a Windows path, but the OS doesn\'t appear to be Windows or MinGW.') if not lib.exists(): mlog.log('Could not find Python3 library {!r}'.format(str(lib))) return None @@ -491,6 +495,15 @@ class PythonInstallation(ExternalProgramHolder): return super().path_method(args, kwargs) +if T.TYPE_CHECKING: + from ..interpreter.kwargs import ExtractRequired + + class FindInstallationKw(ExtractRequired): + + disabler: bool + modules: T.List[str] + + class PythonModule(ExtensionModule): @FeatureNew('Python Module', '0.46.0') @@ -525,16 +538,19 @@ class PythonModule(ExtensionModule): return mesonlib.version_compare(version, '>= 3.0') return True - @FeatureNewKwargs('python.find_installation', '0.49.0', ['disabler']) - @FeatureNewKwargs('python.find_installation', '0.51.0', ['modules']) @disablerIfNotFound - @permittedKwargs({'required', 'modules'}) @typed_pos_args('python.find_installation', optargs=[str]) + @typed_kwargs( + 'python.find_installation', + 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'), + ) def find_installation(self, state: 'ModuleState', args: T.Tuple[T.Optional[str]], - kwargs: 'TYPE_kwargs') -> ExternalProgram: + kwargs: 'FindInstallationKw') -> ExternalProgram: feature_check = FeatureNew('Passing "feature" option to find_installation', '0.48.0') disabled, required, feature = extract_required_kwarg(kwargs, state.subproject, feature_check) - want_modules = mesonlib.extract_as_list(kwargs, 'modules') # type: T.List[str] + want_modules = kwargs['modules'] found_modules: T.List[str] = [] missing_modules: T.List[str] = [] @@ -575,7 +591,7 @@ class PythonModule(ExtensionModule): if python.found() and want_modules: for mod in want_modules: - p, out, err = mesonlib.Popen_safe( + p, *_ = mesonlib.Popen_safe( python.command + ['-c', f'import {mod}']) if p.returncode != 0: |