Skip to content

Commit ad9d46e

Browse files
authored
Merge pull request #9844 from uranusjr/sysconfig-framework-user
2 parents 3209ad0 + 57d9af2 commit ad9d46e

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

news/9844.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix warnings about install scheme selection for Python framework builds
2+
distributed by Apple's Command Line Tools.

src/pip/_internal/locations/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
USER_CACHE_DIR,
1212
get_major_minor_version,
1313
get_src_prefix,
14+
is_osx_framework,
1415
site_packages,
1516
user_site,
1617
)
@@ -115,6 +116,19 @@ def get_scheme(
115116
if skip_pypy_special_case:
116117
continue
117118

119+
# sysconfig's ``osx_framework_user`` does not include ``pythonX.Y`` in
120+
# the ``include`` value, but distutils's ``headers`` does. We'll let
121+
# CPython decide whether this is a bug or feature. See bpo-43948.
122+
skip_osx_framework_user_special_case = (
123+
user
124+
and is_osx_framework()
125+
and k == "headers"
126+
and old_v.parent == new_v
127+
and old_v.name.startswith("python")
128+
)
129+
if skip_osx_framework_user_special_case:
130+
continue
131+
118132
warned.append(_warn_if_mismatch(old_v, new_v, key=f"scheme.{k}"))
119133

120134
if any(warned):

src/pip/_internal/locations/_sysconfig.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
1010
from pip._internal.utils.virtualenv import running_under_virtualenv
1111

12-
from .base import get_major_minor_version
12+
from .base import get_major_minor_version, is_osx_framework
1313

1414
logger = logging.getLogger(__name__)
1515

@@ -30,13 +30,18 @@ def _infer_prefix() -> str:
3030
3131
This tries:
3232
33+
* A special ``osx_framework_library`` for Python distributed by Apple's
34+
Command Line Tools, when not running in a virtual environment.
3335
* Implementation + OS, used by PyPy on Windows (``pypy_nt``).
3436
* Implementation without OS, used by PyPy on POSIX (``pypy``).
3537
* OS + "prefix", used by CPython on POSIX (``posix_prefix``).
3638
* Just the OS name, used by CPython on Windows (``nt``).
3739
3840
If none of the above works, fall back to ``posix_prefix``.
3941
"""
42+
os_framework_global = is_osx_framework() and not running_under_virtualenv()
43+
if os_framework_global and "osx_framework_library" in _AVAILABLE_SCHEMES:
44+
return "osx_framework_library"
4045
implementation_suffixed = f"{sys.implementation.name}_{os.name}"
4146
if implementation_suffixed in _AVAILABLE_SCHEMES:
4247
return implementation_suffixed
@@ -52,7 +57,10 @@ def _infer_prefix() -> str:
5257

5358
def _infer_user() -> str:
5459
"""Try to find a user scheme for the current platform."""
55-
suffixed = f"{os.name}_user"
60+
if is_osx_framework() and not running_under_virtualenv():
61+
suffixed = "osx_framework_user"
62+
else:
63+
suffixed = f"{os.name}_user"
5664
if suffixed in _AVAILABLE_SCHEMES:
5765
return suffixed
5866
if "posix_user" not in _AVAILABLE_SCHEMES: # User scheme unavailable.

src/pip/_internal/locations/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ def get_src_prefix() -> str:
4444
user_site: typing.Optional[str] = site.getusersitepackages()
4545
except AttributeError:
4646
user_site = site.USER_SITE
47+
48+
49+
def is_osx_framework() -> bool:
50+
return bool(sysconfig.get_config_var("PYTHONFRAMEWORK"))

0 commit comments

Comments
 (0)