-
-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathpython@3.14.rb
More file actions
526 lines (452 loc) · 23.2 KB
/
python@3.14.rb
File metadata and controls
526 lines (452 loc) · 23.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
class PythonAT314 < Formula
desc "Interpreted, interactive, object-oriented programming language"
homepage "https://www.python.org/"
url "https://www.python.org/ftp/python/3.14.4/Python-3.14.4.tgz"
sha256 "b4c059d5895f030e7df9663894ce3732bfa1b32cd3ab2883980266a45ce3cb3b"
license "Python-2.0"
compatibility_version 1
livecheck do
url "https://www.python.org/ftp/python/"
regex(%r{href=.*?v?(3\.14(?:\.\d+)*)/?["' >]}i)
end
bottle do
rebuild 1
sha256 arm64_tahoe: "e6aad7f3013cf39f3ba0de702d6ffdb934ec28549fcffb580f91ec8d8685ffde"
sha256 arm64_sequoia: "dcbf428d7f9e448ee88d51c867a29d60e4ee48c69cb537ffa43154c6054951e8"
sha256 arm64_sonoma: "16f997d2727745edc4ac87df52de2517711ba0cb7c298a97f2b14e1150a926cb"
sha256 tahoe: "7498a873e826498cd2302e00f2c4a2bed207b2e3c97b06272c794d3d47662e14"
sha256 sequoia: "c3a2c539efcfaedaa4330fd7bb2abf436435f0320c9acb364bb73de970623750"
sha256 sonoma: "33ecbabc155041ef656a9572d0223a4d3412d14d763a2fdb1a963a9aacfc29c3"
sha256 arm64_linux: "b351cac4da326df26d1b72878493b2ce038e990d3770bec75db1cfd849e6c561"
sha256 x86_64_linux: "115dbf56f954ad54380ccac97205956e50c32ecd8b1bf54dbd509fef07423a79"
end
depends_on "pkgconf" => :build
depends_on "mpdecimal"
depends_on "openssl@3"
depends_on "sqlite"
depends_on "xz"
depends_on "zstd"
uses_from_macos "bzip2"
uses_from_macos "expat", since: :sequoia
uses_from_macos "libedit"
uses_from_macos "libffi"
uses_from_macos "ncurses"
uses_from_macos "unzip"
on_linux do
depends_on "zlib-ng-compat"
end
link_overwrite "bin/idle3"
link_overwrite "bin/pip3"
link_overwrite "bin/pydoc3"
link_overwrite "bin/python3"
link_overwrite "bin/python3-config"
link_overwrite "bin/wheel3"
link_overwrite "share/man/man1/python3.1"
link_overwrite "lib/libpython3.so"
link_overwrite "lib/pkgconfig/python3.pc"
link_overwrite "lib/pkgconfig/python3-embed.pc"
link_overwrite "lib/python3.14/site-packages/pip*"
link_overwrite "lib/python3.14/site-packages/wheel*"
link_overwrite "Frameworks/Python.framework/Headers"
link_overwrite "Frameworks/Python.framework/Python"
link_overwrite "Frameworks/Python.framework/Resources"
link_overwrite "Frameworks/Python.framework/Versions/Current"
pypi_packages package_name: "",
extra_packages: %w[flit-core pip wheel]
resource "flit-core" do
url "https://files.pythonhosted.org/packages/69/59/b6fc2188dfc7ea4f936cd12b49d707f66a1cb7a1d2c16172963534db741b/flit_core-3.12.0.tar.gz"
sha256 "18f63100d6f94385c6ed57a72073443e1a71a4acb4339491615d0f16d6ff01b2"
end
resource "packaging" do
url "https://files.pythonhosted.org/packages/65/ee/299d360cdc32edc7d2cf530f3accf79c4fca01e96ffc950d8a52213bd8e4/packaging-26.0.tar.gz"
sha256 "00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4"
end
resource "pip" do
url "https://files.pythonhosted.org/packages/48/83/0d7d4e9efe3344b8e2fe25d93be44f64b65364d3c8d7bc6dc90198d5422e/pip-26.0.1.tar.gz"
sha256 "c4037d8a277c89b320abe636d59f91e6d0922d08a05b60e85e53b296613346d8"
end
resource "wheel" do
url "https://files.pythonhosted.org/packages/89/24/a2eb353a6edac9a0303977c4cb048134959dd2a51b48a269dfc9dde00c8a/wheel-0.46.3.tar.gz"
sha256 "e3e79874b07d776c40bd6033f8ddf76a7dad46a7b8aa1b2787a83083519a1803"
end
# Modify default sysconfig to match the brew install layout.
# Remove when a non-patching mechanism is added (https://bugs.python.org/issue43976).
# We (ab)use osx_framework_library to exploit pip behaviour to allow --prefix to still work.
patch do
url "https://raw.githubusercontent.com/Homebrew/homebrew-core/1cf441a0/Patches/python/3.13-sysconfig.diff"
sha256 "9f2eae1d08720b06ac3d9ef1999c09388b9db39dfb52687fc261ff820bff20c3"
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["openssl@3"].opt_prefix}
--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["openssl@3"].opt_lib}',"
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/"_sysconfig_vars__darwin_darwin.json",
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
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
<<~EOS
Python is installed as
#{HOMEBREW_PREFIX}/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, are installed into
#{opt_libexec}/bin
`idle#{version.major_minor}` requires tkinter, which is available separately:
brew install python-tk@#{version.major_minor}
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"
system python3, "-c", "import _zstd"
# 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