Skip to content

Commit

Permalink
Fix get_preferred_scheme detection for CPython 3.10 alpha
Browse files Browse the repository at this point in the history
Co-authored-by: Sylvain Desodt <sylvain.desodt@faurecia.com>
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
  • Loading branch information
3 people committed Aug 6, 2021
1 parent f7d912a commit 1ac90bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions news/10252.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Modify the ``sysconfig.get_preferred_scheme`` function check to be
compatible with CPython 3.10’s alphareleases.
14 changes: 7 additions & 7 deletions src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())

_HAS_PREFERRED_SCHEME_API = sys.version_info >= (3, 10)
_PREFERRED_SCHEME_API = getattr(sysconfig, "get_preferred_scheme", None)


def _infer_prefix() -> str:
Expand All @@ -41,8 +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
if _PREFERRED_SCHEME_API:
return _PREFERRED_SCHEME_API("prefix")
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 @@ -61,8 +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 _PREFERRED_SCHEME_API:
return _PREFERRED_SCHEME_API("user")
if is_osx_framework() and not running_under_virtualenv():
suffixed = "osx_framework_user"
else:
Expand All @@ -76,8 +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
if _PREFERRED_SCHEME_API:
return _PREFERRED_SCHEME_API("home")
suffixed = f"{os.name}_home"
if suffixed in _AVAILABLE_SCHEMES:
return suffixed
Expand Down

0 comments on commit 1ac90bb

Please sign in to comment.