2010-04-17 18:50:15 +00:00
|
|
|
require 'formula'
|
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
# Python3 is the new language standard, not just a new revision.
|
|
|
|
# It's somewhat incompatible to Python 2.x, therefore, the executable
|
|
|
|
# "python" will always point to the 2.x version which you can get by
|
|
|
|
# `brew install python`.
|
|
|
|
|
|
|
|
class TkCheck < Requirement
|
|
|
|
def message; <<-EOS.undent
|
|
|
|
Tk.framework detected in /Library/Frameworks
|
|
|
|
and that can make python builds to fail.
|
|
|
|
https://github.com/mxcl/homebrew/issues/11602
|
|
|
|
EOS
|
|
|
|
end
|
2010-07-07 20:15:59 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
def fatal?; false; end
|
2010-07-07 20:15:59 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
def satisfied?
|
|
|
|
not File.exist? '/Library/Frameworks/Tk.framework'
|
|
|
|
end
|
2010-07-07 20:15:59 +00:00
|
|
|
end
|
|
|
|
|
2011-09-01 21:03:53 +00:00
|
|
|
class Distribute < Formula
|
2012-07-26 06:33:03 +00:00
|
|
|
url 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz'
|
|
|
|
md5 'b400b532e33f78551e6847c1f5965e56'
|
2011-09-01 21:03:53 +00:00
|
|
|
end
|
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
# Recommended way of installing python modules (http://pypi.python.org/pypi)
|
|
|
|
class Pip < Formula
|
|
|
|
url 'http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz'
|
|
|
|
md5 '62a9f08dd5dc69d76734568a6c040508'
|
|
|
|
end
|
|
|
|
|
2011-03-10 05:11:03 +00:00
|
|
|
class Python3 < Formula
|
2010-04-17 18:50:15 +00:00
|
|
|
homepage 'http://www.python.org/'
|
2012-04-12 02:19:59 +00:00
|
|
|
url 'http://python.org/ftp/python/3.2.3/Python-3.2.3.tar.bz2'
|
|
|
|
md5 'cea34079aeb2e21e7b60ee82a0ac286b'
|
2010-04-17 18:50:15 +00:00
|
|
|
|
2012-08-14 01:25:42 +00:00
|
|
|
depends_on TkCheck.new
|
2011-09-01 20:22:44 +00:00
|
|
|
depends_on 'pkg-config' => :build
|
2010-07-07 20:15:59 +00:00
|
|
|
depends_on 'readline' => :optional # Prefer over OS X's libedit
|
|
|
|
depends_on 'sqlite' => :optional # Prefer over OS X's older version
|
|
|
|
depends_on 'gdbm' => :optional
|
2012-06-22 16:27:02 +00:00
|
|
|
depends_on :x11 # tk.h includes X11/Xlib.h and X11/X.h
|
2010-04-17 18:50:15 +00:00
|
|
|
|
2012-08-13 15:00:39 +00:00
|
|
|
option 'quicktest', 'Run `make quicktest` after the build'
|
2010-04-17 18:50:15 +00:00
|
|
|
|
2011-09-01 21:03:53 +00:00
|
|
|
# Skip binaries so modules will load; skip lib because it is mostly Python files
|
2010-07-07 20:15:59 +00:00
|
|
|
skip_clean ['bin', 'lib']
|
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
def site_packages_cellar
|
2012-08-14 20:03:36 +00:00
|
|
|
prefix/"Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages"
|
2010-07-07 20:15:59 +00:00
|
|
|
end
|
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
# The HOMEBREW_PREFIX location of site-packages.
|
|
|
|
def site_packages
|
2012-08-14 20:03:36 +00:00
|
|
|
HOMEBREW_PREFIX/"lib/python3.2/site-packages"
|
2012-06-22 16:27:02 +00:00
|
|
|
end
|
2010-04-17 18:50:15 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
# Where distribute/pip will install executable scripts.
|
|
|
|
def scripts_folder
|
2012-08-14 20:03:36 +00:00
|
|
|
HOMEBREW_PREFIX/"share/python3"
|
2012-06-22 16:27:02 +00:00
|
|
|
end
|
2010-07-07 20:15:59 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
def effective_lib
|
2012-08-14 20:03:36 +00:00
|
|
|
prefix/"Frameworks/Python.framework/Versions/3.2/lib"
|
2012-06-22 16:27:02 +00:00
|
|
|
end
|
2010-07-07 20:15:59 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
def install
|
2012-08-15 08:22:14 +00:00
|
|
|
args = %W[--prefix=#{prefix}
|
|
|
|
--enable-ipv6
|
|
|
|
--datarootdir=#{share}
|
|
|
|
--datadir=#{share}
|
|
|
|
--enable-framework=#{prefix}/Frameworks
|
|
|
|
]
|
|
|
|
|
|
|
|
args << '--without-gcc' if ENV.compiler == :clang
|
|
|
|
|
|
|
|
# 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
|
2012-06-22 16:27:02 +00:00
|
|
|
|
|
|
|
# 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
|
2012-08-14 01:25:03 +00:00
|
|
|
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'
|
|
|
|
end
|
2012-06-22 16:27:02 +00:00
|
|
|
|
|
|
|
# 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"))', 'pass'
|
2012-02-15 10:55:35 +00:00
|
|
|
|
2010-04-17 18:50:15 +00:00
|
|
|
system "./configure", *args
|
|
|
|
system "make"
|
2012-06-22 16:27:02 +00:00
|
|
|
ENV.deparallelize # Installs must be serialized
|
|
|
|
# Tell Python not to install into /Applications (default for framework builds)
|
|
|
|
system "make", "install", "PYTHONAPPSDIR=#{prefix}"
|
2012-08-13 15:00:39 +00:00
|
|
|
system "make", "quicktest" if build.include? "quicktest"
|
2012-06-22 16:27:02 +00:00
|
|
|
|
|
|
|
# Any .app get a " 3" attached, so it does not conflict with python 2.x.
|
|
|
|
Dir.glob(prefix/"*.app").each do |app|
|
|
|
|
mv app, app.gsub(".app", " 3.app")
|
2012-02-15 10:55:35 +00:00
|
|
|
end
|
|
|
|
|
2011-09-01 21:03:53 +00:00
|
|
|
# Post-install, fix up the site-packages and install-scripts folders
|
|
|
|
# so that user-installed Python software survives minor updates, such
|
2011-09-04 22:09:37 +00:00
|
|
|
# as going from 3.2.2 to 3.2.3.
|
2011-09-01 21:03:53 +00:00
|
|
|
|
|
|
|
# Remove the site-packages that Python created in its Cellar.
|
2012-06-22 16:27:02 +00:00
|
|
|
site_packages_cellar.rmtree
|
2012-08-14 20:03:36 +00:00
|
|
|
# Create a site-packages in HOMEBREW_PREFIX/lib/python3/site-packages
|
2012-06-22 16:27:02 +00:00
|
|
|
site_packages.mkpath
|
|
|
|
# Symlink the prefix site-packages into the cellar.
|
|
|
|
ln_s site_packages, site_packages_cellar
|
2011-09-01 21:03:53 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
# "python3" and executable is forgotten for framework builds.
|
2012-08-14 20:03:36 +00:00
|
|
|
# Make sure homebrew symlinks it to HOMEBREW_PREFIX/bin.
|
2012-06-22 16:27:02 +00:00
|
|
|
ln_s "#{bin}/python3.2", "#{bin}/python3" unless (bin/"python3").exist?
|
2011-09-01 21:03:53 +00:00
|
|
|
|
|
|
|
# Tell distutils-based installers where to put scripts
|
|
|
|
scripts_folder.mkpath
|
2012-02-15 10:55:35 +00:00
|
|
|
(effective_lib/"python3.2/distutils/distutils.cfg").write <<-EOF.undent
|
2011-09-01 21:03:53 +00:00
|
|
|
[install]
|
|
|
|
install-scripts=#{scripts_folder}
|
|
|
|
EOF
|
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
# Install distribute for python3
|
2011-09-01 21:03:53 +00:00
|
|
|
Distribute.new.brew do
|
2011-09-03 04:22:13 +00:00
|
|
|
system "#{bin}/python3.2", "setup.py", "install"
|
2011-09-01 21:03:53 +00:00
|
|
|
# Symlink to easy_install3 to match python3 command.
|
2012-02-15 10:55:35 +00:00
|
|
|
unless (scripts_folder/'easy_install3').exist?
|
2012-06-22 16:27:02 +00:00
|
|
|
ln_s scripts_folder/"easy_install", scripts_folder/"easy_install3"
|
2012-01-14 05:23:44 +00:00
|
|
|
end
|
2011-09-01 21:03:53 +00:00
|
|
|
end
|
2012-06-22 16:27:02 +00:00
|
|
|
# Install pip-3.2 for python3
|
|
|
|
Pip.new.brew { system "#{bin}/python3.2", "setup.py", "install" }
|
2010-07-07 20:15:59 +00:00
|
|
|
end
|
|
|
|
|
2011-09-01 21:03:53 +00:00
|
|
|
def caveats
|
2012-06-22 16:27:02 +00:00
|
|
|
text = <<-EOS.undent
|
|
|
|
The Python framework is located at:
|
2011-09-01 21:03:53 +00:00
|
|
|
#{prefix}/Frameworks/Python.framework
|
2010-07-07 20:15:59 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
You can `brew linkapps` to symlink "Idle 3" and the "Python Launcher 3".
|
2010-07-07 20:15:59 +00:00
|
|
|
EOS
|
2011-09-01 21:03:53 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
# Tk warning only for 10.6
|
2012-02-15 10:55:35 +00:00
|
|
|
tk_caveats = <<-EOS.undent
|
2012-06-22 16:27:02 +00:00
|
|
|
|
2012-02-15 10:55:35 +00:00
|
|
|
Apple's Tcl/Tk is not recommended for use with Python on Mac OS X 10.6.
|
2011-09-01 21:03:53 +00:00
|
|
|
For more information see: http://www.python.org/download/mac/tcltk/
|
2012-02-15 10:55:35 +00:00
|
|
|
EOS
|
|
|
|
|
|
|
|
general_caveats = <<-EOS.undent
|
2012-06-22 16:27:02 +00:00
|
|
|
|
|
|
|
A "distutils.cfg" has been written, specifying the install-scripts directory as:
|
2011-09-01 21:03:53 +00:00
|
|
|
#{scripts_folder}
|
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
If you install Python packages via "pip-3.2 install x" or "python3 setup.py install"
|
|
|
|
(or the outdated easy_install3), any provided scripts will go into the
|
|
|
|
install-scripts folder above, so you may want to add it to your PATH.
|
2011-09-01 21:03:53 +00:00
|
|
|
|
2012-06-22 16:27:02 +00:00
|
|
|
The site-package directory for brewed Python:
|
|
|
|
#{site_packages}
|
|
|
|
|
|
|
|
Distribute and Pip have been installed. To update them:
|
|
|
|
#{scripts_folder}/pip-3.2 install --upgrade distribute
|
|
|
|
#{scripts_folder}/pip-3.2 install --upgrade pip
|
2011-09-01 21:03:53 +00:00
|
|
|
|
|
|
|
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
|
|
|
|
EOS
|
|
|
|
|
2012-08-14 16:37:29 +00:00
|
|
|
text += tk_caveats unless MacOS.version >= :lion
|
2012-06-22 16:27:02 +00:00
|
|
|
text += general_caveats
|
|
|
|
return text
|
2010-04-17 18:50:15 +00:00
|
|
|
end
|
2012-02-15 10:55:35 +00:00
|
|
|
|
|
|
|
def test
|
2012-06-22 16:27:02 +00:00
|
|
|
# Check if sqlite is ok, because we build with --enable-loadable-sqlite-extensions
|
|
|
|
# and it can occur that building sqlite silently fails.
|
|
|
|
system "#{bin}/python3", "-c", "import sqlite3"
|
|
|
|
# See: https://github.com/mxcl/homebrew/pull/10487
|
|
|
|
# Fixed [upstream](http://bugs.python.org/issue11149), but still nice to have.
|
2012-02-15 10:55:35 +00:00
|
|
|
`#{bin}/python3 -c 'from decimal import Decimal; print(Decimal(4) / Decimal(2))'`.chomp == '2'
|
|
|
|
end
|
2010-04-17 18:50:15 +00:00
|
|
|
end
|