Skip to content

Commit 0b95378

Browse files
authored
Merge pull request #10257 from uranusjr/locations-relative-prefix
2 parents 8ed2178 + a3b186a commit 0b95378

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
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: 15 additions & 9 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

@@ -135,17 +138,20 @@ def get_scheme(
135138

136139

137140
def get_bin_prefix() -> str:
141+
# XXX: In old virtualenv versions, sys.prefix can contain '..' components,
142+
# so we need to call normpath to eliminate them.
143+
prefix = os.path.normpath(sys.prefix)
138144
if WINDOWS:
139-
bin_py = os.path.join(sys.prefix, "Scripts")
145+
bin_py = os.path.join(prefix, "Scripts")
140146
# buildout uses 'bin' on Windows too?
141147
if not os.path.exists(bin_py):
142-
bin_py = os.path.join(sys.prefix, "bin")
148+
bin_py = os.path.join(prefix, "bin")
143149
return bin_py
144150
# Forcing to use /usr/local/bin for standard macOS framework installs
145151
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
146-
if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
152+
if sys.platform[:6] == "darwin" and prefix[:16] == "/System/Library/":
147153
return "/usr/local/bin"
148-
return os.path.join(sys.prefix, "bin")
154+
return os.path.join(prefix, "bin")
149155

150156

151157
def get_purelib() -> str:

0 commit comments

Comments
 (0)