Skip to content

Commit

Permalink
Special-case PyPy's lib location differences
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Feb 27, 2021
1 parent 826234e commit 78fcbeb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import pathlib
import sys
import sysconfig
from typing import List, Optional

Expand Down Expand Up @@ -41,6 +42,19 @@ def _default_base(*, user: bool) -> str:
return base


def _pypy_home_lib_correct(old: pathlib.Path, new: pathlib.Path) -> bool:
"""Special-case PyPy's purelib and platlib paths in a posix_home scheme.
distutils incorrectly put PyPy packages under ``../site-packages/python``
in the ``posix_home`` scheme, but PyPy devs said they expect the last
directory name to be ``pypy`` instead. So we treat this as a bug fix and
not warn about it.
"""
if old.parent != new.parent:
return False
return old.name == "python" and new.name == "pypy"


def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool:
if old == new:
return False
Expand Down Expand Up @@ -99,6 +113,14 @@ def get_scheme(
# Extra join because distutils can return relative paths.
old_v = pathlib.Path(base, getattr(old, k))
new_v = pathlib.Path(getattr(new, k))
skip_pypy_special_case = (
sys.implementation.name == "pypy"
and home is not None
and k in ("platlib", "purelib")
and _pypy_home_lib_correct(old_v, new_v)
)
if skip_pypy_special_case:
continue
warned.append(_warn_if_mismatch(old_v, new_v, key=f"scheme.{k}"))

if any(warned):
Expand Down

0 comments on commit 78fcbeb

Please sign in to comment.