Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use osx_framework_user and osx_framework_library for Command Line Tools Python #9844

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/9844.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix warnings about install scheme selection for Python framework builds
distributed by Apple's Command Line Tools.
14 changes: 14 additions & 0 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
USER_CACHE_DIR,
get_major_minor_version,
get_src_prefix,
is_osx_framework,
site_packages,
user_site,
)
Expand Down Expand Up @@ -115,6 +116,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):
Expand Down
12 changes: 10 additions & 2 deletions src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -30,13 +30,18 @@ def _infer_prefix() -> str:

This tries:

* A special ``osx_framework_library`` for Python distributed by Apple's
Command Line Tools, when not running in a virtual environment.
* Implementation + OS, used by PyPy on Windows (``pypy_nt``).
* Implementation without OS, used by PyPy on POSIX (``pypy``).
* OS + "prefix", used by CPython on POSIX (``posix_prefix``).
* Just the OS name, used by CPython on Windows (``nt``).

If none of the above works, fall back to ``posix_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"
implementation_suffixed = f"{sys.implementation.name}_{os.name}"
if implementation_suffixed in _AVAILABLE_SCHEMES:
return implementation_suffixed
Expand All @@ -52,7 +57,10 @@ def _infer_prefix() -> str:

def _infer_user() -> str:
"""Try to find a user scheme for the current platform."""
suffixed = f"{os.name}_user"
if is_osx_framework() and not running_under_virtualenv():
suffixed = "osx_framework_user"
else:
suffixed = f"{os.name}_user"
if suffixed in _AVAILABLE_SCHEMES:
return suffixed
if "posix_user" not in _AVAILABLE_SCHEMES: # User scheme unavailable.
Expand Down
4 changes: 4 additions & 0 deletions src/pip/_internal/locations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def get_src_prefix() -> str:
user_site: typing.Optional[str] = site.getusersitepackages()
except AttributeError:
user_site = site.USER_SITE


def is_osx_framework() -> bool:
return bool(sysconfig.get_config_var("PYTHONFRAMEWORK"))