From 00656aae146891ff1d1437e6a9105500d501f00d Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 5 Aug 2021 17:03:50 +0800 Subject: [PATCH] Prevent returning relative paths for a location Our own override for the distutils implementation has a bug :) --- src/pip/_internal/locations/__init__.py | 13 +------------ src/pip/_internal/locations/_distutils.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/pip/_internal/locations/__init__.py b/src/pip/_internal/locations/__init__.py index 21b08ebf07f..0d49cf23a93 100644 --- a/src/pip/_internal/locations/__init__.py +++ b/src/pip/_internal/locations/__init__.py @@ -111,15 +111,6 @@ def _fix_abiflags(parts: Tuple[str]) -> Iterator[str]: yield part -def _default_base(*, user: bool) -> str: - if user: - base = sysconfig.get_config_var("userbase") - else: - base = sysconfig.get_config_var("base") - assert base is not None - return base - - @functools.lru_cache(maxsize=None) def _warn_mismatched(old: pathlib.Path, new: pathlib.Path, *, key: str) -> None: issue_url = "https://github.com/pypa/pip/issues/10151" @@ -182,11 +173,9 @@ def get_scheme( prefix=prefix, ) - base = prefix or home or _default_base(user=user) warning_contexts = [] for k in SCHEME_KEYS: - # Extra join because distutils can return relative paths. - old_v = pathlib.Path(base, getattr(old, k)) + old_v = pathlib.Path(getattr(old, k)) new_v = pathlib.Path(getattr(new, k)) if old_v == new_v: diff --git a/src/pip/_internal/locations/_distutils.py b/src/pip/_internal/locations/_distutils.py index 6d7c09dd0fb..8f2c2f1ef60 100644 --- a/src/pip/_internal/locations/_distutils.py +++ b/src/pip/_internal/locations/_distutils.py @@ -81,8 +81,14 @@ def distutils_scheme( scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib)) if running_under_virtualenv(): + if home: + prefix = home + elif user: + prefix = i.install_userbase # type: ignore + else: + prefix = i.prefix scheme["headers"] = os.path.join( - i.prefix, + prefix, "include", "site", f"python{get_major_minor_version()}", @@ -91,10 +97,7 @@ def distutils_scheme( if root is not None: path_no_drive = os.path.splitdrive(os.path.abspath(scheme["headers"]))[1] - scheme["headers"] = os.path.join( - root, - path_no_drive[1:], - ) + scheme["headers"] = os.path.join(root, path_no_drive[1:]) return scheme