From 09055be4bd31591a010c340d3b7fc50a1165f16c 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. --- news/11623.bugfix.rst | 1 + src/pip/_internal/build_env.py | 6 ++---- src/pip/_internal/locations/__init__.py | 5 +++++ src/pip/_internal/locations/_sysconfig.py | 9 +++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 news/11623.bugfix.rst diff --git a/news/11623.bugfix.rst b/news/11623.bugfix.rst new file mode 100644 index 00000000000..45b8fe1928f --- /dev/null +++ b/news/11623.bugfix.rst @@ -0,0 +1 @@ +Fix scripts path in isolated build environment on Debian. 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..547bb803ce2 100644 --- a/src/pip/_internal/locations/__init__.py +++ b/src/pip/_internal/locations/__init__.py @@ -28,6 +28,7 @@ "get_major_minor_version", "get_platlib", "get_isolated_environment_lib_paths", + "get_isolated_environment_bin_path", "get_purelib", "get_scheme", "get_src_prefix", @@ -526,3 +527,7 @@ def get_isolated_environment_lib_paths(prefix: str) -> List[str]: _log_context(prefix=prefix) return old_lib_paths + + +def get_isolated_environment_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..411045146ef 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_environment_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) + return paths["scripts"]