Skip to content

Commit b4c7367

Browse files
committed
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 mesonbuild/meson-python#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 pypa#11598. For uniformity use similar functions as used to lookup the library paths.
1 parent 5f3f592 commit b4c7367

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

news/11623.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix scripts path in isolated build environment on Debian.

src/pip/_internal/build_env.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99
import textwrap
1010
from collections import OrderedDict
11-
from sysconfig import get_paths
1211
from types import TracebackType
1312
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type
1413

@@ -19,6 +18,7 @@
1918
from pip import __file__ as pip_location
2019
from pip._internal.cli.spinners import open_spinner
2120
from pip._internal.locations import (
21+
get_isolated_environment_bin_path,
2222
get_isolated_environment_lib_paths,
2323
get_platlib,
2424
get_purelib,
@@ -37,10 +37,7 @@ class _Prefix:
3737
def __init__(self, path: str) -> None:
3838
self.path = path
3939
self.setup = False
40-
self.bin_dir = get_paths(
41-
"nt" if os.name == "nt" else "posix_prefix",
42-
vars={"base": path, "platbase": path},
43-
)["scripts"]
40+
self.bin_dir = get_isolated_environment_bin_path(path)
4441
self.lib_dirs = get_isolated_environment_lib_paths(path)
4542

4643

src/pip/_internal/locations/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"get_major_minor_version",
2929
"get_platlib",
3030
"get_isolated_environment_lib_paths",
31+
"get_isolated_environment_bin_path",
3132
"get_purelib",
3233
"get_scheme",
3334
"get_src_prefix",
@@ -526,3 +527,7 @@ def get_isolated_environment_lib_paths(prefix: str) -> List[str]:
526527
_log_context(prefix=prefix)
527528

528529
return old_lib_paths
530+
531+
532+
def get_isolated_environment_bin_path(prefix: str) -> str:
533+
return _sysconfig.get_isolated_environment_bin_path(prefix)

src/pip/_internal/locations/_sysconfig.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,18 @@ def get_platlib() -> str:
213213
return sysconfig.get_paths()["platlib"]
214214

215215

216-
def get_isolated_environment_lib_paths(prefix: str) -> typing.Tuple[str, str]:
216+
def _get_isolated_environment_paths(prefix: str) -> typing.Dict[str, str]:
217217
vars = {"base": prefix, "platbase": prefix}
218218
if "venv" in sysconfig.get_scheme_names():
219-
paths = sysconfig.get_paths(vars=vars, scheme="venv")
220-
else:
221-
paths = sysconfig.get_paths(vars=vars)
219+
return sysconfig.get_paths(vars=vars, scheme="venv")
220+
return sysconfig.get_paths(vars=vars)
221+
222+
223+
def get_isolated_environment_lib_paths(prefix: str) -> typing.Tuple[str, str]:
224+
paths = _get_isolated_environment_paths(prefix)
222225
return (paths["purelib"], paths["platlib"])
226+
227+
228+
def get_isolated_environment_bin_path(prefix: str) -> str:
229+
paths = _get_isolated_environment_paths(prefix)
230+
return paths["scripts"]

0 commit comments

Comments
 (0)