Skip to content

Commit 152c13d

Browse files
authored
Merge pull request #155 from pypa/feature/homebrew-py39-scheme
Add support for Homebrew on Python 3.9
2 parents 1b885fa + 949193f commit 152c13d

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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'

distutils/command/install.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from distutils.util import convert_path, subst_vars, change_root
1818
from distutils.util import get_platform
1919
from distutils.errors import DistutilsOptionError
20+
from . import _framework_compat as fw
2021
from .. import _collections
2122

2223
from site import USER_BASE
@@ -82,6 +83,10 @@
8283
'data': '{userbase}',
8384
}
8485

86+
87+
INSTALL_SCHEMES.update(fw.schemes)
88+
89+
8590
# The keys to an installation scheme; if any new types of files are to be
8691
# installed, be sure to add an entry to every installation scheme above,
8792
# and to SCHEME_KEYS here.
@@ -136,7 +141,7 @@ def _resolve_scheme(name):
136141
try:
137142
resolved = sysconfig.get_preferred_scheme(key)
138143
except Exception:
139-
resolved = _pypy_hack(name)
144+
resolved = fw.scheme(_pypy_hack(name))
140145
return resolved
141146

142147

@@ -426,7 +431,7 @@ def finalize_options(self):
426431
local_vars['usersite'] = self.install_usersite
427432

428433
self.config_vars = _collections.DictStack(
429-
[compat_vars, sysconfig.get_config_vars(), local_vars]
434+
[fw.vars(), compat_vars, sysconfig.get_config_vars(), local_vars]
430435
)
431436

432437
self.expand_basedirs()

0 commit comments

Comments
 (0)