Skip to content

Commit

Permalink
Merge pull request #10145 from uranusjr/py310-sysconfig-api
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Jul 12, 2021
2 parents bd5ac26 + 8349b9a commit 646aba8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())

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


def _infer_prefix() -> str:
"""Try to find a prefix scheme for the current platform.
Expand All @@ -39,6 +41,8 @@ def _infer_prefix() -> str:
If none of the above works, fall back to ``posix_prefix``.
"""
if _HAS_PREFERRED_SCHEME_API:
return sysconfig.get_preferred_scheme("prefix") # type: ignore
os_framework_global = is_osx_framework() and not running_under_virtualenv()
if os_framework_global and "osx_framework_library" in _AVAILABLE_SCHEMES:
return "osx_framework_library"
Expand All @@ -57,6 +61,8 @@ def _infer_prefix() -> str:

def _infer_user() -> str:
"""Try to find a user scheme for the current platform."""
if _HAS_PREFERRED_SCHEME_API:
return sysconfig.get_preferred_scheme("user") # type: ignore
if is_osx_framework() and not running_under_virtualenv():
suffixed = "osx_framework_user"
else:
Expand All @@ -70,6 +76,8 @@ def _infer_user() -> str:

def _infer_home() -> str:
"""Try to find a home for the current platform."""
if _HAS_PREFERRED_SCHEME_API:
return sysconfig.get_preferred_scheme("home") # type: ignore
suffixed = f"{os.name}_home"
if suffixed in _AVAILABLE_SCHEMES:
return suffixed
Expand Down

0 comments on commit 646aba8

Please sign in to comment.