Skip to content

Commit fcadb92

Browse files
committed
Prevent returning relative paths for a location
Our own override for the distutils implementation has a bug :)
1 parent 6468908 commit fcadb92

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/pip/_internal/locations/__init__.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ def _fix_abiflags(parts: Tuple[str]) -> Iterator[str]:
9090
yield part
9191

9292

93-
def _default_base(*, user: bool) -> str:
94-
if user:
95-
base = sysconfig.get_config_var("userbase")
96-
else:
97-
base = sysconfig.get_config_var("base")
98-
assert base is not None
99-
return base
100-
101-
10293
@functools.lru_cache(maxsize=None)
10394
def _warn_mismatched(old: pathlib.Path, new: pathlib.Path, *, key: str) -> None:
10495
issue_url = "https://github.com/pypa/pip/issues/10151"
@@ -161,11 +152,9 @@ def get_scheme(
161152
prefix=prefix,
162153
)
163154

164-
base = prefix or home or _default_base(user=user)
165155
warning_contexts = []
166156
for k in SCHEME_KEYS:
167-
# Extra join because distutils can return relative paths.
168-
old_v = pathlib.Path(base, getattr(old, k))
157+
old_v = pathlib.Path(getattr(old, k))
169158
new_v = pathlib.Path(getattr(new, k))
170159

171160
if old_v == new_v:

src/pip/_internal/locations/_distutils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,14 @@ def distutils_scheme(
8181
scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))
8282

8383
if running_under_virtualenv():
84+
if home:
85+
prefix = home
86+
elif user:
87+
prefix = i.install_userbase # type: ignore
88+
else:
89+
prefix = i.prefix
8490
scheme["headers"] = os.path.join(
85-
i.prefix,
91+
prefix,
8692
"include",
8793
"site",
8894
f"python{get_major_minor_version()}",
@@ -91,10 +97,7 @@ def distutils_scheme(
9197

9298
if root is not None:
9399
path_no_drive = os.path.splitdrive(os.path.abspath(scheme["headers"]))[1]
94-
scheme["headers"] = os.path.join(
95-
root,
96-
path_no_drive[1:],
97-
)
100+
scheme["headers"] = os.path.join(root, path_no_drive[1:])
98101

99102
return scheme
100103

0 commit comments

Comments
 (0)