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

Add support for Homebrew on Python 3.9 #155

Merged
merged 1 commit into from
Jul 3, 2022
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
52 changes: 52 additions & 0 deletions distutils/command/_framework_compat.py
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'
9 changes: 7 additions & 2 deletions distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from distutils.util import convert_path, subst_vars, change_root
from distutils.util import get_platform
from distutils.errors import DistutilsOptionError
from . import _framework_compat as fw
from .. import _collections

from site import USER_BASE
Expand Down Expand Up @@ -82,6 +83,10 @@
'data': '{userbase}',
}


INSTALL_SCHEMES.update(fw.schemes)


# The keys to an installation scheme; if any new types of files are to be
# installed, be sure to add an entry to every installation scheme above,
# and to SCHEME_KEYS here.
Expand Down Expand Up @@ -136,7 +141,7 @@ def _resolve_scheme(name):
try:
resolved = sysconfig.get_preferred_scheme(key)
except Exception:
resolved = _pypy_hack(name)
resolved = fw.scheme(_pypy_hack(name))
return resolved


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

self.config_vars = _collections.DictStack(
[compat_vars, sysconfig.get_config_vars(), local_vars]
[fw.vars(), compat_vars, sysconfig.get_config_vars(), local_vars]
)

self.expand_basedirs()
Expand Down