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 Homebrew/homebrew#14689.
Closes Homebrew/homebrew#14686.

Signed-off-by: Adam Vandenberg <flangy@gmail.com>
master
samueljohn 2012-09-04 13:31:42 +02:00 committed by Adam Vandenberg
parent 224a9597d5
commit 26a1cdbf7a
2 changed files with 30 additions and 6 deletions

View File

@ -21,8 +21,8 @@ class Distribute < Formula
end
class Pip < Formula
url 'http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz'
sha1 '842c4e2aff3f016feea3c6e992c7fa96e49c9aa0'
url 'http://pypi.python.org/packages/source/p/pip/pip-1.2.tar.gz'
sha1 '7876f943cfbb0bbb725c2761879de2889c1fe93b'
end
class Python < Formula
@ -62,6 +62,11 @@ class Python < 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
@ -72,6 +77,12 @@ class Python < 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
@ -85,6 +96,7 @@ class Python < 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
if build.universal?
@ -128,8 +140,8 @@ class Python < Formula
EOF
# Install distribute and pip
Distribute.new.brew { system "#{bin}/python", "setup.py", "install" }
Pip.new.brew { system "#{bin}/python", "setup.py", "install" }
Distribute.new.brew { system "#{bin}/python", "setup.py", "--no-user-cfg", "install", "--force" }
Pip.new.brew { system "#{bin}/python", "setup.py", "--no-user-cfg", "install", "--force" }
end
def caveats

View File

@ -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