Skip to content

Commit 07c5620

Browse files
authored
Merge pull request #10255 from uranusjr/locations-deb-system-prefix
Work around Debian bug in get_python_lib()
2 parents a31c30f + 0d57982 commit 07c5620

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/pip/_internal/locations/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,29 @@ def get_bin_user() -> str:
298298
return _sysconfig.get_scheme("", user=True).scripts
299299

300300

301+
def _looks_like_deb_system_dist_packages(value: str) -> bool:
302+
"""Check if the value is Debian's APT-controlled dist-packages.
303+
304+
Debian's ``distutils.sysconfig.get_python_lib()`` implementation returns the
305+
default package path controlled by APT, but does not patch ``sysconfig`` to
306+
do the same. This is similar to the bug worked around in ``get_scheme()``,
307+
but here the default is ``deb_system`` instead of ``unix_local``. Ultimately
308+
we can't do anything about this Debian bug, and this detection allows us to
309+
skip the warning when needed.
310+
"""
311+
if not _looks_like_debian_patched():
312+
return False
313+
if value == "/usr/lib/python3/dist-packages":
314+
return True
315+
return False
316+
317+
301318
def get_purelib() -> str:
302319
"""Return the default pure-Python lib location."""
303320
old = _distutils.get_purelib()
304321
new = _sysconfig.get_purelib()
322+
if _looks_like_deb_system_dist_packages(old):
323+
return old
305324
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="purelib"):
306325
_log_context()
307326
return old
@@ -311,6 +330,8 @@ def get_platlib() -> str:
311330
"""Return the default platform-shared lib location."""
312331
old = _distutils.get_platlib()
313332
new = _sysconfig.get_platlib()
333+
if _looks_like_deb_system_dist_packages(old):
334+
return old
314335
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="platlib"):
315336
_log_context()
316337
return old

0 commit comments

Comments
 (0)