Skip to content

Commit

Permalink
Switch install scheme backend to sysconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Aug 13, 2021
1 parent b9f8295 commit 0d6c892
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

_PLATLIBDIR: str = getattr(sys, "platlibdir", "lib")

_USE_SYSCONFIG = sys.version_info >= (3, 10)


def _looks_like_bpo_44860() -> bool:
"""The resolution to bpo-44860 will change this incorrect platlib.
Expand Down Expand Up @@ -190,15 +192,18 @@ def get_scheme(
isolated: bool = False,
prefix: Optional[str] = None,
) -> Scheme:
old = _distutils.get_scheme(
new = _sysconfig.get_scheme(
dist_name,
user=user,
home=home,
root=root,
isolated=isolated,
prefix=prefix,
)
new = _sysconfig.get_scheme(
if _USE_SYSCONFIG:
return new

old = _distutils.get_scheme(
dist_name,
user=user,
home=home,
Expand Down Expand Up @@ -333,8 +338,11 @@ def get_scheme(


def get_bin_prefix() -> str:
old = _distutils.get_bin_prefix()
new = _sysconfig.get_bin_prefix()
if _USE_SYSCONFIG:
return new

old = _distutils.get_bin_prefix()
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_prefix"):
_log_context()
return old
Expand Down Expand Up @@ -363,8 +371,11 @@ def _looks_like_deb_system_dist_packages(value: str) -> bool:

def get_purelib() -> str:
"""Return the default pure-Python lib location."""
old = _distutils.get_purelib()
new = _sysconfig.get_purelib()
if _USE_SYSCONFIG:
return new

old = _distutils.get_purelib()
if _looks_like_deb_system_dist_packages(old):
return old
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="purelib"):
Expand All @@ -374,19 +385,32 @@ def get_purelib() -> str:

def get_platlib() -> str:
"""Return the default platform-shared lib location."""
old = _distutils.get_platlib()
new = _sysconfig.get_platlib()
if _USE_SYSCONFIG:
return new

old = _distutils.get_platlib()
if _looks_like_deb_system_dist_packages(old):
return old
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="platlib"):
_log_context()
return old


def _deduplicated(v1: str, v2: str) -> List[str]:
"""Deduplicate values from a list."""
if v1 == v2:
return [v1]
return [v1, v2]


def get_prefixed_libs(prefix: str) -> List[str]:
"""Return the lib locations under ``prefix``."""
old_pure, old_plat = _distutils.get_prefixed_libs(prefix)
new_pure, new_plat = _sysconfig.get_prefixed_libs(prefix)
if _USE_SYSCONFIG:
return _deduplicated(new_pure, new_plat)

old_pure, old_plat = _distutils.get_prefixed_libs(prefix)

warned = [
_warn_if_mismatch(
Expand All @@ -403,6 +427,4 @@ def get_prefixed_libs(prefix: str) -> List[str]:
if any(warned):
_log_context(prefix=prefix)

if old_pure == old_plat:
return [old_pure]
return [old_pure, old_plat]
return _deduplicated(old_pure, old_plat)

0 comments on commit 0d6c892

Please sign in to comment.