Skip to content

Commit

Permalink
Prevent returning relative paths for a location
Browse files Browse the repository at this point in the history
Our own override for the distutils implementation has a bug :)
  • Loading branch information
uranusjr committed Aug 6, 2021
1 parent 41a8442 commit 00656aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
13 changes: 1 addition & 12 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 8 additions & 5 deletions src/pip/_internal/locations/_distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}",
Expand All @@ -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

Expand Down

0 comments on commit 00656aa

Please sign in to comment.