-
-
Notifications
You must be signed in to change notification settings - Fork 12.4k
/
python@3.11.rb
528 lines (456 loc) · 23 KB
/
python@3.11.rb
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
527
528
class PythonAT311 < Formula
desc "Interpreted, interactive, object-oriented programming language"
homepage "https://www.python.org/"
url "https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz"
sha256 "85c37a265e5c9dd9f75b35f954e31fbfc10383162417285e30ad25cc073a0d63"
license "Python-2.0"
revision 1
livecheck do
url "https://www.python.org/ftp/python/"
regex(%r{href=.*?v?(3\.11(?:\.\d+)*)/?["' >]}i)
end
bottle do
rebuild 1
sha256 arm64_ventura: "0b34eff80378cb1157e1fefee56a89160e7a805226c32a2f24b09d5d17c1710e"
sha256 arm64_monterey: "4b191c71b7e70dd0ec915982cd5804fd63e3e897e6daf33d670e2564cd081cf8"
sha256 arm64_big_sur: "2f3feaf5da0bf4eb0b93456b0b062f8e532c75103c65a70f4278219f34e3f873"
sha256 ventura: "c01d4341c677cdb8e42284b6bcdf8c0fc589bd25dd9e83af3b8b62ac87204427"
sha256 monterey: "970901e9b8ec29f91fd956f4e5d90c946e34d6f1ce8fffdd2dfdbc7850f26fd6"
sha256 big_sur: "9b93c52f94d66a0243c2e56cbf80ceda9487ced6b479db676b20d8f7d885e9dd"
sha256 x86_64_linux: "0ad7ed8c468230e7dba3cc4f17749b0ccec37a940c5ff2b801c2b79b452e5472"
end
# setuptools remembers the build flags python is built with and uses them to
# build packages later. Xcode-only systems need different flags.
pour_bottle? only_if: :clt_installed
depends_on "pkg-config" => :build
depends_on "mpdecimal"
depends_on "openssl@3"
depends_on "sqlite"
depends_on "xz"
uses_from_macos "bzip2"
uses_from_macos "expat"
uses_from_macos "libedit"
uses_from_macos "libffi", since: :catalina
uses_from_macos "libxcrypt"
uses_from_macos "ncurses"
uses_from_macos "unzip"
uses_from_macos "zlib"
on_linux do
depends_on "berkeley-db@5"
depends_on "libnsl"
end
skip_clean "bin/pip3", "bin/pip-3.4", "bin/pip-3.5", "bin/pip-3.6", "bin/pip-3.7", "bin/pip-3.8", "bin/pip-3.9",
"bin/pip-3.10"
skip_clean "bin/easy_install3", "bin/easy_install-3.4", "bin/easy_install-3.5", "bin/easy_install-3.6",
"bin/easy_install-3.7", "bin/easy_install-3.8", "bin/easy_install-3.9", "bin/easy_install-3.10"
link_overwrite "bin/2to3"
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 "Frameworks/Python.framework/Headers"
link_overwrite "Frameworks/Python.framework/Python"
link_overwrite "Frameworks/Python.framework/Resources"
link_overwrite "Frameworks/Python.framework/Versions/Current"
# Always update to latest release
resource "flit-core" do
url "https://files.pythonhosted.org/packages/c4/e6/c1ac50fe3eebb38a155155711e6e864e254ce4b6e17fe2429b4c4d5b9e80/flit_core-3.9.0.tar.gz"
sha256 "72ad266176c4a3fcfab5f2930d76896059851240570ce9a98733b658cb786eba"
end
resource "setuptools" do
url "https://files.pythonhosted.org/packages/dc/98/5f896af066c128669229ff1aa81553ac14cfb3e5e74b6b44594132b8540e/setuptools-68.0.0.tar.gz"
sha256 "baf1fdb41c6da4cd2eae722e135500da913332ab3f2f5c7d33af9b492acb5235"
end
resource "pip" do
url "https://files.pythonhosted.org/packages/ba/19/e63fb4e0d20e48bd2167bb7e857abc0e21679e24805ba921a224df8977c0/pip-23.2.1.tar.gz"
sha256 "fb0bd5435b3200c602b5bf61d2d43c2f13c02e29c1707567ae7fbc514eb9faf2"
end
resource "wheel" do
url "https://files.pythonhosted.org/packages/ec/34/903929e15b2657335b2ce8723d92fc804d3569b7ac0f1f8877ed1a7b2024/wheel-0.41.0.tar.gz"
sha256 "55a0f0a5a84869bce5ba775abfd9c462e3a6b1b7b7ec69d72c0b83d673a5114d"
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/formula-patches/6d2fba8de3159182025237d373a6f4f78b8bd203/python/3.11-sysconfig.diff"
sha256 "8bfe417c815da4ca2c0a2457ce7ef81bc9dae310e20e4fb36235901ea4be1658"
end
# Make bundled distutils look at preferred sysconfig scheme.
# Remove with Python 3.12.
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/a1618a5005d0b01d63b720321806820a03432f1a/python/3.10-distutils-scheme.diff"
sha256 "d1a29b3c9ecf8aecd65e1e54efc42fb1422b2f5d05cba0c747178f4ef8a69683"
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"
end
# The HOMEBREW_PREFIX location of site-packages.
def site_packages
HOMEBREW_PREFIX/"lib/python#{version.major_minor}/site-packages"
end
def python3
bin/"python#{version.major_minor}"
end
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
]
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"
else
args << "--enable-shared"
args << "--with-dbmliborder=bdb"
end
# 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 MacOS.sdk_path_if_needed
# Help Python's build system (setuptools/pip) to build things on SDK-based systems
# The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
cflags << "-isysroot #{MacOS.sdk_path}"
ldflags << "-isysroot #{MacOS.sdk_path}"
end
# Avoid linking to libgcc https://mail.python.org/pipermail/python-dev/2012-February/116205.html
args << "MACOSX_DEPLOYMENT_TARGET=#{MacOS.version}"
# Resolve HOMEBREW_PREFIX in our sysconfig modification.
inreplace "Lib/sysconfig.py", "@@HOMEBREW_PREFIX@@", HOMEBREW_PREFIX
# We want our readline! This is just to outsmart the detection code,
# superenv makes cc always find includes/libs!
if OS.linux?
inreplace "setup.py",
/do_readline = self.compiler.find_library_file\(self.lib_dirs,\s*readline_lib\)/,
"do_readline = '#{Formula["libedit"].opt_lib/shared_library("libedit")}'"
end
if OS.linux?
# Python's configure adds the system ncurses include entry to CPPFLAGS
# when doing curses header check. The check may fail when there exists
# a 32-bit system ncurses (conflicts with the brewed 64-bit one).
# See https://github.com/Homebrew/linuxbrew-core/pull/22307#issuecomment-781896552
# We want our ncurses! Override system ncurses includes!
inreplace "configure", 'CPPFLAGS="$CPPFLAGS -I/usr/include/ncursesw"',
"CPPFLAGS=\"$CPPFLAGS -I#{Formula["ncurses"].opt_include}\""
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=disabled
]
system "./configure", *args
system "make"
ENV.deparallelize do
# Tell Python not to install into /Applications (default for framework builds)
system "make", "install", "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'"
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}"
end
# Remove the site-packages that Python created in its Cellar.
site_packages_cellar.rmtree
# 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
resource("flit-core").stage do
system whl_build/"bin/pip3", "install", *common_pip_args, "."
end
resource("wheel").stage do
system whl_build/"bin/pip3", "install", *common_pip_args, "."
system whl_build/"bin/pip3", "wheel", *common_pip_args,
"--wheel-dir=#{libexec}",
"."
end
# Replace bundled setuptools/pip with our own.
rm lib_cellar.glob("ensurepip/_bundled/{setuptools,pip}-*.whl")
%w[setuptools pip].each do |r|
resource(r).stage do
system whl_build/"bin/pip3", "wheel", *common_pip_args,
"--wheel-dir=#{lib_cellar}/ensurepip/_bundled",
"."
end
end
# Patch ensurepip to bootstrap our updated versions of setuptools/pip
inreplace lib_cellar/"ensurepip/__init__.py" do |s|
s.gsub!(/_SETUPTOOLS_VERSION = .*/, "_SETUPTOOLS_VERSION = \"#{resource("setuptools").version}\"")
s.gsub!(/_PIP_VERSION = .*/, "_PIP_VERSION = \"#{resource("pip").version}\"")
end
# Write out sitecustomize.py
(lib_cellar/"sitecustomize.py").atomic_write(sitecustomize)
# Install unversioned 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",
}.each do |short_name, long_name|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
end
end
def post_install
ENV.delete "PYTHONPATH"
# Fix up the site-packages so that user-installed Python software survives
# minor updates, such as going from 3.3.2 to 3.3.3:
# Create a site-packages in HOMEBREW_PREFIX/lib/python#{version.major_minor}/site-packages
site_packages.mkpath
# Symlink the prefix site-packages into the cellar.
site_packages_cellar.unlink if site_packages_cellar.exist?
site_packages_cellar.parent.install_symlink site_packages
# Remove old sitecustomize.py. Now stored in the cellar.
rm_rf Dir["#{site_packages}/sitecustomize.py[co]"]
# Remove old setuptools installations that may still fly around and be
# listed in the easy_install.pth. This can break setuptools build with
# zipimport.ZipImportError: bad local file header
# setuptools-0.9.8-py3.3.egg
rm_rf Dir["#{site_packages}/setuptools[-_.][0-9]*", "#{site_packages}/setuptools"]
rm_rf Dir["#{site_packages}/distribute[-_.][0-9]*", "#{site_packages}/distribute"]
rm_rf Dir["#{site_packages}/pip[-_.][0-9]*", "#{site_packages}/pip"]
rm_rf Dir["#{site_packages}/wheel[-_.][0-9]*", "#{site_packages}/wheel"]
system python3, "-Im", "ensurepip"
# Install desired versions of setuptools, 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).
bundled = lib_cellar/"ensurepip/_bundled"
system python3, "-Im", "pip", "install", "-v",
"--no-deps",
"--no-index",
"--upgrade",
"--isolated",
"--target=#{site_packages}",
bundled/"setuptools-#{resource("setuptools").version}-py3-none-any.whl",
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 (site_packages/"bin").children, bin
rmdir site_packages/"bin"
rm_rf bin/"pip"
mv bin/"wheel", bin/"wheel#{version.major_minor}"
bin.install_symlink "wheel#{version.major_minor}" => "wheel3"
# Install unversioned symlinks in libexec/bin.
{
"pip" => "pip#{version.major_minor}",
"wheel" => "wheel#{version.major_minor}",
}.each do |short_name, long_name|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
end
# post_install happens after link
%W[wheel3 pip3 wheel#{version.major_minor} pip#{version.major_minor}].each do |e|
(HOMEBREW_PREFIX/"bin").install_symlink bin/e
end
end
def sitecustomize
<<~EOS
# 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)
if sys.prefix == sys.base_prefix:
site.PREFIXES[:] = [new_prefix if x == sys.prefix else x for x in site.PREFIXES]
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)
if sys.exec_prefix == sys.base_exec_prefix:
site.PREFIXES[:] = [new_exec_prefix if x == sys.exec_prefix else x for x in site.PREFIXES]
sys.exec_prefix = new_exec_prefix
sys.base_exec_prefix = new_exec_prefix
# 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)
EOS
end
def caveats
<<~EOS
Python has been installed as
#{HOMEBREW_PREFIX}/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
#{opt_libexec}/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
#{HOMEBREW_PREFIX}/lib/python#{version.major_minor}/site-packages
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@#{version.major_minor}
gdbm (`dbm.gnu`) is no longer included in this formula, but it is available separately:
brew install python-gdbm@#{version.major_minor}
`dbm.ndbm` changed database backends in Homebrew Python 3.11.
If you need to read a database from a previous Homebrew Python created via `dbm.ndbm`,
you'll need to read your database using the older version of Homebrew Python and convert to another format.
`dbm` still defaults to `dbm.gnu` when it is installed.
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 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
(testpath/"dbm_test.py").write <<~EOS
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"
EOS
system python3, "dbm_test.py"
system bin/"pip#{version.major_minor}", "list", "--format=columns"
end
end