diff --git a/news/10252.bugfix.rst b/news/10252.bugfix.rst new file mode 100644 index 00000000000..ebeeefd25a8 --- /dev/null +++ b/news/10252.bugfix.rst @@ -0,0 +1,2 @@ +Modify the ``sysconfig.get_preferred_scheme`` function check to be +compatible with CPython 3.10’s alphareleases. diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index 0fc67843f7a..86dbee7e954 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -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: @@ -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" @@ -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: @@ -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