-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Homebrew on Python 3.9 instead of relying on distutil…
…s.cfg as found in the stdlib. Fixes #152.
- Loading branch information
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Backward compatibility for homebrew builds on macOS. | ||
""" | ||
|
||
|
||
import sys | ||
import os | ||
import functools | ||
import subprocess | ||
|
||
|
||
@functools.lru_cache() | ||
def enabled(): | ||
""" | ||
Only enabled for Python 3.9 framework builds except ensurepip and venv. | ||
""" | ||
PY39 = (3, 9) < sys.version_info < (3, 10) | ||
framework = sys.platform == 'darwin' and sys._framework | ||
venv = sys.prefix != sys.base_prefix | ||
ensurepip = os.environ.get("ENSUREPIP_OPTIONS") | ||
return PY39 and framework and not venv and not ensurepip | ||
|
||
|
||
schemes = dict( | ||
osx_framework_library=dict( | ||
stdlib='{installed_base}/{platlibdir}/python{py_version_short}', | ||
platstdlib='{platbase}/{platlibdir}/python{py_version_short}', | ||
purelib='{homebrew_prefix}/lib/python{py_version_short}/site-packages', | ||
platlib='{homebrew_prefix}/{platlibdir}/python{py_version_short}/site-packages', | ||
include='{installed_base}/include/python{py_version_short}{abiflags}', | ||
platinclude='{installed_platbase}/include/python{py_version_short}{abiflags}', | ||
scripts='{homebrew_prefix}/bin', | ||
data='{homebrew_prefix}', | ||
) | ||
) | ||
|
||
|
||
@functools.lru_cache() | ||
def vars(): | ||
if not enabled(): | ||
return {} | ||
homebrew_prefix = subprocess.check_output(['brew', '--prefix'], text=True).strip() | ||
return locals() | ||
|
||
|
||
def scheme(name): | ||
""" | ||
Override the selected scheme for posix_prefix. | ||
""" | ||
if not enabled() or not name.endswith('_prefix'): | ||
return name | ||
return 'osx_framework_library' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters