summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-03-28 14:33:19 -0700
committerDylan Baker <dylan@pnwbakers.com>2023-03-03 11:18:58 -0800
commitb62303942e3ad8e32d1d9e06cdc63a64cf3c363b (patch)
treed3478916178e5485720d4724dcbd3556c8eb25e2
parent34e05c01c7fe877e782b2c71f8d36e1164cac0fe (diff)
downloadmeson-b62303942e3ad8e32d1d9e06cdc63a64cf3c363b.tar.gz
modules/python: use typed_kwargs instead of known_shlib_args
We want to delete the latter, and the former is the way to do it.
-rw-r--r--mesonbuild/modules/python.py66
1 files changed, 35 insertions, 31 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 84a76c17c..ef8870daf 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -11,24 +11,24 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import annotations
+from __future__ import annotations
import copy
import os
import shutil
import typing as T
from . import ExtensionModule, ModuleInfo
+from .. import build
from .. import mesonlib
from .. import mlog
from ..coredata import UserFeatureOption
-from ..build import known_shmod_kwargs
from ..dependencies import NotFoundDependency
from ..dependencies.detect import get_dep_identifier
from ..dependencies.python import BasicPythonExternalProgram, python_factory, _PythonDependencyBase
from ..interpreter import ExternalProgramHolder, extract_required_kwarg, permitted_dependency_kwargs
from ..interpreter import primitives as P_OBJ
-from ..interpreter.type_checking import NoneType, PRESERVE_PATH_KW
+from ..interpreter.type_checking import PRESERVE_PATH_KW, SHARED_MOD_KWS, NoneType
from ..interpreterbase import (
noPosargs, noKwargs, permittedKwargs, ContainerTypeInfo,
InvalidArguments, typed_pos_args, typed_kwargs, KwargInfo,
@@ -44,7 +44,8 @@ if T.TYPE_CHECKING:
from ..build import SharedModule, Data
from ..dependencies import Dependency
from ..interpreter import Interpreter
- from ..interpreter.kwargs import ExtractRequired
+ from ..interpreter.interpreter import BuildTargetSource
+ from ..interpreter.kwargs import ExtractRequired, SharedModule as _SharedModuleKW, BuildTarget
from ..interpreterbase.interpreterbase import TYPE_var, TYPE_kwargs
class PyInstallKw(TypedDict):
@@ -59,10 +60,14 @@ if T.TYPE_CHECKING:
modules: T.List[str]
pure: T.Optional[bool]
+ class ExtensionModuleKw(_SharedModuleKW):
-mod_kwargs = {'subdir'}
-mod_kwargs.update(known_shmod_kwargs)
-mod_kwargs -= {'name_prefix', 'name_suffix'}
+ subdir: str
+
+_PURE_KW = KwargInfo('pure', (bool, NoneType))
+_SUBDIR_KW = KwargInfo('subdir', str, default='')
+_MOD_KWARGS = [k for k in SHARED_MOD_KWS if k.name not in {'name_prefix', 'name_suffix'}]
+_MOD_KWARGS.append(_SUBDIR_KW)
class PythonExternalProgram(BasicPythonExternalProgram):
@@ -99,10 +104,6 @@ class PythonExternalProgram(BasicPythonExternalProgram):
return rel_path
-_PURE_KW = KwargInfo('pure', (bool, NoneType))
-_SUBDIR_KW = KwargInfo('subdir', str, default='')
-
-
class PythonInstallation(ExternalProgramHolder):
def __init__(self, python: 'PythonExternalProgram', interpreter: 'Interpreter'):
ExternalProgramHolder.__init__(self, python, interpreter)
@@ -133,19 +134,21 @@ class PythonInstallation(ExternalProgramHolder):
'path': self.path_method,
})
- @permittedKwargs(mod_kwargs)
- def extension_module_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> 'SharedModule':
- if 'install_dir' in kwargs:
- if 'subdir' in kwargs:
- 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.')
-
- kwargs['install_dir'] = self._get_install_dir_impl(False, subdir)
-
- new_deps = mesonlib.extract_as_list(kwargs, 'dependencies')
+ @typed_pos_args('python.extension_module', str, varargs=(str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList))
+ @typed_kwargs('python.extension_module', *_MOD_KWARGS)
+ def extension_module_method(self, args: T.Tuple[str, T.List[BuildTargetSource]],
+ kwargs: ExtensionModuleKw) -> 'SharedModule':
+ # Create a copy of the keyword arguments, but as a SharedModule acrugment dictionary
+ n_kwargs = T.cast('BuildTarget', kwargs.copy())
+ del n_kwargs['subdir'] # type: ignore
+
+ if kwargs['install_dir'] and kwargs['subdir']:
+ raise InvalidArguments('"subdir" and "install_dir" are mutually exclusive')
+ elif not kwargs['install_dir']:
+ subdir = kwargs['subdir']
+ n_kwargs['install_dir'] = self._get_install_dir_impl(False, subdir)
+
+ new_deps = kwargs['dependencies'].copy()
has_pydep = any(isinstance(dep, _PythonDependencyBase) for dep in new_deps)
if not has_pydep:
pydep = self._dependency_method_impl({})
@@ -155,21 +158,22 @@ class PythonInstallation(ExternalProgramHolder):
FeatureNew.single_use('python_installation.extension_module with implicit dependency on python',
'0.63.0', self.subproject, 'use python_installation.dependency()',
self.current_node)
- kwargs['dependencies'] = new_deps
+ n_kwargs['dependencies'] = new_deps
# msys2's python3 has "-cpython-36m.dll", we have to be clever
# FIXME: explain what the specific cleverness is here
split, suffix = self.suffix.rsplit('.', 1)
- args[0] += split
+ name = args[0] + split
- kwargs['name_prefix'] = ''
- kwargs['name_suffix'] = suffix
+ n_kwargs['name_suffix'] = suffix
+ n_kwargs['name_prefix'] = ''
- if 'gnu_symbol_visibility' not in kwargs and \
+ if kwargs.get('gnu_symbol_visibility', '') == '' and \
(self.is_pypy or mesonlib.version_compare(self.version, '>=3.9')):
- kwargs['gnu_symbol_visibility'] = 'inlineshidden'
+ n_kwargs['gnu_symbol_visibility'] = 'inlineshidden'
- return self.interpreter.func_shared_module(None, args, kwargs)
+ return self.interpreter.build_target(
+ self.current_node, (name, args[1]), n_kwargs, build.SharedModule)
def _dependency_method_impl(self, kwargs: TYPE_kwargs) -> Dependency:
for_machine = self.interpreter.machine_from_native_kwarg(kwargs)