Skip to content

Commit 8ed2178

Browse files
authored
Merge pull request #10256 from osx-framework-not-default-prefix
Use posix_prefix for Apple's system Python
2 parents 07c5620 + 051de2f commit 8ed2178

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/pip/_internal/locations/_sysconfig.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616

1717
# 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
2020
# functions try to answer that with some heuristics while accounting for ad-hoc
2121
# platforms not covered by CPython's default sysconfig implementation. If the
2222
# ad-hoc implementation does not fully implement sysconfig, we'll fall back to
@@ -27,6 +27,32 @@
2727
_PREFERRED_SCHEME_API = getattr(sysconfig, "get_preferred_scheme", None)
2828

2929

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+
3056
def _infer_prefix() -> str:
3157
"""Try to find a prefix scheme for the current platform.
3258
@@ -43,8 +69,7 @@ def _infer_prefix() -> str:
4369
"""
4470
if _PREFERRED_SCHEME_API:
4571
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():
4873
return "osx_framework_library"
4974
implementation_suffixed = f"{sys.implementation.name}_{os.name}"
5075
if implementation_suffixed in _AVAILABLE_SCHEMES:
@@ -130,6 +155,12 @@ def get_scheme(
130155
else:
131156
scheme_name = _infer_prefix()
132157

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+
133164
if home is not None:
134165
variables = {k: home for k in _HOME_KEYS}
135166
elif prefix is not None:

0 commit comments

Comments
 (0)