|
| 1 | +""" |
| 2 | +Backward compatibility for homebrew builds on macOS. |
| 3 | +""" |
| 4 | + |
| 5 | + |
| 6 | +import sys |
| 7 | +import os |
| 8 | +import functools |
| 9 | +import subprocess |
| 10 | + |
| 11 | + |
| 12 | +@functools.lru_cache() |
| 13 | +def enabled(): |
| 14 | + """ |
| 15 | + Only enabled for Python 3.9 framework builds except ensurepip and venv. |
| 16 | + """ |
| 17 | + PY39 = (3, 9) < sys.version_info < (3, 10) |
| 18 | + framework = sys.platform == 'darwin' and sys._framework |
| 19 | + venv = sys.prefix != sys.base_prefix |
| 20 | + ensurepip = os.environ.get("ENSUREPIP_OPTIONS") |
| 21 | + return PY39 and framework and not venv and not ensurepip |
| 22 | + |
| 23 | + |
| 24 | +schemes = dict( |
| 25 | + osx_framework_library=dict( |
| 26 | + stdlib='{installed_base}/{platlibdir}/python{py_version_short}', |
| 27 | + platstdlib='{platbase}/{platlibdir}/python{py_version_short}', |
| 28 | + purelib='{homebrew_prefix}/lib/python{py_version_short}/site-packages', |
| 29 | + platlib='{homebrew_prefix}/{platlibdir}/python{py_version_short}/site-packages', |
| 30 | + include='{installed_base}/include/python{py_version_short}{abiflags}', |
| 31 | + platinclude='{installed_platbase}/include/python{py_version_short}{abiflags}', |
| 32 | + scripts='{homebrew_prefix}/bin', |
| 33 | + data='{homebrew_prefix}', |
| 34 | + ) |
| 35 | +) |
| 36 | + |
| 37 | + |
| 38 | +@functools.lru_cache() |
| 39 | +def vars(): |
| 40 | + if not enabled(): |
| 41 | + return {} |
| 42 | + homebrew_prefix = subprocess.check_output(['brew', '--prefix'], text=True).strip() |
| 43 | + return locals() |
| 44 | + |
| 45 | + |
| 46 | +def scheme(name): |
| 47 | + """ |
| 48 | + Override the selected scheme for posix_prefix. |
| 49 | + """ |
| 50 | + if not enabled() or not name.endswith('_prefix'): |
| 51 | + return name |
| 52 | + return 'osx_framework_library' |
0 commit comments