python: Now framework style. Bug fixes.
- Framework style build in order to support wxmac and other GUIs (Note: PySide (and pyqt?) seem to work even with non-framework builds). - Fixed automatic installation of `*.app`s into `/Applications`. - The caveats tell us now about `brew link apps`. - Cleanup of the caveats. - Resolve the issue of duplicate `2to3` can make the symlink phase to break because both python and python3 provide it. (Closes Homebrew/homebrew#12581) - Enable warnings, because python's configure needs it. (Closes Homebrew/homebrew#12194) - Add suppression of recommended warnings from the python docs. - Add work-a-round for python bug: http://bugs.python.org/issue11445 - Add explicit test if sqlite3 built successful. - Check against possible issue like Homebrew/homebrew#12667. - Add needed "depends_on :x11" because tk.h includes x11. - Install the Demo into HOMEBREW_PREFIX/share/python2.7/Extras - Ensure sqlite from homebrew is used and not the one from OS X. - Removed unnecessary flags from configure - Added --without-gcc to the configure flags (all clang now) - Ensure that "man python2.7" works by setting --datadir and --datarootdir to share. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>master
parent
10f9e2f7c5
commit
3b12d76f70
|
@ -1,13 +1,5 @@
|
|||
require 'formula'
|
||||
|
||||
# Was a Framework build requested?
|
||||
def build_framework?; ARGV.include? '--framework'; end
|
||||
|
||||
# Are we installed or installing as a Framework?
|
||||
def as_framework?
|
||||
(self.installed? and File.exists? prefix+"Frameworks/Python.framework") or build_framework?
|
||||
end
|
||||
|
||||
class TkCheck < Requirement
|
||||
def message; <<-EOS.undent
|
||||
Tk.framework detected in /Library/Frameworks
|
||||
|
@ -23,16 +15,15 @@ class TkCheck < Requirement
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
class Distribute < Formula
|
||||
url 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz'
|
||||
md5 'b400b532e33f78551e6847c1f5965e56'
|
||||
sha1 '709bd97d46050d69865d4b588c7707768dfe6711'
|
||||
end
|
||||
|
||||
class Pip < Formula
|
||||
url 'http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz'
|
||||
md5 '62a9f08dd5dc69d76734568a6c040508'
|
||||
end
|
||||
class Pip < Formula
|
||||
url 'http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz'
|
||||
md5 '62a9f08dd5dc69d76734568a6c040508'
|
||||
end
|
||||
|
||||
class Python < Formula
|
||||
homepage 'http://www.python.org/'
|
||||
|
@ -44,45 +35,66 @@ class Python < Formula
|
|||
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
|
||||
depends_on :x11 # tk.h includes X11/Xlib.h and X11/X.h
|
||||
|
||||
def options
|
||||
[
|
||||
["--framework", "Do a 'Framework' build instead of a UNIX-style build."],
|
||||
["--universal", "Build for both 32 & 64 bit Intel."],
|
||||
["--static", "Build static libraries."]
|
||||
["--quicktest", "Run `make quicktest` after build."]
|
||||
]
|
||||
end
|
||||
|
||||
# Skip binaries so modules will load; skip lib because it is mostly Python files
|
||||
skip_clean ['bin', 'lib']
|
||||
|
||||
# The Cellar location of site-packages (different for Framework builds)
|
||||
def site_packages_cellar
|
||||
# We're installed or installing as a Framework, then use that location.
|
||||
prefix+"Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages"
|
||||
end
|
||||
|
||||
# The HOMEBREW_PREFIX location of site-packages.
|
||||
def site_packages
|
||||
HOMEBREW_PREFIX+"lib/python2.7/site-packages"
|
||||
end
|
||||
|
||||
# Where distribute/pip will install executable scripts.
|
||||
def scripts_folder
|
||||
HOMEBREW_PREFIX+"share/python"
|
||||
end
|
||||
|
||||
# lib folder,taking into account whether we are a Framework build or not
|
||||
def effective_lib
|
||||
prefix+"Frameworks/Python.framework/Versions/2.7/lib"
|
||||
end
|
||||
|
||||
def install
|
||||
# Python requires -fwrapv for proper Decimal division with Clang. See:
|
||||
# https://github.com/mxcl/homebrew/pull/10487
|
||||
# http://stackoverflow.com/questions/7590137/dividing-decimals-yields-invalid-results-in-python-2-5-to-2-7
|
||||
# https://trac.macports.org/changeset/87442
|
||||
ENV.append_to_cflags "-fwrapv"
|
||||
args = %W[
|
||||
--prefix=#{prefix}
|
||||
--enable-ipv6
|
||||
--datarootdir=#{share}
|
||||
--datadir=#{share}
|
||||
--without-gcc
|
||||
--enable-framework=#{prefix}/Frameworks
|
||||
]
|
||||
|
||||
if build_framework? and ARGV.include? "--static"
|
||||
onoe "Cannot specify both framework and static."
|
||||
exit 99
|
||||
# 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
|
||||
|
||||
args = ["--prefix=#{prefix}"]
|
||||
|
||||
if ARGV.build_universal?
|
||||
args << "--enable-universalsdk=/" << "--with-universal-archs=intel"
|
||||
end
|
||||
|
||||
if build_framework?
|
||||
args << "--enable-framework=#{prefix}/Frameworks"
|
||||
else
|
||||
args << "--enable-shared" unless ARGV.include? '--static'
|
||||
end
|
||||
|
||||
# allow sqlite3 module to load extensions
|
||||
inreplace "setup.py",
|
||||
'sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))', ''
|
||||
# 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
|
||||
|
||||
|
@ -91,28 +103,27 @@ class Python < Formula
|
|||
inreplace 'pyconfig.h', /.*?(HAVE_POLL[_A-Z]*).*/, '#undef \1'
|
||||
|
||||
system "make"
|
||||
ENV.j1 # Installs must be serialized
|
||||
system "make install"
|
||||
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/python2.7
|
||||
system "make", "frameworkinstallextras", "PYTHONAPPSDIR=#{share}/python2.7"
|
||||
system "make", "quicktest" if ARGV.include? '--quicktest'
|
||||
|
||||
# Post-install, fix up the site-packages and install-scripts folders
|
||||
# so that user-installed Python software survives minor updates, such
|
||||
# as going from 2.7.0 to 2.7.1.
|
||||
# as going from 2.7.0 to 2.7.1:
|
||||
|
||||
# Remove the site-packages that Python created in its Cellar.
|
||||
site_packages.rmtree
|
||||
|
||||
# Create a site-packages in the prefix.
|
||||
prefix_site_packages.mkpath
|
||||
|
||||
site_packages_cellar.rmtree
|
||||
# Create a site-packages in `brew --prefix`/lib/python/site-packages
|
||||
site_packages.mkpath
|
||||
# Symlink the prefix site-packages into the cellar.
|
||||
ln_s prefix_site_packages, site_packages
|
||||
ln_s site_packages, site_packages_cellar
|
||||
|
||||
# This is a fix for better interoperability with pyqt. See:
|
||||
# https://github.com/mxcl/homebrew/issues/6176
|
||||
if not as_framework?
|
||||
(bin+"pythonw").make_link bin+"python"
|
||||
(bin+"pythonw2.7").make_link bin+"python2.7"
|
||||
end
|
||||
# Python 3 has a 2to3, too. Additionally there still is a 2to3-2.7.
|
||||
# (https://github.com/mxcl/homebrew/issues/12581)
|
||||
rm bin/"2to3" if (HOMEBREW_PREFIX/bin/"2to3").exist?
|
||||
|
||||
# Tell distutils-based installers where to put scripts
|
||||
scripts_folder.mkpath
|
||||
|
@ -127,73 +138,39 @@ class Python < Formula
|
|||
end
|
||||
|
||||
def caveats
|
||||
framework_caveats = <<-EOS.undent
|
||||
|
||||
Framework Python was installed to:
|
||||
<<-EOS.undent
|
||||
The Python framework is located at
|
||||
#{prefix}/Frameworks/Python.framework
|
||||
|
||||
You may want to symlink this Framework to a standard OS X location:
|
||||
mkdir -p ~/Library/Frameworks/Python.framework/Versions
|
||||
ln -s "#{prefix}/Frameworks/Python.framework/Versions/2.7" ~/Library/Frameworks/Python.framework/Versions/2.7
|
||||
ln -s ~/Library/Frameworks/Python.framework/Versions/2.7 ~/Library/Frameworks/Python.framework/Versions/Current
|
||||
ln -s ~/Library/Frameworks/Python.framework/Versions/2.7/Python ~/Library/Frameworks/Python.framework/Python
|
||||
ln -s ~/Library/Frameworks/Python.framework/Versions/2.7/Resources ~/Library/Frameworks/Python.framework/Resources
|
||||
EOS
|
||||
You can find the Python demo at
|
||||
#{HOMEBREW_PREFIX}/share/python2.7/Extras
|
||||
|
||||
general_caveats = <<-EOS.undent
|
||||
A "distutils.cfg" has been written to:
|
||||
#{effective_lib}/python2.7/distutils
|
||||
specifing the install-scripts folder as:
|
||||
You can `brew linkapps` to symlink "Idle" and the "Python Launcher".
|
||||
|
||||
A "distutils.cfg" has been written, specifying the install-scripts folder as:
|
||||
#{scripts_folder}
|
||||
|
||||
If you install Python packages via "pip install x" or "python setup.py install"
|
||||
(or the outdated easy_install), any provided scripts will go into the
|
||||
install-scripts folder above, so you may want to add it to your PATH.
|
||||
|
||||
Distribute has been installed. To update distribute itself outside of Homebrew:
|
||||
#{scripts_folder}/pip install --upgrade distribute
|
||||
The site-package directory for brewed Python:
|
||||
#{site_packages}
|
||||
|
||||
Distribute and Pip have been installed. To update them
|
||||
#{scripts_folder}/pip install --upgrade distribute
|
||||
#{scripts_folder}/pip install --upgrade pip
|
||||
|
||||
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
|
||||
EOS
|
||||
|
||||
s = general_caveats
|
||||
s += framework_caveats if as_framework?
|
||||
return s
|
||||
end
|
||||
|
||||
# lib folder,taking into account whether we are a Framework build or not
|
||||
def effective_lib
|
||||
# If we're installed or installing as a Framework, then use that location.
|
||||
return prefix+"Frameworks/Python.framework/Versions/2.7/lib" if as_framework?
|
||||
# Otherwise use just 'lib'
|
||||
return lib
|
||||
end
|
||||
|
||||
# include folder,taking into account whether we are a Framework build or not
|
||||
def effective_include
|
||||
# If we're installed or installing as a Framework, then use that location.
|
||||
return prefix+"Frameworks/Python.framework/Versions/2.7/include" if as_framework?
|
||||
# Otherwise use just 'include'
|
||||
return include
|
||||
end
|
||||
|
||||
# The Cellar location of site-packages
|
||||
def site_packages
|
||||
effective_lib+"python2.7/site-packages"
|
||||
end
|
||||
|
||||
# The HOMEBREW_PREFIX location of site-packages
|
||||
def prefix_site_packages
|
||||
HOMEBREW_PREFIX+"lib/python2.7/site-packages"
|
||||
end
|
||||
|
||||
# Where distribute will install executable scripts
|
||||
def scripts_folder
|
||||
HOMEBREW_PREFIX+"share/python"
|
||||
end
|
||||
|
||||
def test
|
||||
# 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"
|
||||
# See: https://github.com/mxcl/homebrew/pull/10487
|
||||
# Fixed [upstream](http://bugs.python.org/issue11149), but still nice to have.
|
||||
`#{bin}/python -c 'from decimal import Decimal; print Decimal(4) / Decimal(2)'`.chomp == '2'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue