aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-02-13 20:17:22 -0500
committerDylan Baker <dylan@pnwbakers.com>2023-02-22 10:32:09 -0800
commit29592481bccebe54619b4a063a66ac4038e894d6 (patch)
treee23f826656b74668865b8b8e7067a7ea11034e7a
parent9fa4da3ba94cd1bd41917c93742396bd3f94330f (diff)
downloadmeson-29592481bccebe54619b4a063a66ac4038e894d6.zip
meson-29592481bccebe54619b4a063a66ac4038e894d6.tar.gz
meson-29592481bccebe54619b4a063a66ac4038e894d6.tar.bz2
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.
-rw-r--r--mesonbuild/dependencies/python.py61
-rw-r--r--mesonbuild/modules/python.py61
2 files changed, 62 insertions, 60 deletions
diff --git a/mesonbuild/dependencies/python.py b/mesonbuild/dependencies/python.py
index f3a8444..2fc34c1 100644
--- a/mesonbuild/dependencies/python.py
+++ b/mesonbuild/dependencies/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)
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index effa669..dd3a101 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -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',