Skip to content

Commit

Permalink
Fix isolated environment scripts path on Debian
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dnicolodi committed Nov 27, 2022
1 parent 5f3f592 commit 09055be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/11623.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix scripts path in isolated build environment on Debian.
6 changes: 2 additions & 4 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)


Expand Down
5 changes: 5 additions & 0 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
9 changes: 9 additions & 0 deletions src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 09055be

Please sign in to comment.