@@ -34,18 +34,21 @@ class PythonAT38 < Formula
3434 uses_from_macos "libffi"
3535 uses_from_macos "ncurses"
3636 uses_from_macos "unzip"
37+ uses_from_macos "xz"
3738 uses_from_macos "zlib"
3839
3940 skip_clean "bin/pip3" , "bin/pip-3.4" , "bin/pip-3.5" , "bin/pip-3.6" , "bin/pip-3.7" , "bin/pip-3.8"
41+ skip_clean "bin/easy_install3" , "bin/easy_install-3.4" , "bin/easy_install-3.5" , "bin/easy_install-3.6" ,
42+ "bin/easy_install-3.7" , "bin/easy_install-3.8"
4043
4144 resource "setuptools" do
42- url "https://pypi.org/packages/source/s/setuptools/setuptools-57.0 .0.tar.gz"
43- sha256 "401cbf33a7bf817d08014d51560fc003b895c4cdc1a5b521ad2969e928a07535 "
45+ url "https://pypi.org/packages/source/s/setuptools/setuptools-57.4 .0.tar.gz"
46+ sha256 "6bac238ffdf24e8806c61440e755192470352850f3419a52f26ffe0a1a64f465 "
4447 end
4548
4649 resource "pip" do
47- url "https://www.pypi.org/packages/source/p/pip/pip-21.1.2 .tar.gz"
48- sha256 "eb5df6b9ab0af50fe1098a52fd439b04730b6e066887ff7497357b9ebd19f79b "
50+ url "https://www.pypi.org/packages/source/p/pip/pip-21.2.1 .tar.gz"
51+ sha256 "303a82aaa24cdc01f7ebbd1afc7d1b871a4aa0a88bb5bedef1fa86a3ee44ca0a "
4952 end
5053
5154 resource "wheel" do
@@ -59,6 +62,19 @@ class PythonAT38 < Formula
5962 sha256 "104083617f086375974908f619369cd64005d5ffc314038c31b8b49032280148"
6063 end
6164
65+ def lib_cellar
66+ prefix /"Frameworks/Python.framework/Versions/#{ version . major_minor } /lib/python#{ version . major_minor } "
67+ end
68+
69+ def site_packages_cellar
70+ lib_cellar /"site-packages"
71+ end
72+
73+ # The HOMEBREW_PREFIX location of site-packages.
74+ def site_packages
75+ HOMEBREW_PREFIX /"lib/python#{ version . major_minor } /site-packages"
76+ end
77+
6278 def install
6379 # Unset these so that installing pip and setuptools puts them where we want
6480 # and not into some other Python the user has installed.
@@ -70,9 +86,6 @@ def install
7086 ENV [ "PYTHON_DECIMAL_WITH_MACHINE" ] = Hardware ::CPU . arm? ? "uint128" : "x64"
7187 end
7288
73- xy = ( buildpath /"configure.ac" ) . read . slice ( /PYTHON_VERSION, (3\. \d )/ , 1 )
74- lib_cellar = prefix /"Frameworks/Python.framework/Versions/#{ xy } /lib/python#{ xy } "
75-
7689 args = %W[
7790 --prefix=#{ prefix }
7891 --enable-ipv6
@@ -86,18 +99,25 @@ def install
8699 --with-system-libmpdec
87100 ]
88101
89- cflags = [ "-I#{ HOMEBREW_PREFIX } /include" ]
90- ldflags = [ "-L#{ HOMEBREW_PREFIX } /lib" ]
91- cppflags = [ "-I#{ HOMEBREW_PREFIX } /include" ]
102+ # Python re-uses flags when building native modules.
103+ # Since we don't want native modules prioritizing the brew
104+ # include path, we move them to [C|LD]FLAGS_NODIST.
105+ # Note: Changing CPPFLAGS causes issues with dbm, so we
106+ # leave it as-is.
107+ cflags = [ ]
108+ cflags_nodist = [ "-I#{ HOMEBREW_PREFIX } /include" ]
109+ ldflags = [ ]
110+ ldflags_nodist = [ "-L#{ HOMEBREW_PREFIX } /lib" , "-Wl,-rpath,#{ HOMEBREW_PREFIX } /lib" ]
111+ cppflags = [ "-I#{ HOMEBREW_PREFIX } /include" ]
92112
93113 if MacOS . sdk_path_if_needed
94114 # Help Python's build system (setuptools/pip) to build things on SDK-based systems
95115 # The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
96- cflags << "-isysroot #{ MacOS . sdk_path } " << "-I #{ MacOS . sdk_path } /usr/include"
116+ cflags << "-isysroot #{ MacOS . sdk_path } "
97117 ldflags << "-isysroot #{ MacOS . sdk_path } "
98118 end
99119 # Avoid linking to libgcc https://mail.python.org/pipermail/python-dev/2012-February/116205.html
100- args << "MACOSX_DEPLOYMENT_TARGET=#{ MacOS . version . to_f } "
120+ args << "MACOSX_DEPLOYMENT_TARGET=#{ MacOS . version } "
101121
102122 args << "--with-tcltk-includes=-I#{ Formula [ "tcl-tk" ] . opt_include } "
103123 args << "--with-tcltk-libs=-L#{ Formula [ "tcl-tk" ] . opt_lib } -ltcl8.6 -ltk8.6"
@@ -106,7 +126,7 @@ def install
106126 # superenv makes cc always find includes/libs!
107127 inreplace "setup.py" ,
108128 "do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')" ,
109- "do_readline = '#{ Formula [ "readline" ] . opt_lib } /libhistory.dylib '"
129+ "do_readline = '#{ Formula [ "readline" ] . opt_lib } /#{ shared_library ( " libhistory" ) } '"
110130
111131 inreplace "setup.py" do |s |
112132 s . gsub! "sqlite_setup_debug = False" , "sqlite_setup_debug = True"
@@ -124,7 +144,9 @@ def install
124144 end
125145
126146 args << "CFLAGS=#{ cflags . join ( " " ) } " unless cflags . empty?
147+ args << "CFLAGS_NODIST=#{ cflags_nodist . join ( " " ) } " unless cflags_nodist . empty?
127148 args << "LDFLAGS=#{ ldflags . join ( " " ) } " unless ldflags . empty?
149+ args << "LDFLAGS_NODIST=#{ ldflags_nodist . join ( " " ) } " unless ldflags_nodist . empty?
128150 args << "CPPFLAGS=#{ cppflags . join ( " " ) } " unless cppflags . empty?
129151
130152 system "./configure" , *args
@@ -156,10 +178,10 @@ def install
156178 "\\ 1'#{ opt_prefix } /Frameworks/\\ 2'"
157179
158180 # Symlink the pkgconfig files into HOMEBREW_PREFIX so they're accessible.
159- ( lib /"pkgconfig" ) . install_symlink Dir [ "#{ frameworks } /Python.framework/Versions/#{ xy } /lib/pkgconfig/*" ]
181+ ( lib /"pkgconfig" ) . install_symlink Dir [ "#{ frameworks } /Python.framework/Versions/#{ version . major_minor } /lib/pkgconfig/*" ]
160182
161183 # Remove the site-packages that Python created in its Cellar.
162- ( prefix / "Frameworks/Python.framework/Versions/ #{ xy } /lib/python #{ xy } /site-packages" ) . rmtree
184+ site_packages_cellar . rmtree
163185
164186 %w[ setuptools pip wheel ] . each do |r |
165187 ( libexec /r ) . install resource ( r )
@@ -184,14 +206,10 @@ def install
184206 def post_install
185207 ENV . delete "PYTHONPATH"
186208
187- xy = ( prefix /"Frameworks/Python.framework/Versions" ) . children . min . basename . to_s
188- site_packages = HOMEBREW_PREFIX /"lib/python#{ xy } /site-packages"
189- site_packages_cellar = prefix /"Frameworks/Python.framework/Versions/#{ xy } /lib/python#{ xy } /site-packages"
190-
191209 # Fix up the site-packages so that user-installed Python software survives
192210 # minor updates, such as going from 3.3.2 to 3.3.3:
193211
194- # Create a site-packages in HOMEBREW_PREFIX/lib/python#{xy }/site-packages
212+ # Create a site-packages in HOMEBREW_PREFIX/lib/python#{version.major_minor }/site-packages
195213 site_packages . mkpath
196214
197215 # Symlink the prefix site-packages into the cellar.
@@ -220,7 +238,7 @@ def post_install
220238 end
221239 end
222240
223- rm_rf [ bin /"pip" ]
241+ rm_rf [ bin /"pip" , bin / "easy_install" ]
224242 mv bin /"wheel" , bin /"wheel3"
225243
226244 # Create symlink python3 -> python3.8 (due to use of altinstall and conflict with python@3.8 formulae)
@@ -240,7 +258,7 @@ def post_install
240258 library_dirs = [ HOMEBREW_PREFIX /"lib" , Formula [ "openssl@1.1" ] . opt_lib ,
241259 Formula [ "sqlite" ] . opt_lib ] , Formula [ "tcl-tk" ] . opt_lib
242260
243- cfg = prefix / "Frameworks/Python.framework/Versions/ #{ xy } /lib/python #{ xy } / distutils/distutils.cfg"
261+ cfg = lib_cellar / " distutils/distutils.cfg"
244262
245263 cfg . atomic_write <<~EOS
246264 [install]
@@ -252,8 +270,6 @@ def post_install
252270 end
253271
254272 def sitecustomize
255- xy = ( prefix /"Frameworks/Python.framework/Versions" ) . children . min . basename . to_s
256-
257273 <<~EOS
258274 # This file is created by Homebrew and is executed on each python startup.
259275 # Don't print from here, or else python command line scripts may fail!
@@ -273,53 +289,51 @@ def sitecustomize
273289 # Only do this for a brewed python:
274290 if os.path.realpath(sys.executable).startswith('#{ rack } '):
275291 # Shuffle /Library site-packages to the end of sys.path
276- library_site = '/Library/Python/#{ xy } /site-packages'
292+ library_site = '/Library/Python/#{ version . major_minor } /site-packages'
277293 library_packages = [p for p in sys.path if p.startswith(library_site)]
278294 sys.path = [p for p in sys.path if not p.startswith(library_site)]
279295 # .pth files have already been processed so don't use addsitedir
280296 sys.path.extend(library_packages)
281297 # the Cellar site-packages is a symlink to the HOMEBREW_PREFIX
282298 # site_packages; prefer the shorter paths
283- long_prefix = re.compile(r'#{ rack } /[0-9\. _abrc]+/Frameworks/Python\. framework/Versions/#{ xy } /lib/python#{ xy } /site-packages')
284- sys.path = [long_prefix.sub('#{ HOMEBREW_PREFIX /"lib/python#{ xy } /site-packages" } ', p) for p in sys.path]
299+ long_prefix = re.compile(r'#{ rack } /[0-9\. _abrc]+/Frameworks/Python\. framework/Versions/#{ version . major_minor } /lib/python#{ version . major_minor } /site-packages')
300+ sys.path = [long_prefix.sub('#{ HOMEBREW_PREFIX /"lib/python#{ version . major_minor } /site-packages" } ', p) for p in sys.path]
285301 # Set the sys.executable to use the opt_prefix. Only do this if PYTHONEXECUTABLE is not
286302 # explicitly set and we are not in a virtualenv:
287303 if 'PYTHONEXECUTABLE' not in os.environ and sys.prefix == sys.base_prefix:
288- sys.executable = '#{ opt_bin } /python#{ xy } '
304+ sys.executable = '#{ opt_bin } /python#{ version . major_minor } '
289305 EOS
290306 end
291307
292308 def caveats
293- xy = if prefix . exist?
294- ( prefix /"Frameworks/Python.framework/Versions" ) . children . min . basename . to_s
295- else
296- version . to_s . slice ( /(3\. \d )/ ) || "3.8"
297- end
298309 <<~EOS
299310 Python has been installed as
300311 #{ opt_bin } /python3.8
301312
313+ Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
314+ `python3`, `python3-config`, `pip3` etc., respectively, have been installed into
315+ #{ opt_libexec } /bin
316+
302317 You can install Python packages with
303- #{ opt_bin } /pip3.8 install <package>
318+ #{ opt_bin } /pip3 install <package>
304319 They will install into the site-package directory
305- #{ prefix / "Frameworks/Python.framework/Versions/ #{ xy } / lib/python#{ xy } /site-packages"}
320+ #{ HOMEBREW_PREFIX / " lib/python#{ version . major_minor } /site-packages"}
306321
307322 See: https://docs.brew.sh/Homebrew-and-Python
308323 EOS
309324 end
310325
311326 test do
312- xy = ( prefix /"Frameworks/Python.framework/Versions" ) . children . min . basename . to_s
313327 # Check if sqlite is ok, because we build with --enable-loadable-sqlite-extensions
314328 # and it can occur that building sqlite silently fails if OSX's sqlite is used.
315- system "#{ bin } /python#{ xy } " , "-c" , "import sqlite3"
329+ system "#{ bin } /python#{ version . major_minor } " , "-c" , "import sqlite3"
316330 # Check if some other modules import. Then the linked libs are working.
317- system "#{ bin } /python#{ xy } " , "-c" , "import _decimal"
318- system "#{ bin } /python#{ xy } " , "-c" , "import tkinter; root = tkinter.Tk()"
331+ system "#{ bin } /python#{ version . major_minor } " , "-c" , "import _decimal"
332+ system "#{ bin } /python#{ version . major_minor } " , "-c" , "import tkinter; root = tkinter.Tk()"
319333
320- system "#{ bin } /python#{ xy } " , "-c" , "import _gdbm"
321- system "#{ bin } /python#{ xy } " , "-c" , "import zlib"
322- system "#{ bin } /python#{ xy } " , "-c" , "import ssl"
323- system bin / "pip3.8 ", "list" , "--format=columns"
334+ system "#{ bin } /python#{ version . major_minor } " , "-c" , "import _gdbm"
335+ system "#{ bin } /python#{ version . major_minor } " , "-c" , "import zlib"
336+ system "#{ bin } /python#{ version . major_minor } " , "-c" , "import ssl"
337+ system " #{ bin } /pip #{ version . major_minor } ", "list" , "--format=columns"
324338 end
325339end
0 commit comments