diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2022-07-03 20:10:33 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2022-07-03 20:17:54 -0400 |
commit | cd62fb6f7c4fc9df6407a0edb23231e39a7954ed (patch) | |
tree | 2cf2e8594e0f94026409732227eafd5d58cfad9f /setuptools/_distutils/command | |
parent | 120d9270c50a07caad0c697ca1f4b865226dde99 (diff) | |
parent | 152c13de811b302dcc673f6ed4c595cd29fd671d (diff) | |
download | python-setuptools-git-cd62fb6f7c4fc9df6407a0edb23231e39a7954ed.tar.gz |
Merge with pypa/distutils@152c13d
Diffstat (limited to 'setuptools/_distutils/command')
-rw-r--r-- | setuptools/_distutils/command/_framework_compat.py | 52 | ||||
-rw-r--r-- | setuptools/_distutils/command/build_py.py | 7 | ||||
-rw-r--r-- | setuptools/_distutils/command/install.py | 9 |
3 files changed, 60 insertions, 8 deletions
diff --git a/setuptools/_distutils/command/_framework_compat.py b/setuptools/_distutils/command/_framework_compat.py new file mode 100644 index 00000000..e032603a --- /dev/null +++ b/setuptools/_distutils/command/_framework_compat.py @@ -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' diff --git a/setuptools/_distutils/command/build_py.py b/setuptools/_distutils/command/build_py.py index 1b22004e..7723d359 100644 --- a/setuptools/_distutils/command/build_py.py +++ b/setuptools/_distutils/command/build_py.py @@ -201,16 +201,11 @@ class build_py(Command): "but is not a directory" % package_dir ) - # Require __init__.py for all but the "root package" + # Directories without __init__.py are namespace packages (PEP 420). if package: init_py = os.path.join(package_dir, "__init__.py") if os.path.isfile(init_py): return init_py - else: - log.warn( - ("package init file '%s' not found " + "(or not a regular file)"), - init_py, - ) # Either not in a package at all (__init__.py not expected), or # __init__.py doesn't exist -- so don't return the filename. diff --git a/setuptools/_distutils/command/install.py b/setuptools/_distutils/command/install.py index 0660406f..7d9054e3 100644 --- a/setuptools/_distutils/command/install.py +++ b/setuptools/_distutils/command/install.py @@ -17,6 +17,7 @@ from distutils.file_util import write_file 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 @@ -82,6 +83,10 @@ if HAS_USER_SITE: '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. @@ -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 @@ -426,7 +431,7 @@ class install(Command): 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() |