partial migration of the python module dependency into dependencies

In preparation for wholly merging the dependency handling from the
python module into dependencies.*, move the unique class definitions
from there into their new home in dependencies.python, which is
semantically convenient.
pull/11250/head
Eli Schwartz 2 years ago committed by Dylan Baker
parent 9fa4da3ba9
commit 29592481bc
  1. 61
      mesonbuild/dependencies/python.py
  2. 61
      mesonbuild/modules/python.py

@ -18,8 +18,10 @@ from pathlib import Path
import typing as T
from .. import mesonlib, mlog
from .base import DependencyMethods, SystemDependency
from .base import DependencyMethods, ExternalDependency, SystemDependency
from .factory import DependencyFactory
from .framework import ExtraFrameworkDependency
from .pkgconfig import PkgConfigDependency
from ..environment import detect_cpu_family
from ..programs import ExternalProgram
@ -41,6 +43,10 @@ if T.TYPE_CHECKING:
variables: T.Dict[str, str]
version: str
_Base = ExternalDependency
else:
_Base = object
class BasicPythonExternalProgram(ExternalProgram):
def __init__(self, name: str, command: T.Optional[T.List[str]] = None,
@ -103,6 +109,59 @@ class BasicPythonExternalProgram(ExternalProgram):
return False
class _PythonDependencyBase(_Base):
def __init__(self, python_holder: 'BasicPythonExternalProgram', embed: bool):
self.embed = embed
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
else:
self.major_version = 2
class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
kwargs: T.Dict[str, T.Any], installation: 'BasicPythonExternalProgram',
libpc: bool = False):
if libpc:
mlog.debug(f'Searching for {name!r} via pkgconfig lookup in LIBPC')
else:
mlog.debug(f'Searching for {name!r} via fallback pkgconfig lookup in default paths')
PkgConfigDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))
if libpc and not self.is_found:
mlog.debug(f'"python-{self.version}" could not be found in LIBPC, this is likely due to a relocated python installation')
# The "-embed" version of python.pc was introduced in 3.8, and distutils
# extension linking was changed to be considered a non embed usage. Before
# then, this dependency always uses the embed=True file because that is the
# only one that exists,
#
# On macOS and some Linux distros (Debian) distutils doesn't link extensions
# against libpython, even on 3.7 and below. We call into distutils and
# mirror its behavior. See https://github.com/mesonbuild/meson/issues/4117
if not self.embed and not self.link_libpython and mesonlib.version_compare(self.version, '< 3.8'):
self.link_args = []
class PythonFrameworkDependency(ExtraFrameworkDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
kwargs: T.Dict[str, T.Any], installation: 'BasicPythonExternalProgram'):
ExtraFrameworkDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))
class Python3DependencySystem(SystemDependency):
def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> None:
super().__init__(name, environment, kwargs)

@ -25,11 +25,11 @@ 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 import (DependencyMethods, NotFoundDependency, SystemDependency,
DependencyTypeName, ExternalDependency)
from ..dependencies.base import process_method_kw
from ..dependencies.detect import get_dep_identifier
from ..dependencies.python import BasicPythonExternalProgram
from ..dependencies.python import BasicPythonExternalProgram, PythonFrameworkDependency, PythonPkgConfigDependency, _PythonDependencyBase
from ..environment import detect_cpu_family
from ..interpreter import ExternalProgramHolder, extract_required_kwarg, permitted_dependency_kwargs
from ..interpreter import primitives as P_OBJ
@ -66,69 +66,12 @@ if T.TYPE_CHECKING:
modules: T.List[str]
pure: T.Optional[bool]
_Base = ExternalDependency
else:
_Base = object
mod_kwargs = {'subdir'}
mod_kwargs.update(known_shmod_kwargs)
mod_kwargs -= {'name_prefix', 'name_suffix'}
class _PythonDependencyBase(_Base):
def __init__(self, python_holder: 'BasicPythonExternalProgram', embed: bool):
self.embed = embed
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
else:
self.major_version = 2
class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
kwargs: T.Dict[str, T.Any], installation: 'BasicPythonExternalProgram',
libpc: bool = False):
if libpc:
mlog.debug(f'Searching for {name!r} via pkgconfig lookup in LIBPC')
else:
mlog.debug(f'Searching for {name!r} via fallback pkgconfig lookup in default paths')
PkgConfigDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))
if libpc and not self.is_found:
mlog.debug(f'"python-{self.version}" could not be found in LIBPC, this is likely due to a relocated python installation')
# The "-embed" version of python.pc was introduced in 3.8, and distutils
# extension linking was changed to be considered a non embed usage. Before
# then, this dependency always uses the embed=True file because that is the
# only one that exists,
#
# On macOS and some Linux distros (Debian) distutils doesn't link extensions
# against libpython, even on 3.7 and below. We call into distutils and
# mirror its behavior. See https://github.com/mesonbuild/meson/issues/4117
if not self.embed and not self.link_libpython and mesonlib.version_compare(self.version, '< 3.8'):
self.link_args = []
class PythonFrameworkDependency(ExtraFrameworkDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
kwargs: T.Dict[str, T.Any], installation: 'BasicPythonExternalProgram'):
ExtraFrameworkDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))
class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',

Loading…
Cancel
Save