aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/python.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-10-22 08:22:36 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2021-11-09 18:49:03 +0200
commit898bf6e518692fb9d895470438e04568cd670d58 (patch)
tree5e79ea7989430d6718db4cd6c29d4f5db95199ff /mesonbuild/modules/python.py
parentf48d75dcaecec5a441ec745388c08c73201ed46c (diff)
downloadmeson-898bf6e518692fb9d895470438e04568cd670d58.zip
meson-898bf6e518692fb9d895470438e04568cd670d58.tar.gz
meson-898bf6e518692fb9d895470438e04568cd670d58.tar.bz2
python: Better detect when install path is not in sys.path
Using pathlib ensure propre platform specific path handling, such as case sensitivity.
Diffstat (limited to 'mesonbuild/modules/python.py')
-rw-r--r--mesonbuild/modules/python.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 18fe926..b650f56 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -399,16 +399,19 @@ class PythonExternalProgram(ExternalProgram):
return False
def _get_path(self, state: T.Optional['ModuleState'], key: str) -> None:
- if state:
- value = state.get_option(f'{key}dir', module='python')
- if value:
- return value
- 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)):
- mlog.warning('Broken python installation detected. Python files',
- 'installed by Meson might not be found by python interpreter.\n',
+ if not state:
+ # This happens only from run_project_tests.py
+ return rel_path
+ value = state.get_option(f'{key}dir', module='python')
+ if value:
+ return value
+ # Use python's path relative to prefix, and warn if that's not a location
+ # python will lookup for modules.
+ abs_path = Path(state.get_option('prefix'), rel_path)
+ sys_paths = [Path(i) for i in self.info['sys_paths']]
+ if abs_path not in sys_paths:
+ mlog.warning('Python files installed by Meson might not be found by python interpreter.\n',
f'This warning can be avoided by setting "python.{key}dir" option.',
once=True)
return rel_path