python: Workaround broken install path

0.59
Xavier Claessens 3 years ago committed by Nirbheek Chauhan
parent 72fac1f25e
commit 142b741384
  1. 23
      mesonbuild/modules/python.py
  2. 5
      run_project_tests.py

@ -272,6 +272,7 @@ print (json.dumps ({
'variables': sysconfig.get_config_vars(), 'variables': sysconfig.get_config_vars(),
'paths': sysconfig.get_paths(), 'paths': sysconfig.get_paths(),
'install_paths': install_paths, 'install_paths': install_paths,
'sys_paths': sys.path,
'version': sysconfig.get_python_version(), 'version': sysconfig.get_python_version(),
'platform': sysconfig.get_platform(), 'platform': sysconfig.get_platform(),
'is_pypy': '__pypy__' in sys.builtin_module_names, 'is_pypy': '__pypy__' in sys.builtin_module_names,
@ -334,10 +335,27 @@ class PythonExternalProgram(ExternalProgram):
variables = info['variables'] variables = info['variables']
info['suffix'] = variables.get('EXT_SUFFIX') or variables.get('SO') or variables.get('.so') info['suffix'] = variables.get('EXT_SUFFIX') or variables.get('SO') or variables.get('.so')
self.info = T.cast('PythonIntrospectionDict', info) self.info = T.cast('PythonIntrospectionDict', info)
self.platlib = self._get_path('platlib')
self.purelib = self._get_path('purelib')
return True return True
else: else:
return False return False
def _get_path(self, key: str) -> None:
user_dir = str(Path.home())
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
class PythonInstallation(ExternalProgramHolder): class PythonInstallation(ExternalProgramHolder):
def __init__(self, python, interpreter): def __init__(self, python, interpreter):
@ -347,9 +365,8 @@ class PythonInstallation(ExternalProgramHolder):
self.variables = info['variables'] self.variables = info['variables']
self.suffix = info['suffix'] self.suffix = info['suffix']
self.paths = info['paths'] self.paths = info['paths']
install_paths = info['install_paths'] self.platlib_install_path = os.path.join(prefix, python.platlib)
self.platlib_install_path = os.path.join(prefix, install_paths['platlib'][1:]) self.purelib_install_path = os.path.join(prefix, python.purelib)
self.purelib_install_path = os.path.join(prefix, install_paths['purelib'][1:])
self.version = info['version'] self.version = info['version']
self.platform = info['platform'] self.platform = info['platform']
self.is_pypy = info['is_pypy'] self.is_pypy = info['is_pypy']

@ -147,7 +147,6 @@ class InstalledFile:
(env.machines.host.is_windows() and compiler in {'pgi', 'dmd', 'ldc'})): (env.machines.host.is_windows() and compiler in {'pgi', 'dmd', 'ldc'})):
canonical_compiler = 'msvc' canonical_compiler = 'msvc'
python_paths = python.info['install_paths']
python_suffix = python.info['suffix'] python_suffix = python.info['suffix']
has_pdb = False has_pdb = False
@ -170,8 +169,8 @@ class InstalledFile:
# Handle the different types # Handle the different types
if self.typ in {'py_implib', 'python_lib', 'python_file'}: if self.typ in {'py_implib', 'python_lib', 'python_file'}:
val = p.as_posix() val = p.as_posix()
val = val.replace('@PYTHON_PLATLIB@', python_paths['platlib']) val = val.replace('@PYTHON_PLATLIB@', python.platlib)
val = val.replace('@PYTHON_PURELIB@', python_paths['purelib']) val = val.replace('@PYTHON_PURELIB@', python.purelib)
p = Path(val) p = Path(val)
if self.typ == 'python_file': if self.typ == 'python_file':
return p return p

Loading…
Cancel
Save