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.
@@ -24,6 +24,8 @@ logger = logging.getLogger(__name__)
_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())
+_HAS_PREFERRED_SCHEME_API = sys.version_info >= (3, 10)
+
def _infer_prefix() -> str:
"""Try to find a prefix scheme for the current platform.
@@ -39,6 +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")
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"
@@ -57,6 +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")
if is_osx_framework() and not running_under_virtualenv():
suffixed = "osx_framework_user"
else:
@@ -70,6 +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")
suffixed = f"{os.name}_home"
if suffixed in _AVAILABLE_SCHEMES:
return suffixed
