aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Laíns <lains@riseup.net>2021-09-21 19:52:55 +0100
committerXavier Claessens <xclaesse@gmail.com>2021-09-29 08:54:05 -0400
commit05b5a1e56fe8f5400b65d0d69680cc6531fe74f8 (patch)
treebd11f7fbdd70b515a46bd553fdde78161889368d
parent6ef3946ea8858886905a6668a595ffc48520eace (diff)
downloadmeson-05b5a1e56fe8f5400b65d0d69680cc6531fe74f8.zip
meson-05b5a1e56fe8f5400b65d0d69680cc6531fe74f8.tar.gz
meson-05b5a1e56fe8f5400b65d0d69680cc6531fe74f8.tar.bz2
modules: python: better handling of the Python paths for Debian
Hardcoding the name is fragile, and enabling it based on the existence of /etc/debian_version (as the is_debianlike helper does) will result in incorrect paths if the Python binary is not provided by Debian. Using the deb_system distuils scheme instead makes sure we use the install path from the current interpreter, which Debian could change between releases, and gives us the correct value on Python installations that are not provided by Debian (eg. deadsnakes, Github Action Python, etc.) Do notice, though, that there is still no guarantee that these are the correct paths, as they assume all schemes paths have the install prefix as a base, see #9284. Signed-off-by: Filipe Laíns <lains@riseup.net>
-rw-r--r--mesonbuild/modules/python.py43
1 files changed, 35 insertions, 8 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 57cea91..2d5eaea 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -276,11 +276,43 @@ def python_factory(env: 'Environment', for_machine: 'MachineChoice',
INTROSPECT_COMMAND = '''\
+import os.path
import sysconfig
import json
import sys
-
-install_paths = sysconfig.get_paths(vars={'base': '', 'platbase': '', 'installed_base': ''})
+import distutils.command.install
+
+def get_distutils_paths(scheme=None, prefix=None):
+ import distutils.dist
+ distribution = distutils.dist.Distribution()
+ install_cmd = distribution.get_command_obj('install')
+ if prefix is not None:
+ install_cmd.prefix = prefix
+ if scheme:
+ install_cmd.select_scheme(scheme)
+ install_cmd.finalize_options()
+ return {
+ 'data': install_cmd.install_data,
+ 'include': os.path.dirname(install_cmd.install_headers),
+ 'platlib': install_cmd.install_platlib,
+ 'purelib': install_cmd.install_purelib,
+ 'scripts': install_cmd.install_scripts,
+ }
+
+# On Debian derivatives, the Python interpreter shipped by the distribution uses
+# a custom install scheme, deb_system, for the system install, and changes the
+# default scheme to a custom one pointing to /usr/local and replacing
+# site-packages with dist-packages.
+# See https://github.com/mesonbuild/meson/issues/8739.
+# XXX: We should be using sysconfig, but Debian only patches distutils.
+
+if 'deb_system' in distutils.command.install.INSTALL_SCHEMES:
+ paths = get_distutils_paths(scheme='deb_system')
+ install_paths = get_distutils_paths(scheme='deb_system', prefix='')
+else:
+ paths = sysconfig.get_paths()
+ empty_vars = {'base': '', 'platbase': '', 'installed_base': ''}
+ install_paths = sysconfig.get_paths(vars=empty_vars)
def links_against_libpython():
from distutils.core import Distribution, Extension
@@ -290,7 +322,7 @@ def links_against_libpython():
print(json.dumps({
'variables': sysconfig.get_config_vars(),
- 'paths': sysconfig.get_paths(),
+ 'paths': paths,
'install_paths': install_paths,
'sys_paths': sys.path,
'version': sysconfig.get_python_version(),
@@ -373,14 +405,9 @@ class PythonExternalProgram(ExternalProgram):
sys_paths = self.info['sys_paths']
rel_path = self.info['install_paths'][key][1:]
if not any(p.endswith(rel_path) for p in sys_paths if not p.startswith(user_dir)):
- # On Debian derivatives sysconfig install path is broken and is not
- # included in the locations python actually lookup.
- # See https://github.com/mesonbuild/meson/issues/8739.
mlog.warning('Broken python installation detected. Python files',
'installed by Meson might not be found by python interpreter.',
once=True)
- if mesonlib.is_debianlike():
- rel_path = 'lib/python3/dist-packages'
return rel_path