Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_preferred_scheme detection for CPython 3.10 alpha #10252

Merged
merged 5 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
uranusjr marked this conversation as resolved.
Show resolved Hide resolved
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