diff options
| author | samueljohn | 2012-10-01 15:20:59 +0200 |
|---|---|---|
| committer | Max Howell | 2012-10-01 10:14:42 -0400 |
| commit | 2a09cbe0dcad7d310b0041c0f5f0da9adb0768d1 (patch) | |
| tree | 39d9debd57ebea1e829ef0fe6abfc7a37c74055a /Library/Formula/python.rb | |
| parent | 64138ef5e5c12d0d044f0242de93b48566dcf004 (diff) | |
| download | homebrew-2a09cbe0dcad7d310b0041c0f5f0da9adb0768d1.tar.bz2 | |
python: Fix site-packages installs via pip (& co.)
- Removed accidently added -py-debug
- Ensure HOMEBREW_PREFIX/share/python exists as a dir
- Don't change the sys.prefix (broke virtualenv)
and instead add install-lib dir to distutils.cfg.
superenv respects brewed python
Closes #15220.
Signed-off-by: Max Howell <mxcl@me.com>
Diffstat (limited to 'Library/Formula/python.rb')
| -rw-r--r-- | Library/Formula/python.rb | 149 |
1 files changed, 78 insertions, 71 deletions
diff --git a/Library/Formula/python.rb b/Library/Formula/python.rb index d26078114..5da970295 100644 --- a/Library/Formula/python.rb +++ b/Library/Formula/python.rb @@ -81,64 +81,16 @@ class Python < Formula ] args << '--without-gcc' if ENV.compiler == :clang - args << '--with-pydebug' if ENV.compiler == :clang # http://bugs.python.org/issue13370 args << '--with-dtrace' if build.include? 'with-dtrace' - if superenv? - # To allow certain Python bindings to find brewed software: - cflags = "CFLAGS=-I#{HOMEBREW_PREFIX}/include" - ldflags = "LDFLAGS=-L#{HOMEBREW_PREFIX}/lib" - unless MacOS::CLT.installed? - # Help Python's build system (distribute/pip) to build things on Xcode-only 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}" - # Same zlib.h-not-found-bug as in env :std (see below) - args << "CPPFLAGS=-I#{MacOS.sdk_path}/usr/include" - end - args << cflags - args << ldflags - # Avoid linking to libgcc http://code.activestate.com/lists/python-dev/112195/ - args << "MACOSX_DEPLOYMENT_TARGET=#{MacOS.version}" - # We want our readline! This is just to outsmart the detection code, - # superenv handles that cc finds includes/libs! - inreplace "setup.py", - "do_readline = self.compiler.find_library_file(lib_dirs, 'readline')", - "do_readline = '#{HOMEBREW_PREFIX}/opt/readline/lib/libhistory.dylib'" - - else - # This is obsolte with superenv (superenv defaults to -Os and does not - # disable warnings), but to support --env=std we leave it here: - - # Python scans all "-I" dirs but not "-isysroot", so we add - # the needed includes with "-I" here to avoid this err: - # building dbm using ndbm - # error: /usr/include/zlib.h: No such file or directory - ENV.append 'CPPFLAGS', "-I#{MacOS.sdk_path}/usr/include" unless MacOS::CLT.installed? - - # Don't use optimizations other than "-Os" here, because Python's distutils - # remembers (hint: `python-config --cflags`) and reuses them for C - # extensions which can break software (such as scipy 0.11 fails when - # "-msse4" is present.) - ENV.minimal_optimization - - # We need to enable warnings because the configure.in uses -Werror to detect - # "whether gcc supports ParseTuple" (https://github.com/mxcl/homebrew/issues/12194) - ENV.enable_warnings - if ENV.compiler == :clang - # http://docs.python.org/devguide/setup.html#id8 suggests to disable some Warnings. - ENV.append_to_cflags '-Wno-unused-value' - ENV.append_to_cflags '-Wno-empty-body' - ENV.append_to_cflags '-Qunused-arguments' - end - end + distutils_fix_superenv(args) + distutils_fix_stdenv if build.universal? args << "--enable-universalsdk=/" << "--with-universal-archs=intel" end - # Allow sqlite3 module to load extensions: - # http://docs.python.org/library/sqlite3.html#f1 + # Allow sqlite3 module to load extensions: http://docs.python.org/library/sqlite3.html#f1 inreplace "setup.py", 'sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))', '' system "./configure", *args @@ -152,7 +104,8 @@ class Python < Formula ENV.deparallelize # Installs must be serialized # Tell Python not to install into /Applications (default for framework builds) system "make", "install", "PYTHONAPPSDIR=#{prefix}" - # Demos and Tools into HOMEBREW_PREFIX/share/python + # Demos and Tools + (HOMEBREW_PREFIX/'share/python').mkpath system "make", "frameworkinstallextras", "PYTHONAPPSDIR=#{share}/python" system "make", "quicktest" if build.include? 'quicktest' @@ -168,16 +121,17 @@ class Python < Formula ln_s site_packages, site_packages_cellar # Teach python not to use things from /System - # and teach it about the correct site-package dir because we moved it - sitecustomize = site_packages/"sitecustomize.py" + # and tell it about the correct site-package dir because we moved it + sitecustomize = site_packages_cellar/"sitecustomize.py" rm sitecustomize if File.exist? sitecustomize sitecustomize.write <<-EOF.undent # This file is created by `brew install python` and is executed on each # python startup. Don't print from here, or else universe will collapse. import sys + import site - # Only do our fixes, if the currently run python is a brewed one. - if sys.executable.startswith("#{HOMEBREW_PREFIX}"): + # Only do fix 1 and 2, if the currently run python is a brewed one. + if sys.executable.startswith('#{HOMEBREW_PREFIX}'): # Fix 1) # A setuptools.pth and/or easy-install.pth sitting either in # /Library/Python/2.7/site-packages or in @@ -190,18 +144,29 @@ class Python < Formula sys.path = [ p for p in sys.path if not p.startswith('/System') ] # Fix 2) - # pip install records installed files with relative paths and - # because Homebrew installs python into #{HOMEBREW_PREFIX}/Cellar, - # the symlinks for the executable python scripts is not correct, so - # they are not uninstalled when `pip uninstall <x>` is called. - # See: https://github.com/mxcl/homebrew/issues/14688 - sys.prefix = "#{HOMEBREW_PREFIX}" + # Remove brewed Python's hard-coded site-packages + sys.path.remove('#{site_packages_cellar}') + + # Fix 3) + # For all Pythons: Tell about homebrew's site-packages location. + # This is needed for for Python to parse *.pth files. + site.addsitedir('#{site_packages}') EOF - # Tell distutils-based installers where to put scripts + # Install distribute and pip + # It's important to have these installers in our bin, because some users + # forget to put #{script_folder} in PATH, then easy_install'ing + # into /Library/Python/X.Y/site-packages with /usr/bin/easy_install. + mkdir_p scripts_folder unless scripts_folder.exist? + setup_args = ["-s", "setup.py", "--no-user-cfg", "install", "--force", "--verbose", "--install-lib=#{site_packages_cellar}", "--install-scripts=#{bin}" ] + Distribute.new.brew { system "#{bin}/python", *setup_args } + Pip.new.brew { system "#{bin}/python", *setup_args } + + # Tell distutils-based installers where to put scripts and python modules (prefix/"Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/distutils.cfg").write <<-EOF.undent [install] install-scripts=#{scripts_folder} + install-lib=#{site_packages} EOF unless MacOS::CLT.installed? @@ -214,15 +179,57 @@ class Python < Formula end end - # Install distribute and pip - setup_args = ["-s", "setup.py", "--no-user-cfg", "install", "--force", "--verbose"] - Distribute.new.brew { system "#{bin}/python", *setup_args } - Pip.new.brew { system "#{bin}/python", *setup_args } + end - # It's important to have these installers in our bin, because some users - # forget to put #{script_folder} in PATH, then easy_install'ing - # into /Library/Python/X.Y/site-packages with /usr/bin/easy_install. - ['pip', 'pip-2.7', 'easy_install', 'easy_install-2.7'].each { |b| mv scripts_folder/b, bin } + def distutils_fix_superenv(args) + if superenv? + # To allow certain Python bindings to find brewed software: + cflags = "CFLAGS=-I#{HOMEBREW_PREFIX}/include" + ldflags = "LDFLAGS=-L#{HOMEBREW_PREFIX}/lib" + unless MacOS::CLT.installed? + # Help Python's build system (distribute/pip) to build things on Xcode-only 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}" + # Same zlib.h-not-found-bug as in env :std (see below) + args << "CPPFLAGS=-I#{MacOS.sdk_path}/usr/include" + end + args << cflags + args << ldflags + # Avoid linking to libgcc http://code.activestate.com/lists/python-dev/112195/ + args << "MACOSX_DEPLOYMENT_TARGET=#{MacOS.version}" + # We want our readline! This is just to outsmart the detection code, + # superenv handles that cc finds includes/libs! + inreplace "setup.py", + "do_readline = self.compiler.find_library_file(lib_dirs, 'readline')", + "do_readline = '#{HOMEBREW_PREFIX}/opt/readline/lib/libhistory.dylib'" + end + end + + def distutils_fix_stdenv() + if not superenv? + # Python scans all "-I" dirs but not "-isysroot", so we add + # the needed includes with "-I" here to avoid this err: + # building dbm using ndbm + # error: /usr/include/zlib.h: No such file or directory + ENV.append 'CPPFLAGS', "-I#{MacOS.sdk_path}/usr/include" unless MacOS::CLT.installed? + + # Don't use optimizations other than "-Os" here, because Python's distutils + # remembers (hint: `python3-config --cflags`) and reuses them for C + # extensions which can break software (such as scipy 0.11 fails when + # "-msse4" is present.) + ENV.minimal_optimization + + # We need to enable warnings because the configure.in uses -Werror to detect + # "whether gcc supports ParseTuple" (https://github.com/mxcl/homebrew/issues/12194) + ENV.enable_warnings + if ENV.compiler == :clang + # http://docs.python.org/devguide/setup.html#id8 suggests to disable some Warnings. + ENV.append_to_cflags '-Wno-unused-value' + ENV.append_to_cflags '-Wno-empty-body' + ENV.append_to_cflags '-Qunused-arguments' + end + end end def caveats |
