python: Allow --with-brewed-tk.

- Fixes Homebrew/homebrew#16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Also remove Tk.framework check from python3.rb
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.

Closes Homebrew/homebrew#17008.

Signed-off-by: Adam Vandenberg <flangy@gmail.com>
master
Samuel John 2013-01-11 14:46:52 +01:00 committed by Adam Vandenberg
parent 0f06b16930
commit 3bf507fd46
2 changed files with 37 additions and 30 deletions

View File

@ -1,20 +1,5 @@
require 'formula' require 'formula'
class TkCheck < Requirement
def message; <<-EOS.undent
Tk.framework was detected in /Library/Frameworks
This can cause Python builds to fail. See:
https://github.com/mxcl/homebrew/issues/11602
EOS
end
def fatal?; false; end
def satisfied?
not File.exist? '/Library/Frameworks/Tk.framework'
end
end
class Distribute < Formula class Distribute < Formula
url 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.34.tar.gz' url 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.34.tar.gz'
sha1 'b6f9cfbaf3e63833b71009812a613be13e68f5de' sha1 'b6f9cfbaf3e63833b71009812a613be13e68f5de'
@ -30,20 +15,20 @@ class Python < Formula
url 'http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2' url 'http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2'
sha1 '842c4e2aff3f016feea3c6e992c7fa96e49c9aa0' sha1 '842c4e2aff3f016feea3c6e992c7fa96e49c9aa0'
depends_on TkCheck.new option :universal
option 'quicktest', 'Run `make quicktest` after the build'
option 'with-brewed-openssl', "Use Homebrew's openSSL instead of the one from OS X"
option 'with-brewed-tk', "Use Homebrew's Tk (has optional Cocoa and threads support)"
option 'with-poll', 'Enable select.poll, which is not fully implemented on OS X (http://bugs.python.org/issue5154)'
# --with-dtrace relies on CLT as dtrace hard-codes paths to /usr
option 'with-dtrace', 'Experimental DTrace support (http://bugs.python.org/issue13405)' if MacOS::CLT.installed?
depends_on 'pkg-config' => :build depends_on 'pkg-config' => :build
depends_on 'readline' => :recommended depends_on 'readline' => :recommended
depends_on 'sqlite' => :recommended depends_on 'sqlite' => :recommended
depends_on 'gdbm' => :recommended depends_on 'gdbm' => :recommended
depends_on 'openssl' if build.include? 'with-brewed-openssl' depends_on 'openssl' if build.include? 'with-brewed-openssl'
depends_on 'homebrew/dupes/tk' if build.include? 'with-brewed-tk'
option :universal
option 'quicktest', 'Run `make quicktest` after the build'
option 'with-brewed-openssl', "Use Homebrew's openSSL instead of the one from OS X"
option 'with-poll', 'Enable select.poll, which is not fully implemented on OS X (http://bugs.python.org/issue5154)'
# --with-dtrace relies on CLT as dtrace hard-codes paths to /usr
option 'with-dtrace', 'Experimental DTrace support (http://bugs.python.org/issue13405)' if MacOS::CLT.installed?
def patches def patches
p = [] p = []
@ -51,7 +36,8 @@ class Python < Formula
# see http://bugs.python.org/issue14662 # see http://bugs.python.org/issue14662
p << "https://gist.github.com/raw/4349132/25662c6b382315b5db67bf949773d76471bbcee7/python-nfs-shutil.diff" p << "https://gist.github.com/raw/4349132/25662c6b382315b5db67bf949773d76471bbcee7/python-nfs-shutil.diff"
p << 'https://raw.github.com/gist/3415636/2365dea8dc5415daa0148e98c394345e1191e4aa/pythondtrace-patch.diff' if build.include? 'with-dtrace' p << 'https://raw.github.com/gist/3415636/2365dea8dc5415daa0148e98c394345e1191e4aa/pythondtrace-patch.diff' if build.include? 'with-dtrace'
# Patch to disable the search for Tk.frameworked, since homebrew's Tk is a plain unix build
p << DATA if build.include? 'with-brewed-tk'
p p
end end
@ -182,6 +168,7 @@ class Python < Formula
s.gsub!(/^CXX=.*$/, "CXX=xcrun clang++") s.gsub!(/^CXX=.*$/, "CXX=xcrun clang++")
s.gsub!(/^AR=.*$/, "AR=xcrun ar") s.gsub!(/^AR=.*$/, "AR=xcrun ar")
s.gsub!(/^RANLIB=.*$/, "RANLIB=xcrun ranlib") s.gsub!(/^RANLIB=.*$/, "RANLIB=xcrun ranlib")
s.gsub!(/^PYTHONFRAMEWORKDIR=\tPython\.framework/, "PYTHONFRAMEWORKDIR= #{opt_prefix}/Frameworks/Python.framework")
end end
end end
@ -196,11 +183,13 @@ class Python < Formula
# Help Python's build system (distribute/pip) to build things on Xcode-only systems # Help Python's build system (distribute/pip) to build things on Xcode-only systems
# The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot) # The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
cflags += " -isysroot #{MacOS.sdk_path}" cflags += " -isysroot #{MacOS.sdk_path}"
# For the Xlib.h, Python needs this header dir
cflags += " -I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
ldflags += " -isysroot #{MacOS.sdk_path}" ldflags += " -isysroot #{MacOS.sdk_path}"
# Same zlib.h-not-found-bug as in env :std (see below) # Same zlib.h-not-found-bug as in env :std (see below)
args << "CPPFLAGS=-I#{MacOS.sdk_path}/usr/include" args << "CPPFLAGS=-I#{MacOS.sdk_path}/usr/include"
# For the Xlib.h, Python needs this header dir with the system Tk
unless build.include? 'with-brewed-tk'
cflags += " -I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
end
end end
args << cflags args << cflags
args << ldflags args << ldflags
@ -260,6 +249,7 @@ class Python < Formula
They will install into the site-package directory They will install into the site-package directory
#{site_packages} #{site_packages}
Executable python scripts will be put in: Executable python scripts will be put in:
#{scripts_folder} #{scripts_folder}
so you may want to put "#{scripts_folder}" in your PATH, too. so you may want to put "#{scripts_folder}" in your PATH, too.
@ -273,6 +263,25 @@ class Python < Formula
# and it can occur that building sqlite silently fails if OSX's sqlite is used. # and it can occur that building sqlite silently fails if OSX's sqlite is used.
system "#{bin}/python", "-c", "import sqlite3" system "#{bin}/python", "-c", "import sqlite3"
# Check if some other modules import. Then the linked libs are working. # Check if some other modules import. Then the linked libs are working.
system "#{bin}/python", "-c", "import Tkinter" system "#{bin}/python", "-c", "import Tkinter; root = Tkinter.Tk()"
end end
end end
__END__
diff --git a/setup.py b/setup.py
index 6b47451..b0400f8 100644
--- a/setup.py
+++ b/setup.py
@@ -1702,9 +1702,9 @@ class PyBuildExt(build_ext):
# AquaTk is a separate method. Only one Tkinter will be built on
# Darwin - either AquaTk, if it is found, or X11 based Tk.
platform = self.get_platform()
- if (platform == 'darwin' and
- self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
- return
+ # if (platform == 'darwin' and
+ # self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
+ # return
# Assume we haven't found any of the libraries or include files
# The versions with dots are used on Unix, and the versions without

View File

@ -1,5 +1,4 @@
require 'formula' require 'formula'
require Formula.path("python") # For TkCheck requirement
# Python3 is the new language standard, not just a new revision. # Python3 is the new language standard, not just a new revision.
# It's somewhat incompatible with Python 2.x, therefore, the executable # It's somewhat incompatible with Python 2.x, therefore, the executable
@ -22,7 +21,6 @@ class Python3 < Formula
sha1 '3e1464bc2c1dfa74287bc58da81168f50b0ae5c7' sha1 '3e1464bc2c1dfa74287bc58da81168f50b0ae5c7'
VER='3.3' # The <major>.<minor> is used so often. VER='3.3' # The <major>.<minor> is used so often.
depends_on TkCheck.new
depends_on 'pkg-config' => :build depends_on 'pkg-config' => :build
depends_on 'readline' => :recommended depends_on 'readline' => :recommended
depends_on 'sqlite' => :recommended depends_on 'sqlite' => :recommended