aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-07-24 13:08:50 -0400
committerDylan Baker <dylan@pnwbakers.com>2023-02-22 10:32:09 -0800
commitb6ba054d16a6a9df53dc53acf8b54eab687cfad4 (patch)
tree3fb08684d60dd5ea5a1c42950d59066a6e1c5017
parentf5c8f8b659f53f228fe3bf5f226de565b40bc172 (diff)
downloadmeson-b6ba054d16a6a9df53dc53acf8b54eab687cfad4.zip
meson-b6ba054d16a6a9df53dc53acf8b54eab687cfad4.tar.gz
meson-b6ba054d16a6a9df53dc53acf8b54eab687cfad4.tar.bz2
python module: break the association between dependency and installation objects
We pass around a PythonInstallation into the depths of the dependency factory, solely so that we can get at is_pypy in one particular branch. We don't need the DSL functions, we don't need access to the interpreter, let's just use the enhanced ExternalProgram object on its own. Add is_pypy to the object, and modify other references to get information from .info['...'] instead of direct access.
-rw-r--r--mesonbuild/modules/python.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index a5db019..8df8f7d 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -91,13 +91,14 @@ mod_kwargs -= {'name_prefix', 'name_suffix'}
class _PythonDependencyBase(_Base):
- def __init__(self, python_holder: 'PythonInstallation', embed: bool):
+ def __init__(self, python_holder: 'PythonExternalProgram', embed: bool):
self.embed = embed
- self.version: str = python_holder.version
- self.platform = python_holder.platform
- self.variables = python_holder.variables
- self.paths = python_holder.paths
- self.link_libpython = python_holder.link_libpython
+ self.version: str = python_holder.info['version']
+ self.platform = python_holder.info['platform']
+ self.variables = python_holder.info['variables']
+ self.paths = python_holder.info['paths']
+ self.is_pypy = python_holder.info['is_pypy']
+ self.link_libpython = python_holder.info['link_libpython']
self.info: T.Optional[T.Dict[str, str]] = None
if mesonlib.version_compare(self.version, '>= 3.0'):
self.major_version = 3
@@ -108,7 +109,7 @@ class _PythonDependencyBase(_Base):
class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
- kwargs: T.Dict[str, T.Any], installation: 'PythonInstallation',
+ kwargs: T.Dict[str, T.Any], installation: 'PythonExternalProgram',
libpc: bool = False):
if libpc:
mlog.debug(f'Searching for {name!r} via pkgconfig lookup in LIBPC')
@@ -136,7 +137,7 @@ class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase):
class PythonFrameworkDependency(ExtraFrameworkDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
- kwargs: T.Dict[str, T.Any], installation: 'PythonInstallation'):
+ kwargs: T.Dict[str, T.Any], installation: 'PythonExternalProgram'):
ExtraFrameworkDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))
@@ -144,17 +145,17 @@ class PythonFrameworkDependency(ExtraFrameworkDependency, _PythonDependencyBase)
class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
- kwargs: T.Dict[str, T.Any], installation: 'PythonInstallation'):
+ kwargs: T.Dict[str, T.Any], installation: 'PythonExternalProgram'):
SystemDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))
if mesonlib.is_windows():
self._find_libpy_windows(environment)
else:
- self._find_libpy(installation, environment)
+ self._find_libpy(environment)
- def _find_libpy(self, python_holder: 'PythonInstallation', environment: 'Environment') -> None:
- if python_holder.is_pypy:
+ def _find_libpy(self, environment: 'Environment') -> None:
+ if self.is_pypy:
if self.major_version == 3:
libname = 'pypy3-c'
else:
@@ -282,21 +283,21 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
def python_factory(env: 'Environment', for_machine: 'MachineChoice',
kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods],
- installation: 'PythonInstallation') -> T.List['DependencyGenerator']:
+ installation: 'PythonExternalProgram') -> T.List['DependencyGenerator']:
# We can't use the factory_methods decorator here, as we need to pass the
# extra installation argument
embed = kwargs.get('embed', False)
candidates: T.List['DependencyGenerator'] = []
- pkg_version = installation.variables.get('LDVERSION') or installation.version
+ pkg_version = installation.info['variables'].get('LDVERSION') or installation.info['version']
if DependencyMethods.PKGCONFIG in methods:
- pkg_libdir = installation.variables.get('LIBPC')
- pkg_embed = '-embed' if embed and mesonlib.version_compare(installation.version, '>=3.8') else ''
+ pkg_libdir = installation.info['variables'].get('LIBPC')
+ pkg_embed = '-embed' if embed and mesonlib.version_compare(installation.info['version'], '>=3.8') else ''
pkg_name = f'python-{pkg_version}{pkg_embed}'
# If python-X.Y.pc exists in LIBPC, we will try to use it
def wrap_in_pythons_pc_dir(name: str, env: 'Environment', kwargs: T.Dict[str, T.Any],
- installation: 'PythonInstallation') -> 'ExternalDependency':
+ installation: 'PythonExternalProgram') -> 'ExternalDependency':
if not pkg_libdir:
# there is no LIBPC, so we can't search in it
empty = ExternalDependency(DependencyTypeName('pkgconfig'), env, {})
@@ -582,7 +583,7 @@ class PythonInstallation(ExternalProgramHolder):
methods = process_method_kw({DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM}, kwargs)
# it's theoretically (though not practically) possible to not bind dep, let's ensure it is.
dep: Dependency = NotFoundDependency('python', self.interpreter.environment)
- for d in python_factory(self.interpreter.environment, for_machine, new_kwargs, methods, self):
+ for d in python_factory(self.interpreter.environment, for_machine, new_kwargs, methods, self.held_object):
dep = d()
if dep.found():
break