Skip to content

Commit 87aee20

Browse files
SylvainDeSylvain Desodturanusjr
authored
Fix get_preferred_scheme detection for CPython 3.10 alpha
Co-authored-by: Sylvain Desodt <[email protected]> Co-authored-by: Tzu-ping Chung <[email protected]>
1 parent 6468908 commit 87aee20

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

news/10252.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Modify the ``sysconfig.get_preferred_scheme`` function check to be
2+
compatible with CPython 3.10’s alphareleases.

src/pip/_internal/locations/_sysconfig.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())
2626

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

2929

3030
def _infer_prefix() -> str:
@@ -41,8 +41,8 @@ def _infer_prefix() -> str:
4141
4242
If none of the above works, fall back to ``posix_prefix``.
4343
"""
44-
if _HAS_PREFERRED_SCHEME_API:
45-
return sysconfig.get_preferred_scheme("prefix") # type: ignore
44+
if _PREFERRED_SCHEME_API:
45+
return _PREFERRED_SCHEME_API("prefix")
4646
os_framework_global = is_osx_framework() and not running_under_virtualenv()
4747
if os_framework_global and "osx_framework_library" in _AVAILABLE_SCHEMES:
4848
return "osx_framework_library"
@@ -61,8 +61,8 @@ def _infer_prefix() -> str:
6161

6262
def _infer_user() -> str:
6363
"""Try to find a user scheme for the current platform."""
64-
if _HAS_PREFERRED_SCHEME_API:
65-
return sysconfig.get_preferred_scheme("user") # type: ignore
64+
if _PREFERRED_SCHEME_API:
65+
return _PREFERRED_SCHEME_API("user")
6666
if is_osx_framework() and not running_under_virtualenv():
6767
suffixed = "osx_framework_user"
6868
else:
@@ -76,8 +76,8 @@ def _infer_user() -> str:
7676

7777
def _infer_home() -> str:
7878
"""Try to find a home for the current platform."""
79-
if _HAS_PREFERRED_SCHEME_API:
80-
return sysconfig.get_preferred_scheme("home") # type: ignore
79+
if _PREFERRED_SCHEME_API:
80+
return _PREFERRED_SCHEME_API("home")
8181
suffixed = f"{os.name}_home"
8282
if suffixed in _AVAILABLE_SCHEMES:
8383
return suffixed

0 commit comments

Comments
 (0)