From d4b23ac7eb08c9934ba2322aaddec25a7052ca0f Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Tue, 27 Apr 2021 15:56:12 +0800 Subject: [PATCH] Ignore header difference for osx_framework_user --- src/pip/_internal/locations/__init__.py | 14 ++++++++++++++ src/pip/_internal/locations/_sysconfig.py | 10 +++------- src/pip/_internal/locations/base.py | 4 ++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/pip/_internal/locations/__init__.py b/src/pip/_internal/locations/__init__.py index 18bf0319f3d..12e009c5242 100644 --- a/src/pip/_internal/locations/__init__.py +++ b/src/pip/_internal/locations/__init__.py @@ -11,6 +11,7 @@ USER_CACHE_DIR, get_major_minor_version, get_src_prefix, + is_osx_framework, site_packages, user_site, ) @@ -116,6 +117,19 @@ def get_scheme( if skip_pypy_special_case: continue + # sysconfig's ``osx_framework_user`` does not include ``pythonX.Y`` in + # the ``include`` value, but distutils's ``headers`` does. We'll let + # CPython decide whether this is a bug or feature. See bpo-43948. + skip_osx_framework_user_special_case = ( + user + and is_osx_framework() + and k == "headers" + and old_v.parent == new_v + and old_v.name.startswith("python") + ) + if skip_osx_framework_user_special_case: + continue + warned.append(_warn_if_mismatch(old_v, new_v, key=f"scheme.{k}")) if any(warned): diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index 9055a6b1461..979a2b18849 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -9,7 +9,7 @@ from pip._internal.models.scheme import SCHEME_KEYS, Scheme from pip._internal.utils.virtualenv import running_under_virtualenv -from .base import get_major_minor_version +from .base import get_major_minor_version, is_osx_framework logger = logging.getLogger(__name__) @@ -25,10 +25,6 @@ _AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names()) -def _is_osx_framework() -> bool: - return sysconfig.get_config_var("PYTHONFRAMEWORK") - - def _infer_prefix(): # type: () -> str """Try to find a prefix scheme for the current platform. @@ -44,7 +40,7 @@ def _infer_prefix(): If none of the above works, fall back to ``posix_prefix``. """ - os_framework_global = _is_osx_framework() and not running_under_virtualenv() + 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" implementation_suffixed = f"{sys.implementation.name}_{os.name}" @@ -63,7 +59,7 @@ def _infer_prefix(): def _infer_user(): # type: () -> str """Try to find a user scheme for the current platform.""" - if _is_osx_framework() and not running_under_virtualenv(): + if is_osx_framework() and not running_under_virtualenv(): suffixed = "osx_framework_user" else: suffixed = f"{os.name}_user" diff --git a/src/pip/_internal/locations/base.py b/src/pip/_internal/locations/base.py index 98557abbe63..33a099d6f28 100644 --- a/src/pip/_internal/locations/base.py +++ b/src/pip/_internal/locations/base.py @@ -46,3 +46,7 @@ def get_src_prefix(): user_site = site.getusersitepackages() # type: typing.Optional[str] except AttributeError: user_site = site.USER_SITE + + +def is_osx_framework() -> bool: + return bool(sysconfig.get_config_var("PYTHONFRAMEWORK"))