python: stop shadowing system python.
Use the `python2` etc. binaries instead and provide a link to `python` in a directory not in the `PATH` by default.
This commit is contained in:
parent
97650f8940
commit
e7f4e1c03a
3 changed files with 36 additions and 13 deletions
1
Aliases/python2
Symbolic link
1
Aliases/python2
Symbolic link
|
@ -0,0 +1 @@
|
|||
../Formula/python.rb
|
1
Aliases/python@2
Symbolic link
1
Aliases/python@2
Symbolic link
|
@ -0,0 +1 @@
|
|||
../Formula/python.rb
|
|
@ -3,6 +3,7 @@ class Python < Formula
|
|||
homepage "https://www.python.org"
|
||||
url "https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz"
|
||||
sha256 "35d543986882f78261f97787fd3e06274bfa6df29fac9b4a94f73930ff98f731"
|
||||
revision 1
|
||||
head "https://github.com/python/cpython.git", :branch => "2.7"
|
||||
|
||||
bottle do
|
||||
|
@ -36,9 +37,6 @@ class Python < Formula
|
|||
depends_on "tcl-tk" => :optional
|
||||
depends_on "berkeley-db@4" => :optional
|
||||
|
||||
skip_clean "bin/pip", "bin/pip-2.7"
|
||||
skip_clean "bin/easy_install", "bin/easy_install-2.7"
|
||||
|
||||
resource "setuptools" do
|
||||
url "https://files.pythonhosted.org/packages/26/d1/dc7fe14ce4a3ff3faebf1ac11350de4104ea2d2a80c98393b55c84362b0c/setuptools-32.1.0.tar.gz"
|
||||
sha256 "86d57bf86edc0ecfd2dc0907ed3710bc4501fb13a06c0fcaf7632305b00ce832"
|
||||
|
@ -152,7 +150,7 @@ class Python < Formula
|
|||
|
||||
# Allow python modules to use ctypes.find_library to find homebrew's stuff
|
||||
# even if homebrew is not a /usr/local/lib. Try this with:
|
||||
# `brew install enchant && pip install pyenchant`
|
||||
# `brew install enchant && pip2 install pyenchant`
|
||||
inreplace "./Lib/ctypes/macholib/dyld.py" do |f|
|
||||
f.gsub! "DEFAULT_LIBRARY_FALLBACK = [", "DEFAULT_LIBRARY_FALLBACK = [ '#{HOMEBREW_PREFIX}/lib',"
|
||||
f.gsub! "DEFAULT_FRAMEWORK_FALLBACK = [", "DEFAULT_FRAMEWORK_FALLBACK = [ '#{HOMEBREW_PREFIX}/Frameworks',"
|
||||
|
@ -218,6 +216,24 @@ class Python < Formula
|
|||
doc.install Dir["build/html/*"]
|
||||
end
|
||||
end
|
||||
|
||||
# Remove commands shadowing system python.
|
||||
{
|
||||
"2to3" => "2to3-2",
|
||||
"easy_install" => "easy_install-2.7",
|
||||
"idle" => "idle2",
|
||||
"pip" => "pip2",
|
||||
"pydoc" => "pydoc2",
|
||||
"python" => "python2",
|
||||
"python-config" => "python2-config",
|
||||
"pythonw" => "pythonw2",
|
||||
"smtpd.py" => "smtpd2.py",
|
||||
"wheel" => nil,
|
||||
}.each do |unversioned_name, versioned_name|
|
||||
rm_f bin/unversioned_name
|
||||
next unless versioned_name
|
||||
(libexec/"bin").install_symlink bin/versioned_name => unversioned_name
|
||||
end
|
||||
end
|
||||
|
||||
def post_install
|
||||
|
@ -250,13 +266,13 @@ class Python < Formula
|
|||
"--install-scripts=#{bin}",
|
||||
"--install-lib=#{site_packages}"]
|
||||
|
||||
(libexec/"setuptools").cd { system "#{bin}/python", *setup_args }
|
||||
(libexec/"pip").cd { system "#{bin}/python", *setup_args }
|
||||
(libexec/"wheel").cd { system "#{bin}/python", *setup_args }
|
||||
(libexec/"setuptools").cd { system "#{bin}/python2", *setup_args }
|
||||
(libexec/"pip").cd { system "#{bin}/python2", *setup_args }
|
||||
(libexec/"wheel").cd { system "#{bin}/python2", *setup_args }
|
||||
|
||||
# When building from source, these symlinks will not exist, since
|
||||
# post_install happens after linking.
|
||||
%w[pip pip2 pip2.7 easy_install easy_install-2.7 wheel].each do |e|
|
||||
%w[pip2 pip2.7 easy_install-2.7].each do |e|
|
||||
(HOMEBREW_PREFIX/"bin").install_symlink bin/e
|
||||
end
|
||||
|
||||
|
@ -336,11 +352,16 @@ class Python < Formula
|
|||
end
|
||||
|
||||
def caveats; <<-EOS.undent
|
||||
This formula installs a python2 executable to #{HOMEBREW_PREFIX}/bin.
|
||||
If you wish to have this formula's python executable in your PATH then add
|
||||
the following to #{shell_profile}:
|
||||
export PATH="#{opt_libexec}/bin:$PATH"
|
||||
|
||||
Pip and setuptools have been installed. To update them
|
||||
pip install --upgrade pip setuptools
|
||||
pip2 install --upgrade pip setuptools
|
||||
|
||||
You can install Python packages with
|
||||
pip install <package>
|
||||
pip2 install <package>
|
||||
|
||||
They will install into the site-package directory
|
||||
#{site_packages}
|
||||
|
@ -352,9 +373,9 @@ class Python < Formula
|
|||
test do
|
||||
# Check if sqlite is ok, because we build with --enable-loadable-sqlite-extensions
|
||||
# and it can occur that building sqlite silently fails if OSX's sqlite is used.
|
||||
system "#{bin}/python", "-c", "import sqlite3"
|
||||
system "#{bin}/python2", "-c", "import sqlite3"
|
||||
# Check if some other modules import. Then the linked libs are working.
|
||||
system "#{bin}/python", "-c", "import Tkinter; root = Tkinter.Tk()"
|
||||
system bin/"pip", "list"
|
||||
system "#{bin}/python2", "-c", "import Tkinter; root = Tkinter.Tk()"
|
||||
system bin/"pip2", "list"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue