15
15
16
16
17
17
# Notes on _infer_* functions.
18
- # Unfortunately ``_get_default_scheme ()`` is private , so there's no way to
19
- # ask things like "what is the '_prefix' scheme on this platform". These
18
+ # Unfortunately ``get_default_scheme ()`` didn't exist before 3.10 , so there's no
19
+ # way to ask things like "what is the '_prefix' scheme on this platform". These
20
20
# functions try to answer that with some heuristics while accounting for ad-hoc
21
21
# platforms not covered by CPython's default sysconfig implementation. If the
22
22
# ad-hoc implementation does not fully implement sysconfig, we'll fall back to
27
27
_PREFERRED_SCHEME_API = getattr (sysconfig , "get_preferred_scheme" , None )
28
28
29
29
30
+ def _should_use_osx_framework_prefix () -> bool :
31
+ """Check for Apple's ``osx_framework_library`` scheme.
32
+
33
+ Python distributed by Apple's Command Line Tools has this special scheme
34
+ that's used when:
35
+
36
+ * This is a framework build.
37
+ * We are installing into the system prefix.
38
+
39
+ This does not account for ``pip install --prefix`` (also means we're not
40
+ installing to the system prefix), which should use ``posix_prefix``, but
41
+ logic here means ``_infer_prefix()`` outputs ``osx_framework_library``. But
42
+ since ``prefix`` is not available for ``sysconfig.get_default_scheme()``,
43
+ which is the stdlib replacement for ``_infer_prefix()``, presumably Apple
44
+ wouldn't be able to magically switch between ``osx_framework_library`` and
45
+ ``posix_prefix``. ``_infer_prefix()`` returning ``osx_framework_library``
46
+ means its behavior is consistent whether we use the stdlib implementation
47
+ or our own, and we deal with this special case in ``get_scheme()`` instead.
48
+ """
49
+ return (
50
+ "osx_framework_library" in _AVAILABLE_SCHEMES
51
+ and not running_under_virtualenv ()
52
+ and is_osx_framework ()
53
+ )
54
+
55
+
30
56
def _infer_prefix () -> str :
31
57
"""Try to find a prefix scheme for the current platform.
32
58
@@ -43,8 +69,7 @@ def _infer_prefix() -> str:
43
69
"""
44
70
if _PREFERRED_SCHEME_API :
45
71
return _PREFERRED_SCHEME_API ("prefix" )
46
- os_framework_global = is_osx_framework () and not running_under_virtualenv ()
47
- if os_framework_global and "osx_framework_library" in _AVAILABLE_SCHEMES :
72
+ if _should_use_osx_framework_prefix ():
48
73
return "osx_framework_library"
49
74
implementation_suffixed = f"{ sys .implementation .name } _{ os .name } "
50
75
if implementation_suffixed in _AVAILABLE_SCHEMES :
@@ -130,6 +155,12 @@ def get_scheme(
130
155
else :
131
156
scheme_name = _infer_prefix ()
132
157
158
+ # Special case: When installing into a custom prefix, use posix_prefix
159
+ # instead of osx_framework_library. See _should_use_osx_framework_prefix()
160
+ # docstring for details.
161
+ if prefix is not None and scheme_name == "osx_framework_library" :
162
+ scheme_name = "posix_prefix"
163
+
133
164
if home is not None :
134
165
variables = {k : home for k in _HOME_KEYS }
135
166
elif prefix is not None :
0 commit comments