Skip to content

Commit ca4aa12

Browse files
committed
Use Python 3.10 sysconfig.get_preferred_scheme()
This function is introduced to 3.10 to do precisely what we want, so let's use it if possible.
1 parent ad3d498 commit ca4aa12

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/pip/_internal/locations/_sysconfig.py

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

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

27+
_HAS_PREFERRED_SCHEME_API = sys.version_info >= (3, 10)
28+
2729

2830
def _infer_prefix() -> str:
2931
"""Try to find a prefix scheme for the current platform.
@@ -39,6 +41,8 @@ def _infer_prefix() -> str:
3941
4042
If none of the above works, fall back to ``posix_prefix``.
4143
"""
44+
if _HAS_PREFERRED_SCHEME_API:
45+
return sysconfig.get_preferred_scheme("prefix")
4246
os_framework_global = is_osx_framework() and not running_under_virtualenv()
4347
if os_framework_global and "osx_framework_library" in _AVAILABLE_SCHEMES:
4448
return "osx_framework_library"
@@ -57,6 +61,8 @@ def _infer_prefix() -> str:
5761

5862
def _infer_user() -> str:
5963
"""Try to find a user scheme for the current platform."""
64+
if _HAS_PREFERRED_SCHEME_API:
65+
return sysconfig.get_preferred_scheme("user")
6066
if is_osx_framework() and not running_under_virtualenv():
6167
suffixed = "osx_framework_user"
6268
else:
@@ -70,6 +76,8 @@ def _infer_user() -> str:
7076

7177
def _infer_home() -> str:
7278
"""Try to find a home for the current platform."""
79+
if _HAS_PREFERRED_SCHEME_API:
80+
return sysconfig.get_preferred_scheme("home")
7381
suffixed = f"{os.name}_home"
7482
if suffixed in _AVAILABLE_SCHEMES:
7583
return suffixed

0 commit comments

Comments
 (0)