11 Fork 245alephobjects/Cura
13 branch: SteamEngine Cura / scripts / darwin / python.rb
14 aaronaskewaaronaskew 14 hours ago Updated homebrew python formula to newest official and changed MACOSX…
15 2 contributors Ilya Kulakovaaronaskew
16 383 lines (324 sloc) 15.644 kb RawBlameHistory
19 class Python < Formula
20 homepage "https://www.python.org"
21 head "https://hg.python.org/cpython", :using => :hg, :branch => "2.7"
22 url "https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz"
23 sha1 "511960dd78451a06c9df76509635aeec05b2051a"
27 sha1 "b84f255563bb7c86c15329b534d64ab2c8fcb7ba" => :mavericks
28 sha1 "8921690c3c855ab0a06c76d8c4a2cdf9702b9fdb" => :mountain_lion
29 sha1 "61d735d94ae8e84c9fdc3bba2af16233aaabda29" => :lion
33 option "quicktest", "Run `make quicktest` after the build (for devs; may fail)"
34 option "with-brewed-tk", "Use Homebrew's Tk (has optional Cocoa and threads support)"
35 option "with-poll", "Enable select.poll, which is not fully implemented on OS X (http://bugs.python.org/issue5154)"
36 option "with-dtrace", "Experimental DTrace support (http://bugs.python.org/issue13405)"
38 depends_on "pkg-config" => :build
39 depends_on "readline" => :recommended
40 depends_on "sqlite" => :recommended
41 depends_on "gdbm" => :recommended
43 depends_on "homebrew/dupes/tcl-tk" if build.with? "brewed-tk"
44 depends_on :x11 if build.with? "brewed-tk" and Tab.for_name("tcl-tk").with? "x11"
46 skip_clean "bin/pip", "bin/pip-2.7"
47 skip_clean "bin/easy_install", "bin/easy_install-2.7"
49 resource "setuptools" do
50 url "https://pypi.python.org/packages/source/s/setuptools/setuptools-5.4.2.tar.gz"
51 sha1 "a681ba56c30c0eb66528215842d3e3fcb5157614"
55 url "https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz"
56 sha1 "e6cd9e6f2fd8d28c9976313632ef8aa8ac31249e"
59 # Patch for pyport.h macro issue
60 # http://bugs.python.org/issue10910
61 # https://trac.macports.org/ticket/44288
63 url "http://bugs.python.org/file30805/issue10910-workaround.txt"
64 sha1 "9926640cb7c8e273e4b451469a2b13d4b9df5ba3"
67 # Patch to disable the search for Tk.framework, since Homebrew's Tk is
68 # a plain unix build. Remove `-lX11`, too because our Tk is "AquaTk".
69 patch :DATA if build.with? "brewed-tk"
72 prefix/"Frameworks/Python.framework/Versions/2.7/lib/python2.7"
75 def site_packages_cellar
76 lib_cellar/"site-packages"
79 # The HOMEBREW_PREFIX location of site-packages.
81 HOMEBREW_PREFIX/"lib/python2.7/site-packages"
84 # setuptools remembers the build flags python is built with and uses them to
85 # build packages later. Xcode-only systems need different flags.
92 opoo "The given option --with-poll enables a somewhat broken poll() on OS X (http://bugs.python.org/issue5154)."
95 # Unset these so that installing pip and setuptools puts them where we want
96 # and not into some other Python the user has installed.
97 ENV["PYTHONHOME"] = nil
98 ENV["PYTHONPATH"] = nil
103 --datarootdir=#{share}
105 --enable-framework=#{frameworks}
108 args << "--without-gcc" if ENV.compiler == :clang
109 args << "--with-dtrace" if build.with? "dtrace"
112 distutils_fix_superenv(args)
119 args << "--enable-universalsdk=/" << "--with-universal-archs=intel"
122 # Allow sqlite3 module to load extensions:
123 # http://docs.python.org/library/sqlite3.html#f1
124 if build.with? "sqlite"
125 inreplace("setup.py", 'sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))', '')
128 # Allow python modules to use ctypes.find_library to find homebrew's stuff
129 # even if homebrew is not a /usr/local/lib. Try this with:
130 # `brew install enchant && pip install pyenchant`
131 inreplace "./Lib/ctypes/macholib/dyld.py" do |f|
132 f.gsub! 'DEFAULT_LIBRARY_FALLBACK = [', "DEFAULT_LIBRARY_FALLBACK = [ '#{HOMEBREW_PREFIX}/lib',"
133 f.gsub! 'DEFAULT_FRAMEWORK_FALLBACK = [', "DEFAULT_FRAMEWORK_FALLBACK = [ '#{HOMEBREW_PREFIX}/Frameworks',"
136 if build.with? "brewed-tk"
137 tcl_tk = Formula["tcl-tk"].opt_prefix
138 ENV.append "CPPFLAGS", "-I#{tcl_tk}/include"
139 ENV.append "LDFLAGS", "-L#{tcl_tk}/lib"
142 system "./configure", *args
144 # HAVE_POLL is "broken" on OS X. See:
145 # http://trac.macports.org/ticket/18376
146 # http://bugs.python.org/issue5154
147 if build.without? "poll"
148 inreplace "pyconfig.h", /.*?(HAVE_POLL[_A-Z]*).*/, '#undef \1'
153 ENV.deparallelize # installs must be serialized
154 # Tell Python not to install into /Applications
155 system "make", "install", "PYTHONAPPSDIR=#{prefix}"
157 system "make", "frameworkinstallextras", "PYTHONAPPSDIR=#{share}/python"
158 system "make", "quicktest" if build.include? 'quicktest'
160 # Fixes setting Python build flags for certain software
161 # See: https://github.com/Homebrew/homebrew/pull/20182
162 # http://bugs.python.org/issue3588
163 inreplace lib_cellar/"config/Makefile" do |s|
164 s.change_make_var! "LINKFORSHARED",
165 "-u _PyMac_Error $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)"
168 # Remove the site-packages that Python created in its Cellar.
169 site_packages_cellar.rmtree
171 (libexec/'setuptools').install resource('setuptools')
172 (libexec/'pip').install resource('pip')
176 # Fix up the site-packages so that user-installed Python software survives
177 # minor updates, such as going from 2.7.0 to 2.7.1:
179 # Create a site-packages in HOMEBREW_PREFIX/lib/python2.7/site-packages
182 # Symlink the prefix site-packages into the cellar.
183 site_packages_cellar.unlink if site_packages_cellar.exist?
184 site_packages_cellar.parent.install_symlink site_packages
186 # Write our sitecustomize.py
187 rm_rf Dir["#{site_packages}/sitecustomize.py[co]"]
188 (site_packages/"sitecustomize.py").atomic_write(sitecustomize)
190 # Remove old setuptools installations that may still fly around and be
191 # listed in the easy_install.pth. This can break setuptools build with
192 # zipimport.ZipImportError: bad local file header
193 # setuptools-0.9.5-py3.3.egg
194 rm_rf Dir["#{site_packages}/setuptools*"]
195 rm_rf Dir["#{site_packages}/distribute*"]
197 setup_args = ["-s", "setup.py", "--no-user-cfg", "install", "--force",
199 "--install-scripts=#{bin}",
200 "--install-lib=#{site_packages}"]
202 (libexec/"setuptools").cd { system "#{bin}/python", *setup_args }
203 (libexec/"pip").cd { system "#{bin}/python", *setup_args }
205 # When building from source, these symlinks will not exist, since
206 # post_install happens after linking.
207 %w[pip pip2 pip2.7 easy_install easy_install-2.7].each do |e|
208 (HOMEBREW_PREFIX/"bin").install_symlink bin/e
211 # And now we write the distutils.cfg
212 cfg = lib_cellar/"distutils/distutils.cfg"
213 cfg.atomic_write <<-EOF.undent
218 prefix=#{HOMEBREW_PREFIX}
222 def distutils_fix_superenv(args)
223 # This is not for building python itself but to allow Python's build tools
224 # (pip) to find brewed stuff when installing python packages.
225 sqlite = Formula["sqlite"].opt_prefix
226 cflags = "CFLAGS=-I#{HOMEBREW_PREFIX}/include -I#{sqlite}/include"
227 ldflags = "LDFLAGS=-L#{HOMEBREW_PREFIX}/lib -L#{sqlite}/lib"
228 if build.with? "brewed-tk"
229 tcl_tk = Formula["tcl-tk"].opt_prefix
230 cflags += " -I#{tcl_tk}/include"
231 ldflags += " -L#{tcl_tk}/lib"
233 unless MacOS::CLT.installed?
234 # Help Python's build system (setuptools/pip) to build things on Xcode-only systems
235 # The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
236 cflags += " -isysroot #{MacOS.sdk_path}"
237 ldflags += " -isysroot #{MacOS.sdk_path}"
238 args << "CPPFLAGS=-I#{MacOS.sdk_path}/usr/include" # find zlib
239 # For the Xlib.h, Python needs this header dir with the system Tk
240 if build.without? "brewed-tk"
241 cflags += " -I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
246 # Avoid linking to libgcc http://code.activestate.com/lists/python-dev/112195/
247 args << "MACOSX_DEPLOYMENT_TARGET=10.6"
248 # We want our readline! This is just to outsmart the detection code,
249 # superenv handles that cc finds includes/libs!
250 inreplace "setup.py",
251 "do_readline = self.compiler.find_library_file(lib_dirs, 'readline')",
252 "do_readline = '#{HOMEBREW_PREFIX}/opt/readline/lib/libhistory.dylib'"
255 def distutils_fix_stdenv
256 # Python scans all "-I" dirs but not "-isysroot", so we add
257 # the needed includes with "-I" here to avoid this err:
258 # building dbm using ndbm
259 # error: /usr/include/zlib.h: No such file or directory
260 ENV.append "CPPFLAGS", "-I#{MacOS.sdk_path}/usr/include" unless MacOS::CLT.installed?
262 # Don't use optimizations other than "-Os" here, because Python's distutils
263 # remembers (hint: `python-config --cflags`) and reuses them for C
264 # extensions which can break software (such as scipy 0.11 fails when
265 # "-msse4" is present.)
266 ENV.minimal_optimization
268 # We need to enable warnings because the configure.in uses -Werror to detect
269 # "whether gcc supports ParseTuple" (https://github.com/Homebrew/homebrew/issues/12194)
271 if ENV.compiler == :clang
272 # http://docs.python.org/devguide/setup.html#id8 suggests to disable some Warnings.
273 ENV.append_to_cflags "-Wno-unused-value"
274 ENV.append_to_cflags "-Wno-empty-body"
280 # This file is created by Homebrew and is executed on each python startup.
281 # Don't print from here, or else python command line scripts may fail!
282 # <https://github.com/Homebrew/homebrew/wiki/Homebrew-and-Python>
286 if sys.version_info[0] != 2:
287 # This can only happen if the user has set the PYTHONPATH for 3.x and run Python 2.x or vice versa.
288 # Every Python looks at the PYTHONPATH variable and we can't fix it here in sitecustomize.py,
289 # because the PYTHONPATH is evaluated after the sitecustomize.py. Many modules (e.g. PyQt4) are
290 # built only for a specific version of Python and will fail with cryptic error messages.
291 # In the end this means: Don't set the PYTHONPATH permanently if you use different Python versions.
292 exit('Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python ' +
293 str(sys.version_info[0]) + '.x!\\n PYTHONPATH is currently: "' + str(os.environ['PYTHONPATH']) + '"\\n' +
294 ' You should `unset PYTHONPATH` to fix this.')
296 # Only do this for a brewed python:
297 opt_executable = '#{opt_bin}/python2.7'
298 if os.path.commonprefix([os.path.realpath(e) for e in [opt_executable, sys.executable]]).startswith('#{rack}'):
299 # Remove /System site-packages, and the Cellar site-packages
300 # which we moved to lib/pythonX.Y/site-packages. Further, remove
301 # HOMEBREW_PREFIX/lib/python because we later addsitedir(...).
302 sys.path = [ p for p in sys.path
303 if (not p.startswith('/System') and
304 not p.startswith('#{HOMEBREW_PREFIX}/lib/python') and
305 not (p.startswith('#{rack}') and p.endswith('site-packages'))) ]
307 # LINKFORSHARED (and python-config --ldflags) return the
308 # full path to the lib (yes, "Python" is actually the lib, not a
309 # dir) so that third-party software does not need to add the
310 # -F/#{HOMEBREW_PREFIX}/Frameworks switch.
311 # Assume Framework style build (default since months in brew)
313 from _sysconfigdata import build_time_vars
314 build_time_vars['LINKFORSHARED'] = '-u _PyMac_Error #{opt_prefix}/Frameworks/Python.framework/Versions/2.7/Python'
316 pass # remember: don't print here. Better to fail silently.
318 # Set the sys.executable to use the opt_prefix
319 sys.executable = opt_executable
321 # Tell about homebrew's site-packages location.
322 # This is needed for Python to parse *.pth.
324 site.addsitedir('#{site_packages}')
328 def caveats; <<-EOS.undent
329 Setuptools and Pip have been installed. To update them
330 pip install --upgrade setuptools
331 pip install --upgrade pip
333 You can install Python packages with
334 pip install <package>
336 They will install into the site-package directory
339 See: https://github.com/Homebrew/homebrew/wiki/Homebrew-and-Python
344 # Check if sqlite is ok, because we build with --enable-loadable-sqlite-extensions
345 # and it can occur that building sqlite silently fails if OSX's sqlite is used.
346 system "#{bin}/python", "-c", "import sqlite3"
347 # Check if some other modules import. Then the linked libs are working.
348 system "#{bin}/python", "-c", "import Tkinter; root = Tkinter.Tk()"
353 diff --git a/setup.py b/setup.py
354 index 716f08e..66114ef 100644
357 @@ -1810,9 +1810,6 @@ class PyBuildExt(build_ext):
358 # Rather than complicate the code below, detecting and building
359 # AquaTk is a separate method. Only one Tkinter will be built on
360 # Darwin - either AquaTk, if it is found, or X11 based Tk.
361 - if (host_platform == 'darwin' and
362 - self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
365 # Assume we haven't found any of the libraries or include files
366 # The versions with dots are used on Unix, and the versions without
367 @@ -1858,21 +1855,6 @@ class PyBuildExt(build_ext):
368 if dir not in include_dirs:
369 include_dirs.append(dir)
371 - # Check for various platform-specific directories
372 - if host_platform == 'sunos5':
373 - include_dirs.append('/usr/openwin/include')
374 - added_lib_dirs.append('/usr/openwin/lib')
375 - elif os.path.exists('/usr/X11R6/include'):
376 - include_dirs.append('/usr/X11R6/include')
377 - added_lib_dirs.append('/usr/X11R6/lib64')
378 - added_lib_dirs.append('/usr/X11R6/lib')
379 - elif os.path.exists('/usr/X11R5/include'):
380 - include_dirs.append('/usr/X11R5/include')
381 - added_lib_dirs.append('/usr/X11R5/lib')
383 - # Assume default location for X11
384 - include_dirs.append('/usr/X11/include')
385 - added_lib_dirs.append('/usr/X11/lib')
387 # If Cygwin, then verify that X is installed before proceeding
388 if host_platform == 'cygwin':
389 @@ -1897,9 +1879,6 @@ class PyBuildExt(build_ext):
390 if host_platform in ['aix3', 'aix4']:
393 - # Finally, link with the X11 libraries (not appropriate on cygwin)
394 - if host_platform != "cygwin":
397 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
398 define_macros=[('WITH_APPINIT', 1)] + defs,
399 Status API Training Shop Blog About
400 © 2014 GitHub, Inc. Terms Privacy Security Contact