Skip to content

Commit 00656aa

Browse files
committed
Prevent returning relative paths for a location
Our own override for the distutils implementation has a bug :)
1 parent 41a8442 commit 00656aa

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
@@ -111,15 +111,6 @@ def _fix_abiflags(parts: Tuple[str]) -> Iterator[str]:
111111
yield part
112112

113113

114-
def _default_base(*, user: bool) -> str:
115-
if user:
116-
base = sysconfig.get_config_var("userbase")
117-
else:
118-
base = sysconfig.get_config_var("base")
119-
assert base is not None
120-
return base
121-
122-
123114
@functools.lru_cache(maxsize=None)
124115
def _warn_mismatched(old: pathlib.Path, new: pathlib.Path, *, key: str) -> None:
125116
issue_url = "https://github.com/pypa/pip/issues/10151"
@@ -182,11 +173,9 @@ def get_scheme(
182173
prefix=prefix,
183174
)
184175

185-
base = prefix or home or _default_base(user=user)
186176
warning_contexts = []
187177
for k in SCHEME_KEYS:
188-
# Extra join because distutils can return relative paths.
189-
old_v = pathlib.Path(base, getattr(old, k))
178+
old_v = pathlib.Path(getattr(old, k))
190179
new_v = pathlib.Path(getattr(new, k))
191180

192181
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)