Skip to content

Commit

Permalink
Special osx_framework_library prefix scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jul 12, 2021
1 parent 1501272 commit 77810bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion news/9844.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Fix ``--user`` install scheme selection for macOS framework build.
Fix warnings about install scheme selection for Python framework builds
distributed by Apple's Command Line Tools.
11 changes: 10 additions & 1 deletion src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,27 @@
_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())


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


def _infer_prefix() -> str:
"""Try to find a prefix scheme for the current platform.
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 +61,7 @@ def _infer_prefix() -> str:

def _infer_user() -> str:
"""Try to find a user scheme for the current platform."""
if sysconfig.get_config_var("PYTHONFRAMEWORK"): # Mac framework build.
if _is_osx_framework() and not running_under_virtualenv():
suffixed = "osx_framework_user"
else:
suffixed = f"{os.name}_user"
Expand Down

0 comments on commit 77810bc

Please sign in to comment.