From f20d35ac2f94c4bcb87dcd748ed46c18cabdc8f5 Mon Sep 17 00:00:00 2001 From: samueljohn Date: Tue, 4 Sep 2012 13:31:42 +0200 Subject: python2/3: Harden against other pythons. Pip 1.2 - Unset PYTHONPATH and PYTHONHOME which would lead to install distribute and pip into the wrong python. - For NCLT: Add to CPPFLAGS the path to zlib via -I because python's setup.py scans only these flags. - '-Qunused-arguments' can be added after ENV.enable_warnings to reduce noise. The only thing which we must not add is the "-w" switch! - For python.rb only: Pass "--no-user-cfg" to python setup.py and add --force when installing distribute and pip to ensure overwriting with the new ones. Closes #14689. Closes #14686. Signed-off-by: Adam Vandenberg --- Library/Formula/python3.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Library/Formula/python3.rb') diff --git a/Library/Formula/python3.rb b/Library/Formula/python3.rb index c350de465..37f31b787 100644 --- a/Library/Formula/python3.rb +++ b/Library/Formula/python3.rb @@ -53,6 +53,11 @@ class Python3 < Formula end def install + # Unset these so that installing pip and distribute puts them where we want + # and not into some other Python the user has installed. + ENV['PYTHONPATH'] = nil + ENV['PYTHONHOME'] = nil + args = %W[--prefix=#{prefix} --enable-ipv6 --datarootdir=#{share} @@ -62,6 +67,12 @@ class Python3 < Formula args << '--without-gcc' if ENV.compiler == :clang + # Further, 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 @@ -75,6 +86,7 @@ class Python3 < Formula # 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 # Allow sqlite3 module to load extensions: @@ -117,14 +129,14 @@ class Python3 < Formula # Install distribute for python3 Distribute.new.brew do - system "#{bin}/python3.2", "setup.py", "install" + system "#{bin}/python3.2", "setup.py", "install", "--force" # Symlink to easy_install3 to match python3 command. unless (scripts_folder/'easy_install3').exist? ln_s scripts_folder/"easy_install", scripts_folder/"easy_install3" end end # Install pip-3.2 for python3 - Pip.new.brew { system "#{bin}/python3.2", "setup.py", "install" } + Pip.new.brew { system "#{bin}/python3.2", "setup.py", "install", "--force" } end def caveats -- cgit v1.2.3