From 81ca47548058d25bbdc6bd4326f1dba0d34eb442 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Sun, 27 Nov 2022 16:49:08 +0100 Subject: [PATCH] Fix isolated environment scripts path on Debian The scripts path was looked up passing explicitly the scheme to be used using "nt" on Windows and "posix_prefix" everywhere else. However, when the isolated build environment is created, packages are installed using the default scheme for the platform. On most platforms this works because normally "nt" and "posix_prefix" are the default schemes. However, Debian customizes sysconfig to use a "posix_local" scheme by default and under this scheme the scripts path does not match the one of the "posix_prefix" scheme. This results in scripts installed as part of the build dependencies not to be found during the build, as reported here https://github.com/mesonbuild/meson-python/issues/109 and here https://bugs.debian.org/1019293. The problem can be solved omitting to specify a scheme when looking up the scripts path. To future proof the path lookup, use the "venv" scheme if available as done in #11598. For uniformity use similar functions as used to lookup the library paths. --- src/pip/_internal/build_env.py | 6 ++---- src/pip/_internal/locations/__init__.py | 4 ++++ src/pip/_internal/locations/_sysconfig.py | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pip/_internal/build_env.py b/src/pip/_internal/build_env.py index e67b868e8f4..4689c3b0a20 100644 --- a/src/pip/_internal/build_env.py +++ b/src/pip/_internal/build_env.py @@ -19,6 +19,7 @@ from pip import __file__ as pip_location from pip._internal.cli.spinners import open_spinner from pip._internal.locations import ( + get_isolated_environment_bin_path, get_isolated_environment_lib_paths, get_platlib, get_purelib, @@ -37,10 +38,7 @@ class _Prefix: def __init__(self, path: str) -> None: self.path = path self.setup = False - self.bin_dir = get_paths( - "nt" if os.name == "nt" else "posix_prefix", - vars={"base": path, "platbase": path}, - )["scripts"] + self.bin_dir = get_isolated_environment_bin_path(path) self.lib_dirs = get_isolated_environment_lib_paths(path) diff --git a/src/pip/_internal/locations/__init__.py b/src/pip/_internal/locations/__init__.py index 516bd607839..67fca2666c7 100644 --- a/src/pip/_internal/locations/__init__.py +++ b/src/pip/_internal/locations/__init__.py @@ -526,3 +526,7 @@ def get_isolated_environment_lib_paths(prefix: str) -> List[str]: _log_context(prefix=prefix) return old_lib_paths + + +def get_isolated_environmemt_bin_path(prefix: str) -> str: + return _sysconfig.get_isolated_environment_bin_path(prefix) diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index 69821572081..2b4a3cbf776 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -220,3 +220,12 @@ def get_isolated_environment_lib_paths(prefix: str) -> typing.Tuple[str, str]: else: paths = sysconfig.get_paths(vars=vars) return (paths["purelib"], paths["platlib"]) + + +def get_isolated_environmemt_bin_path(prefix: str) -> str: + vars = {"base": prefix, "platbase": prefix} + if "venv" in sysconfig.get_scheme_names(): + paths = sysconfig.get_paths(vars=vars, scheme="venv") + else: + paths = sysconfig.get_paths(vars=vars) + retun paths["scripts"]