533 lines
23 KiB
Ruby
533 lines
23 KiB
Ruby
class PythonAT313 < Formula
|
|
bottle do
|
|
root_url "https://homebrew.mirror.ygg/bottles"
|
|
sha256 cellar: "/opt/homebrew/Cellar", arm64_sequoia: "a7ce66c50eeee32186f6db8054ff259cf480942e8bf10767588d47cb45a97692"
|
|
sha256 cellar: "/opt/homebrew/Cellar", arm64_tahoe: "02e3c9b06f15a5aef1509838ca3572f111588ffb395c638148b54b0cf041848e"
|
|
sha256 cellar: "/usr/local/Cellar", sequoia: "f2d7049c87cba28e4dce89c45bd3566ccf51441cad33c19e9e67525c603c1453"
|
|
sha256 cellar: "/home/linuxbrew/.linuxbrew/Cellar", x86_64_linux: "4cdbffcfe9e2b2d9a5c28597d8e00d2dc995962785c25a098b2e4d8298edec54"
|
|
end
|
|
desc "Interpreted, interactive, object-oriented programming language"
|
|
homepage "https://www.python.org/"
|
|
url "https://www.python.org/ftp/python/3.13.15/Python-3.13.15.tgz"
|
|
sha256 "c28d9d213c09b5b5ab2c29812950e12f746999e099b82894231be954b26baed9"
|
|
license "Python-2.0"
|
|
compatibility_version 1
|
|
|
|
livecheck do
|
|
url "https://www.python.org/downloads/source/"
|
|
regex(%r{href=.*?/Python[._-]v?(3\.13(?:\.\d+)*)\.t}i)
|
|
end
|
|
|
|
|
|
|
|
# https://devguide.python.org/versions/#versions
|
|
deprecate! date: "2029-11-01", because: :deprecated_upstream
|
|
disable! date: "2030-11-01", because: :deprecated_upstream
|
|
|
|
depends_on "pkgconf" => :build
|
|
depends_on "mpdecimal"
|
|
depends_on "openssl@3"
|
|
depends_on "sqlite"
|
|
depends_on "xz"
|
|
|
|
uses_from_macos "bzip2"
|
|
uses_from_macos "expat", since: :sequoia
|
|
uses_from_macos "libedit"
|
|
uses_from_macos "libffi"
|
|
uses_from_macos "ncurses"
|
|
|
|
on_linux do
|
|
depends_on "zlib-ng-compat"
|
|
end
|
|
|
|
link_overwrite "lib/python3.13/site-packages/pip*"
|
|
link_overwrite "lib/python3.13/site-packages/wheel*"
|
|
|
|
pypi_packages package_name: "",
|
|
extra_packages: %w[flit-core pip wheel]
|
|
|
|
resource "flit-core" do
|
|
url "https://files.pythonhosted.org/packages/46/ef/34533186e76c526d9ec17a1ad9a10c7354cbfb20f51583cc36dfe4bdccd0/flit_core-4.0.2.tar.gz"
|
|
sha256 "b6929defd93884b584d7c87829e0e7b5c26ed6be17b0b873979019314aa841c8"
|
|
end
|
|
|
|
resource "packaging" do
|
|
url "https://files.pythonhosted.org/packages/7d/fa/3944b40b07da9ce895c0e6303a5ab7d53da063554f534556b134a54d6093/packaging-26.3.tar.gz"
|
|
sha256 "94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79"
|
|
end
|
|
|
|
resource "pip" do
|
|
url "https://files.pythonhosted.org/packages/db/96/e6f8e9d9d7b9cc4457092712a7e919c3186aa2c2fa9ffed2c5d29cc947e8/pip-26.2.tar.gz"
|
|
sha256 "2d8542afcc84cdd8e846c2b36b2861fad1da376dd98f8e7113e9108a3c331690"
|
|
end
|
|
|
|
resource "wheel" do
|
|
url "https://files.pythonhosted.org/packages/39/62/75f18a0f03b4219c456652c7780e4d749b929eb605c098ce3a5b6b6bc081/wheel-0.47.0.tar.gz"
|
|
sha256 "cc72bd1009ba0cf63922e28f94d9d83b920aa2bb28f798a31d0691b02fa3c9b3"
|
|
end
|
|
|
|
# Modify default sysconfig to match the brew install layout.
|
|
# Remove when a non-patching mechanism is added.
|
|
# We (ab)use osx_framework_library to exploit pip behaviour to allow --prefix to still work.
|
|
patch do
|
|
file "Patches/python/3.13-sysconfig.diff"
|
|
type :unofficial
|
|
resolves "https://bugs.python.org/issue43976"
|
|
end
|
|
|
|
def lib_cellar
|
|
on_macos do
|
|
return frameworks/"Python.framework/Versions"/version.major_minor/"lib/python#{version.major_minor}"
|
|
end
|
|
on_linux do
|
|
return lib/"python#{version.major_minor}"
|
|
end
|
|
end
|
|
|
|
def site_packages_cellar = lib_cellar/"site-packages"
|
|
|
|
# The HOMEBREW_PREFIX location of site-packages.
|
|
def site_packages = HOMEBREW_PREFIX/"lib/python#{version.major_minor}/site-packages"
|
|
|
|
def altinstall? = name != Formula["python3"].name
|
|
|
|
def python3 = bin/"python#{version.major_minor}"
|
|
|
|
def install
|
|
# Unset these so that installing pip and setuptools puts them where we want
|
|
# and not into some other Python the user has installed.
|
|
ENV["PYTHONHOME"] = nil
|
|
ENV["PYTHONPATH"] = nil
|
|
|
|
# Override the auto-detection of libmpdec, which assumes a universal build.
|
|
# This is currently an inreplace due to https://github.com/python/cpython/issues/98557.
|
|
if OS.mac?
|
|
inreplace "configure", "libmpdec_machine=universal",
|
|
"libmpdec_machine=#{ENV["PYTHON_DECIMAL_WITH_MACHINE"] = Hardware::CPU.arm? ? "uint128" : "x64"}"
|
|
end
|
|
|
|
# The --enable-optimization and --with-lto flags diverge from what upstream
|
|
# python does for their macOS binary releases. They have chosen not to apply
|
|
# these flags because they want one build that will work across many macOS
|
|
# releases. Homebrew is not so constrained because the bottling
|
|
# infrastructure specializes for each macOS major release.
|
|
args = %W[
|
|
--prefix=#{prefix}
|
|
--enable-ipv6
|
|
--datarootdir=#{share}
|
|
--datadir=#{share}
|
|
--without-ensurepip
|
|
--enable-loadable-sqlite-extensions
|
|
--with-openssl=#{formula_opt_prefix("openssl@3")}
|
|
--enable-optimizations
|
|
--with-system-expat
|
|
--with-system-libmpdec
|
|
--with-readline=editline
|
|
]
|
|
|
|
# Python re-uses flags when building native modules.
|
|
# Since we don't want native modules prioritizing the brew
|
|
# include path, we move them to [C|LD]FLAGS_NODIST.
|
|
# Note: Changing CPPFLAGS causes issues with dbm, so we
|
|
# leave it as-is.
|
|
cflags = []
|
|
cflags_nodist = ["-I#{HOMEBREW_PREFIX}/include"]
|
|
ldflags = []
|
|
ldflags_nodist = ["-L#{HOMEBREW_PREFIX}/lib", "-Wl,-rpath,#{HOMEBREW_PREFIX}/lib"]
|
|
cppflags = ["-I#{HOMEBREW_PREFIX}/include"]
|
|
|
|
if OS.mac?
|
|
# Enabling LTO on Linux makes libpython3.*.a unusable for anyone whose GCC
|
|
# install does not match the one in CI _exactly_ (major and minor version).
|
|
# https://github.com/orgs/Homebrew/discussions/3734
|
|
args << "--with-lto"
|
|
args << "--enable-framework=#{frameworks}"
|
|
args << "--with-dtrace"
|
|
args << "--with-dbmliborder=ndbm"
|
|
|
|
# Avoid linking to libgcc https://mail.python.org/pipermail/python-dev/2012-February/116205.html
|
|
args << "MACOSX_DEPLOYMENT_TARGET=#{MacOS.version}"
|
|
else
|
|
args << "--enable-shared"
|
|
args << "--with-dbmliborder="
|
|
end
|
|
|
|
# Allow python modules to use ctypes.find_library to find homebrew's stuff
|
|
# even if homebrew is not a /usr/local/lib. Try this with:
|
|
# `brew install enchant && pip install pyenchant`
|
|
inreplace "./Lib/ctypes/macholib/dyld.py" do |f|
|
|
f.gsub! "DEFAULT_LIBRARY_FALLBACK = [",
|
|
"DEFAULT_LIBRARY_FALLBACK = [ '#{HOMEBREW_PREFIX}/lib', '#{formula_opt_lib("openssl@3")}',"
|
|
f.gsub! "DEFAULT_FRAMEWORK_FALLBACK = [", "DEFAULT_FRAMEWORK_FALLBACK = [ '#{HOMEBREW_PREFIX}/Frameworks',"
|
|
end
|
|
|
|
args << "CFLAGS=#{cflags.join(" ")}" unless cflags.empty?
|
|
args << "CFLAGS_NODIST=#{cflags_nodist.join(" ")}" unless cflags_nodist.empty?
|
|
args << "LDFLAGS=#{ldflags.join(" ")}" unless ldflags.empty?
|
|
args << "LDFLAGS_NODIST=#{ldflags_nodist.join(" ")}" unless ldflags_nodist.empty?
|
|
args << "CPPFLAGS=#{cppflags.join(" ")}" unless cppflags.empty?
|
|
|
|
# Disabled modules - provided in separate formulae
|
|
args += %w[
|
|
py_cv_module__tkinter=n/a
|
|
]
|
|
|
|
system "./configure", *args
|
|
system "make"
|
|
|
|
ENV.deparallelize do
|
|
# The `altinstall` target prevents the installation of files with only Python's major
|
|
# version in its name. This allows us to link multiple versioned Python formulae.
|
|
# https://github.com/python/cpython#installing-multiple-versions
|
|
#
|
|
# Tell Python not to install into /Applications (default for framework builds)
|
|
target = "#{"alt" if altinstall?}install"
|
|
system "make", target, "PYTHONAPPSDIR=#{prefix}"
|
|
system "make", "frameworkinstallextras", "PYTHONAPPSDIR=#{pkgshare}" if OS.mac?
|
|
end
|
|
|
|
if OS.mac?
|
|
# Any .app get a " 3" attached, so it does not conflict with python 2.x.
|
|
prefix.glob("*.app") { |app| mv app, app.to_s.sub(/\.app$/, " 3.app") }
|
|
|
|
pc_dir = frameworks/"Python.framework/Versions"/version.major_minor/"lib/pkgconfig"
|
|
# Symlink the pkgconfig files into HOMEBREW_PREFIX so they're accessible.
|
|
(lib/"pkgconfig").install_symlink pc_dir.children
|
|
|
|
# Prevent third-party packages from building against fragile Cellar paths
|
|
bad_cellar_path_files = [
|
|
lib_cellar/"_sysconfigdata__darwin_darwin.py",
|
|
lib_cellar/"config-#{version.major_minor}-darwin/Makefile",
|
|
pc_dir/"python-#{version.major_minor}.pc",
|
|
pc_dir/"python-#{version.major_minor}-embed.pc",
|
|
]
|
|
inreplace bad_cellar_path_files, prefix, opt_prefix
|
|
|
|
# Help third-party packages find the Python framework
|
|
inreplace lib_cellar/"config-#{version.major_minor}-darwin/Makefile",
|
|
/^LINKFORSHARED=(.*)PYTHONFRAMEWORKDIR(.*)/,
|
|
"LINKFORSHARED=\\1PYTHONFRAMEWORKINSTALLDIR\\2"
|
|
|
|
# Symlink the pkgconfig files into HOMEBREW_PREFIX so they're accessible.
|
|
(lib/"pkgconfig").install_symlink pc_dir.children
|
|
|
|
# Fix for https://github.com/Homebrew/homebrew-core/issues/21212
|
|
inreplace lib_cellar/"_sysconfigdata__darwin_darwin.py",
|
|
%r{('LINKFORSHARED': .*?) (Python.framework/Versions/3.\d+/Python)'}m,
|
|
"\\1 #{opt_prefix}/Frameworks/\\2'"
|
|
|
|
# For an altinstall, remove symlinks that conflict with the main Python formula.
|
|
rm frameworks.glob("Python.framework/{Headers,Python,Resources,Versions/Current}") if altinstall?
|
|
else
|
|
# Prevent third-party packages from building against fragile Cellar paths
|
|
inreplace Dir[lib_cellar/"**/_sysconfigdata_*linux_x86_64-*.py",
|
|
lib_cellar/"config*/Makefile",
|
|
bin/"python#{version.major_minor}-config",
|
|
lib/"pkgconfig/python-3*.pc"],
|
|
prefix, opt_prefix
|
|
|
|
inreplace bin/"python#{version.major_minor}-config",
|
|
'prefix_real=$(installed_prefix "$0")',
|
|
"prefix_real=#{opt_prefix}"
|
|
|
|
# For an altinstall, remove symlinks that conflict with the main Python formula.
|
|
rm lib/"libpython3.so" if altinstall?
|
|
end
|
|
|
|
# Remove the site-packages that Python created in its Cellar.
|
|
rm_r site_packages_cellar.children
|
|
|
|
# Prepare a wheel of wheel to install later.
|
|
common_pip_args = %w[
|
|
-v
|
|
--no-deps
|
|
--no-binary :all:
|
|
--no-index
|
|
--no-build-isolation
|
|
]
|
|
whl_build = buildpath/"whl_build"
|
|
system python3, "-m", "venv", whl_build
|
|
%w[flit-core wheel].each do |r|
|
|
resource(r).stage do
|
|
system whl_build/"bin/pip3", "install", *common_pip_args, "."
|
|
end
|
|
end
|
|
resource("wheel").stage do
|
|
system whl_build/"bin/pip3", "wheel", *common_pip_args,
|
|
"--wheel-dir=#{libexec}",
|
|
"."
|
|
end
|
|
|
|
# Replace bundled pip with our own.
|
|
rm lib_cellar.glob("ensurepip/_bundled/pip-*.whl")
|
|
resource("pip").stage do
|
|
system whl_build/"bin/pip3", "wheel", *common_pip_args,
|
|
"--wheel-dir=#{lib_cellar}/ensurepip/_bundled",
|
|
"."
|
|
end
|
|
|
|
# Patch ensurepip to bootstrap our updated version of pip
|
|
inreplace lib_cellar/"ensurepip/__init__.py" do |s|
|
|
s.gsub!(/_PIP_VERSION = .*/, "_PIP_VERSION = \"#{resource("pip").version}\"")
|
|
end
|
|
|
|
# Ensure that our new pip wheel is globally readable.
|
|
chmod "ugo+r", lib_cellar.glob("ensurepip/_bundled/pip-*.whl")
|
|
|
|
# Install unversioned (and for an altinstall, major-versioned) symlinks in libexec/bin.
|
|
{
|
|
"idle" => "idle#{version.major_minor}",
|
|
"pydoc" => "pydoc#{version.major_minor}",
|
|
"python" => "python#{version.major_minor}",
|
|
"python-config" => "python#{version.major_minor}-config",
|
|
}.merge(altinstall? ? {
|
|
"idle3" => "idle#{version.major_minor}",
|
|
"pydoc3" => "pydoc#{version.major_minor}",
|
|
"python3" => "python#{version.major_minor}",
|
|
"python3-config" => "python#{version.major_minor}-config",
|
|
} : {}).each do |short_name, long_name|
|
|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
|
|
end
|
|
|
|
# Bootstrap initial install of pip.
|
|
system python3, "-Im", "ensurepip"
|
|
|
|
# Install desired versions of pip, wheel using the version of
|
|
# pip bootstrapped by ensurepip.
|
|
# Note that while we replaced the ensurepip wheels, there's no guarantee
|
|
# ensurepip actually used them, since other existing installations could
|
|
# have been picked up (and we can't pass --ignore-installed).
|
|
root_site_packages = lib/"python#{version.major_minor}/site-packages"
|
|
bundled = lib_cellar/"ensurepip/_bundled"
|
|
system python3, "-Im", "pip", "install", "-v",
|
|
"--no-deps",
|
|
"--no-index",
|
|
"--upgrade",
|
|
"--isolated",
|
|
"--target=#{root_site_packages}",
|
|
bundled/"pip-#{resource("pip").version}-py3-none-any.whl",
|
|
libexec/"wheel-#{resource("wheel").version}-py3-none-any.whl"
|
|
|
|
# pip install with --target flag will just place the bin folder into the
|
|
# target, so move its contents into the appropriate location
|
|
mv (root_site_packages/"bin").children, bin
|
|
rmdir root_site_packages/"bin"
|
|
|
|
rm bin/"pip"
|
|
rm bin/"pip3" if altinstall?
|
|
mv bin/"wheel", bin/"wheel#{version.major_minor}"
|
|
bin.install_symlink "wheel#{version.major_minor}" => "wheel3" unless altinstall?
|
|
|
|
# Install unversioned (and for an altinstall, major-versioned) symlinks in libexec/bin.
|
|
{
|
|
"pip" => "pip#{version.major_minor}",
|
|
"wheel" => "wheel#{version.major_minor}",
|
|
}.merge(altinstall? ? {
|
|
"pip3" => "pip#{version.major_minor}",
|
|
"wheel3" => "wheel#{version.major_minor}",
|
|
} : {}).each do |short_name, long_name|
|
|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
|
|
end
|
|
|
|
if OS.mac?
|
|
# Replace framework site-packages with a symlink to the real one.
|
|
rm_r site_packages_cellar
|
|
site_packages_cellar.parent.install_symlink root_site_packages
|
|
end
|
|
|
|
# Write out sitecustomize.py
|
|
(lib_cellar/"sitecustomize.py").atomic_write(sitecustomize)
|
|
|
|
# Mark Homebrew python as externally managed: https://peps.python.org/pep-0668/#marking-an-interpreter-as-using-an-external-package-manager
|
|
# Placed after ensurepip since it invokes pip in isolated mode, meaning
|
|
# we can't pass --break-system-packages.
|
|
(lib_cellar/"EXTERNALLY-MANAGED").write <<~INI
|
|
[externally-managed]
|
|
Error=To install Python packages system-wide, try brew install
|
|
xyz, where xyz is the package you are trying to
|
|
install.
|
|
|
|
If you wish to install a Python library that isn't in Homebrew,
|
|
use a virtual environment:
|
|
|
|
python3 -m venv path/to/venv
|
|
source path/to/venv/bin/activate
|
|
python3 -m pip install xyz
|
|
|
|
If you wish to install a Python application that isn't in Homebrew,
|
|
it may be easiest to use 'pipx install xyz', which will manage a
|
|
virtual environment for you. You can install pipx with
|
|
|
|
brew install pipx
|
|
|
|
You may restore the old behavior of pip by passing
|
|
the '--break-system-packages' flag to pip, or by adding
|
|
'break-system-packages = true' to your pip.conf file. The latter
|
|
will permanently disable this error.
|
|
|
|
If you disable this error, we STRONGLY recommend that you additionally
|
|
pass the '--user' flag to pip, or set 'user = true' in your pip.conf
|
|
file. Failure to do this can result in a broken Homebrew installation.
|
|
|
|
Read more about this behavior here: <https://peps.python.org/pep-0668/>
|
|
INI
|
|
end
|
|
|
|
post_install_steps do
|
|
on_macos do
|
|
set_permissions "Python.framework/Versions/{{version.major_minor}}/" \
|
|
"lib/python{{version.major_minor}}/venv/scripts/**/*",
|
|
"u+w", base: :frameworks, recursive: false
|
|
end
|
|
on_linux do
|
|
set_permissions "python{{version.major_minor}}/venv/scripts/**/*", "u+w", base: :lib, recursive: false
|
|
end
|
|
end
|
|
|
|
def sitecustomize
|
|
<<~PYTHON
|
|
# This file is created by Homebrew and is executed on each python startup.
|
|
# Don't print from here, or else python command line scripts may fail!
|
|
# <https://docs.brew.sh/Homebrew-and-Python>
|
|
import re
|
|
import os
|
|
import site
|
|
import sys
|
|
if sys.version_info[:2] != (#{version.major}, #{version.minor}):
|
|
# This can only happen if the user has set the PYTHONPATH to a mismatching site-packages directory.
|
|
# Every Python looks at the PYTHONPATH variable and we can't fix it here in sitecustomize.py,
|
|
# because the PYTHONPATH is evaluated after the sitecustomize.py. Many modules (e.g. PyQt4) are
|
|
# built only for a specific version of Python and will fail with cryptic error messages.
|
|
# In the end this means: Don't set the PYTHONPATH permanently if you use different Python versions.
|
|
exit(f'Your PYTHONPATH points to a site-packages dir for Python #{version.major_minor} '
|
|
f'but you are running Python {sys.version_info[0]}.{sys.version_info[1]}!\\n'
|
|
f' PYTHONPATH is currently: "{os.environ["PYTHONPATH"]}"\\n'
|
|
f' You should `unset PYTHONPATH` to fix this.')
|
|
# Only do this for a brewed python:
|
|
if os.path.realpath(sys.executable).startswith('#{rack}'):
|
|
# Shuffle /Library site-packages to the end of sys.path
|
|
library_site = '/Library/Python/#{version.major_minor}/site-packages'
|
|
library_packages = [p for p in sys.path if p.startswith(library_site)]
|
|
sys.path = [p for p in sys.path if not p.startswith(library_site)]
|
|
# .pth files have already been processed so don't use addsitedir
|
|
sys.path.extend(library_packages)
|
|
# the Cellar site-packages is a symlink to the HOMEBREW_PREFIX
|
|
# site_packages; prefer the shorter paths
|
|
long_prefix = re.compile(r'#{rack}/[0-9\\._abrc]+/(?:Frameworks/Python\\.framework/Versions/#{version.major_minor}/)?lib/python#{version.major_minor}/site-packages')
|
|
sys.path = [long_prefix.sub('#{site_packages}', p) for p in sys.path]
|
|
# Set the sys.executable to use the opt_prefix. Only do this if PYTHONEXECUTABLE is not
|
|
# explicitly set and we are not in a virtualenv:
|
|
if 'PYTHONEXECUTABLE' not in os.environ and sys.prefix == sys.base_prefix:
|
|
sys.executable = sys._base_executable = '#{opt_bin}/python#{version.major_minor}'
|
|
if 'PYTHONHOME' not in os.environ:
|
|
cellar_prefix = re.compile(r'#{rack}/[0-9\\._abrc]+(?=/|$)')
|
|
if os.path.realpath(sys.base_prefix).startswith('#{rack}'):
|
|
new_prefix = cellar_prefix.sub('#{opt_prefix}', sys.base_prefix)
|
|
site.PREFIXES[:] = [new_prefix if x == sys.base_prefix else x for x in site.PREFIXES]
|
|
if sys.prefix == sys.base_prefix:
|
|
sys.prefix = new_prefix
|
|
sys.base_prefix = new_prefix
|
|
if os.path.realpath(sys.base_exec_prefix).startswith('#{rack}'):
|
|
new_exec_prefix = cellar_prefix.sub('#{opt_prefix}', sys.base_exec_prefix)
|
|
site.PREFIXES[:] = [new_exec_prefix if x == sys.base_exec_prefix else x for x in site.PREFIXES]
|
|
if sys.exec_prefix == sys.base_exec_prefix:
|
|
sys.exec_prefix = new_exec_prefix
|
|
sys.base_exec_prefix = new_exec_prefix
|
|
# Make site.getsitepackages() return the HOMEBREW_PREFIX site-packages,
|
|
# but only if we are outside a venv or in one with include-system-site-packages.
|
|
if sys.base_prefix in site.PREFIXES:
|
|
site.PREFIXES.insert(site.PREFIXES.index(sys.base_prefix), '#{HOMEBREW_PREFIX}')
|
|
site.addsitedir('#{site_packages}')
|
|
# Check for and add the prefix of split Python formulae.
|
|
for split_module in ["tk", "gdbm"]:
|
|
split_prefix = f"#{HOMEBREW_PREFIX}/opt/python-{split_module}@#{version.major_minor}/libexec"
|
|
if os.path.isdir(split_prefix):
|
|
sys.path.append(split_prefix)
|
|
PYTHON
|
|
end
|
|
|
|
def caveats
|
|
dbm_is = "`dbm.gnu` is"
|
|
on_linux do
|
|
dbm_is = "`dbm.gnu` and `dbm.ndbm` are"
|
|
end
|
|
|
|
<<~EOS
|
|
Python is installed as
|
|
#{HOMEBREW_PREFIX}/bin/python#{version.major_minor}
|
|
|
|
Unversioned and major-versioned symlinks `python`, `python3`, `python-config`, `python3-config`, `pip`, `pip3`, etc. pointing to
|
|
`python#{version.major_minor}`, `python#{version.major_minor}-config`, `pip#{version.major_minor}` etc., respectively, are installed into
|
|
#{opt_libexec}/bin
|
|
|
|
If you do not need a specific version of Python, and always want Homebrew's `python3` in your PATH:
|
|
brew install python3
|
|
|
|
`idle#{version.major_minor}` requires tkinter, which is available separately:
|
|
brew install python-tk@#{version.major_minor}
|
|
|
|
#{dbm_is} available separately:
|
|
brew install python-gdbm@#{version.major_minor}
|
|
|
|
For more information about Homebrew and Python, see: https://docs.brew.sh/Homebrew-and-Python
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
# Check if sqlite is ok, because we build with --enable-loadable-sqlite-extensions
|
|
# and it can occur that building sqlite silently fails if OSX's sqlite is used.
|
|
system python3, "-c", "import sqlite3"
|
|
|
|
# check to see if we can create a venv
|
|
system python3, "-m", "venv", testpath/"myvenv"
|
|
|
|
# Check if some other modules import. Then the linked libs are working.
|
|
system python3, "-c", "import _ctypes"
|
|
system python3, "-c", "import _decimal"
|
|
system python3, "-c", "import pyexpat"
|
|
system python3, "-c", "import readline"
|
|
system python3, "-c", "import zlib"
|
|
|
|
# tkinter is provided in a separate formula
|
|
assert_match "ModuleNotFoundError: No module named '_tkinter'",
|
|
shell_output("#{python3} -Sc 'import tkinter' 2>&1", 1)
|
|
|
|
# gdbm is provided in a separate formula
|
|
assert_match "ModuleNotFoundError: No module named '_gdbm'",
|
|
shell_output("#{python3} -Sc 'import _gdbm' 2>&1", 1)
|
|
assert_match "ModuleNotFoundError: No module named '_gdbm'",
|
|
shell_output("#{python3} -Sc 'import dbm.gnu' 2>&1", 1)
|
|
|
|
# Verify that the selected DBM interface works on macOS.
|
|
# Linux requires installing python-gdbm formula
|
|
(testpath/"dbm_test.py").write <<~PYTHON
|
|
import dbm
|
|
|
|
with dbm.ndbm.open("test", "c") as db:
|
|
db[b"foo \\xbd"] = b"bar \\xbd"
|
|
with dbm.ndbm.open("test", "r") as db:
|
|
assert list(db.keys()) == [b"foo \\xbd"]
|
|
assert b"foo \\xbd" in db
|
|
assert db[b"foo \\xbd"] == b"bar \\xbd"
|
|
PYTHON
|
|
system python3, "dbm_test.py" if OS.mac?
|
|
|
|
system bin/"pip#{version.major_minor}", "list", "--format=columns"
|
|
|
|
# Check our sitecustomize.py
|
|
assert_match HOMEBREW_CELLAR.to_s, shell_output("#{python3} -Sc 'import sys; print(sys.base_prefix)'")
|
|
refute_match HOMEBREW_CELLAR.to_s, shell_output("#{python3} -c 'import sys; print(sys.base_prefix)'")
|
|
refute_match site_packages_cellar.to_s, shell_output("#{python3} -c 'import sys; print(sys.path)'")
|
|
|
|
# Verify our sysconfig patches
|
|
sysconfig_path = "import sysconfig; print(sysconfig.get_paths(\"osx_framework_library\")[\"data\"])"
|
|
assert_equal HOMEBREW_PREFIX.to_s, shell_output("#{python3} -c '#{sysconfig_path}'").strip
|
|
linkforshared_var = "import sysconfig; print(sysconfig.get_config_var(\"LINKFORSHARED\"))"
|
|
assert_match opt_prefix.to_s, shell_output("#{python3} -c '#{linkforshared_var}'") if OS.mac?
|
|
|
|
# Check our externally managed marker
|
|
assert_match "If you wish to install a Python library",
|
|
shell_output("#{python3} -m pip install pip 2>&1", 1)
|
|
end
|
|
end
|