1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

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.
This commit is contained in:
Daniele Nicolodi 2022-11-27 16:49:08 +01:00
parent 8dbb8b9bbe
commit da478818c1
4 changed files with 20 additions and 9 deletions

1
news/11623.bugfix.rst Normal file
View file

@ -0,0 +1 @@
Fix scripts path in isolated build environment on Debian.

View file

@ -8,7 +8,6 @@ import site
import sys
import textwrap
from collections import OrderedDict
from sysconfig import get_paths
from types import TracebackType
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type
@ -19,6 +18,7 @@ from pip._vendor.packaging.version import Version
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 +37,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)

View file

@ -28,6 +28,7 @@ __all__ = [
"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)

View file

@ -213,10 +213,18 @@ def get_platlib() -> str:
return sysconfig.get_paths()["platlib"]
def get_isolated_environment_lib_paths(prefix: str) -> typing.Tuple[str, str]:
def _get_isolated_environment_paths(prefix: str) -> typing.Dict[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 sysconfig.get_paths(vars=vars, scheme="venv")
return sysconfig.get_paths(vars=vars)
def get_isolated_environment_lib_paths(prefix: str) -> typing.Tuple[str, str]:
paths = _get_isolated_environment_paths(prefix)
return (paths["purelib"], paths["platlib"])
def get_isolated_environment_bin_path(prefix: str) -> str:
paths = _get_isolated_environment_paths(prefix)
return paths["scripts"]