Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Python 2.x and 3.x support
Browse files Browse the repository at this point in the history
New `depends_on :python` Dependency.
New `depends_on :python3` Dependency.

To avoid having multiple formulae with endings -py2 and -py3,
we will handle support for different pythons (2.x vs. 3.x)
in the same formula.
Further brewed vs. external python will be transparently supported.

The formula also gets a new object `python`, which is false if
no Python is available or the user has disabled it. Otherwise
it is defined and provides several support methods:

python.site_packages # the site-packages in the formula's Cellar
python.global_site_packages
python.binary # the full path to the python binary
python.prefix
python.version
python.version.major
python.version.minor
python.xy # => e.g. "python2.7"
python.incdir # includes of python
python.libdir # the python dylib library
python.pkg_config_path # used internally by brew
python.from_osx?
python.framework?
python.universal?
python.pypy?
python.standard_caveats # Text to set PYTHONPATH for python.from_osx?
python.if3then3 # => "" for 2.x and to "3" for 3.x.

Further, to avoid code duplication, `python` takes an optional
block that is run twice if the formula defines depends_on
:python AND :python3.

python do
  system python, 'setup.py', "--prefix=#{prefix}"
end

Read more in the Homebrew wiki.
  • Loading branch information
samueljohn committed Jun 3, 2013
1 parent 35c46b4 commit 0b50110
Show file tree
Hide file tree
Showing 109 changed files with 1,664 additions and 1,368 deletions.
3 changes: 2 additions & 1 deletion Library/Formula/asymptote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def caveats; <<-EOS.undent
If you wish to use xasy, you must first install the Python Imaging Library:
easy_install http://effbot.org/downloads/Imaging-1.1.7.tar.gz
brew install pil
EOS
end
end
35 changes: 5 additions & 30 deletions Library/Formula/bazaar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,18 @@ class Bazaar < Formula
url 'https://launchpad.net/bzr/2.5/2.5.1/+download/bzr-2.5.1.tar.gz'
sha1 '7e2776e3aaf8fb48828026d3fc2a3047465eea5e'

option "system", "Install using the OS X system Python."
depends_on :python

def install
ENV.j1 # Builds aren't parallel-safe

# Make and install man page first
system "make man1/bzr.1"
man1.install "man1/bzr.1"

if build.include? "system"
ENV.prepend "PATH", "/System/Library/Frameworks/Python.framework/Versions/Current/bin", ":"
end

# Find the arch for the Python we are building against.
# We remove 'ppc' support, so we can pass Intel-optimized CFLAGS.
if build.include? "system"
python_cmd = "/usr/bin/python"
else
python_cmd = "python"
python do
# In this python block, the site-packages are already set up
system python, "setup.py", "install", "--prefix=#{prefix}"
(prefix/'man').rmtree
end

archs = archs_for_command(python_cmd)
archs.remove_ppc!
ENV['ARCHFLAGS'] = archs.as_arch_flags

system "make"
inreplace "bzr", "#! /usr/bin/env python", "#!/usr/bin/python" if build.include? "system"
libexec.install 'bzr', 'bzrlib'

bin.install_symlink libexec+'bzr'
end

def caveats; <<-EOS.undent
We've built a "standalone" version of bazaar and installed its libraries to:
#{libexec}
We've specifically kept it out of your Python's "site-packages" folder.
EOS
end
end
19 changes: 16 additions & 3 deletions Library/Formula/beecrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Beecrypt < Formula
sha256 '286f1f56080d1a6b1d024003a5fa2158f4ff82cae0c6829d3c476a4b5898c55d'

depends_on "icu4c"
depends_on :python => :optional

def patches
# fix build with newer clang, gcc 4.7 (https://bugs.gentoo.org/show_bug.cgi?id=413951)
Expand All @@ -19,15 +20,27 @@ def darwin_major_version
end

def install
ENV.remove_from_cflags /-march=\S*/
args = ["--prefix=#{prefix}", "--disable-openmp", "--without-java", "--without-python"]
ENV.remove_from_cflags(/-march=\S*/)
args = ["--prefix=#{prefix}", "--disable-openmp", "--without-java"]
if MacOS.prefer_64_bit?
args << "--build=x86_64-apple-darwin#{darwin_major_version}"
end

args << "--without-python" if build.without? 'python'

if python
# We don't want beecrypt to use get_python_lib() to install into
# the global site-packages. There is no option to set it.
# Fixing this in configure make the configure output printout correct.
inreplace "configure", "ac_cv_python_libdir=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib()'`",
"ac_cv_python_libdir='#{python.site_packages}'"
end
system "./configure", *args
system "make"
system "make check"
system "make install"
# We have to move the check after install (which is stupid, I know) but
# otherwise they fail because python bindings don't yet find the libbeecrypt
system "make check"
end
end

Expand Down
22 changes: 11 additions & 11 deletions Library/Formula/boost.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'formula'

class UniversalPython < Requirement
satisfy { archs_for_command("python").universal? }
satisfy(:build_env => false) { archs_for_command("python").universal? }

def message; <<-EOS.undent
A universal build was requested, but Python is not a universal build
Expand Down Expand Up @@ -29,14 +29,14 @@ class Boost < Formula

option :universal
option 'with-mpi', 'Enable MPI support'
option 'without-python', 'Build without Python'
option 'with-icu', 'Build regexp engine with icu support'
option 'with-icu4c', 'Build regexp engine with icu support'
option 'with-c++11', 'Compile using Clang, std=c++11 and stdlib=libc++' if MacOS.version >= :lion
option 'use-system-layout', 'Use system layout instead of tagged'

depends_on UniversalPython if build.universal? and not build.include? "without-python"
depends_on "icu4c" if build.include? "with-icu"
depends_on MPIDependency.new(:cc, :cxx) if build.include? "with-mpi"
depends_on :python => :recommended
depends_on UniversalPython if build.universal? and build.with? "python"
depends_on "icu4c" => :optional
depends_on MPIDependency.new(:cc, :cxx) if build.with? "mpi"

fails_with :llvm do
build 2335
Expand Down Expand Up @@ -69,15 +69,15 @@ def install
# Force boost to compile using the appropriate GCC version
open("user-config.jam", "a") do |file|
file.write "using darwin : : #{ENV.cxx} ;\n"
file.write "using mpi ;\n" if build.include? 'with-mpi'
file.write "using mpi ;\n" if build.with? 'mpi'
end

# we specify libdir too because the script is apparently broken
bargs = ["--prefix=#{prefix}", "--libdir=#{lib}"]

bargs << "--with-toolset=clang" if build.include? "with-c++11"
bargs << "--with-toolset=clang" if build.with? "c++11"

if build.include? 'with-icu'
if build.with? 'icu4c'
icu4c_prefix = Formula.factory('icu4c').opt_prefix
bargs << "--with-icu=#{icu4c_prefix}"
else
Expand All @@ -99,7 +99,7 @@ def install
"threading=multi",
"install"]

if MacOS.version >= :lion and build.include? 'with-c++11'
if MacOS.version >= :lion and build.with? 'c++11'
args << "toolset=clang" << "cxxflags=-std=c++11"
args << "cxxflags=-stdlib=libc++" << "cxxflags=-fPIC"
args << "cxxflags=-arch x86_64" if MacOS.prefer_64_bit? or build.universal?
Expand All @@ -111,7 +111,7 @@ def install
end

args << "address-model=32_64" << "architecture=x86" << "pch=off" if build.universal?
args << "--without-python" if build.include? "without-python"
args << "--without-python" if build.without? 'python'

system "./bootstrap.sh", *bargs
system "./b2", *args
Expand Down
18 changes: 9 additions & 9 deletions Library/Formula/boost149.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'formula'

class UniversalPython < Requirement
satisfy { archs_for_command("python").universal? }
satisfy(:build_env => false) { archs_for_command("python").universal? }

def message; <<-EOS.undent
A universal build was requested, but Python is not a universal build
Expand All @@ -23,12 +23,12 @@ class Boost149 < Formula

option :universal
option 'with-mpi', 'Enable MPI support'
option 'without-python', 'Build without Python'
option 'with-icu', 'Build regexp engine with icu support'
option 'with-icu4c', 'Build regexp engine with icu support'

depends_on UniversalPython if build.universal? and not build.include? "without-python"
depends_on "icu4c" if build.include? "with-icu"
depends_on MPIDependency.new(:cc, :cxx) if build.include? "with-mpi"
depends_on :python => :recommended
depends_on UniversalPython if build.universal? and build.with? "python"
depends_on "icu4c" => :optional
depends_on MPIDependency.new(:cc, :cxx) if build.with? "mpi"

fails_with :llvm do
build 2335
Expand All @@ -50,13 +50,13 @@ def install
# Force boost to compile using the appropriate GCC version
open("user-config.jam", "a") do |file|
file.write "using darwin : : #{ENV.cxx} ;\n"
file.write "using mpi ;\n" if build.include? 'with-mpi'
file.write "using mpi ;\n" if build.with? 'mpi'
end

# we specify libdir too because the script is apparently broken
bargs = ["--prefix=#{prefix}", "--libdir=#{lib}"]

if build.include? 'with-icu'
if build.with? 'icu4c'
icu4c_prefix = Formula.factory('icu4c').opt_prefix
bargs << "--with-icu=#{icu4c_prefix}"
else
Expand All @@ -73,7 +73,7 @@ def install
"install"]

args << "address-model=32_64" << "architecture=x86" << "pch=off" if build.universal?
args << "--without-python" if build.include? "without-python"
args << "--without-python" if build.without? 'python'

system "./bootstrap.sh", *bargs
system "./bjam", *args
Expand Down
24 changes: 12 additions & 12 deletions Library/Formula/bulk_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BulkExtractor < Formula

depends_on :autoconf
depends_on :automake
depends_on :python

depends_on 'afflib' => :optional
depends_on 'exiv2' => :optional
Expand All @@ -19,25 +20,24 @@ def patches
end

def install
system "./configure", "--disable-dependency-tracking",
"--prefix=#{prefix}"
system "make"
system "make install"
python do
system "./configure", "--disable-dependency-tracking",
"--prefix=#{prefix}"
system "make"
system "make install"

# Install documentation
(share/'bulk_extractor/doc').install Dir['doc/*.{html,txt,pdf}']
# Install documentation
(share/'bulk_extractor/doc').install Dir['doc/*.{html,txt,pdf}']

# Install Python utilities
(share/'bulk_extractor/python').install Dir['python/*.py']
(lib/python.xy/"site-packages").install Dir['python/*.py']
end

# Install the GUI the Homebrew way
libexec.install 'java_gui/BEViewer.jar'
bin.write_jar_script libexec/"BEViewer.jar", "BEViewer", "-Xmx1g"
end

def caveats; <<-EOS.undent
You may need to add the directory containing the Python bindings to your PYTHONPATH:
#{share}/bulk_extractor/python
EOS
def caveats
python.standard_caveats if python
end
end
16 changes: 10 additions & 6 deletions Library/Formula/bup.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
require 'formula'

class Bup < Formula
homepage 'https://github.com/apenwarr/bup'
url 'https://github.com/apenwarr/bup/archive/bup-0.25-rc1.tar.gz'
homepage 'https://github.com/bup/bup'
url 'https://github.com/bup/bup/archive/bup-0.25-rc1.tar.gz'
sha1 'b88bd38d6f00a646faf0bd1f561595ebc0e55b30'

head 'https://github.com/apenwarr/bup.git', :branch => 'master'
head 'https://github.com/bup/bup.git', :branch => 'master'

option "run-tests", "Run unit tests after compilation"

depends_on :python

# patch to make the `--prefix` parameter work
# found at https://github.com/apenwarr/bup/pull/5
def patches
DATA
end

def install
ENV['PATH'] = '/usr/bin:' + ENV['PATH'] # make sure we Sytem Python
system "./configure", "--prefix=#{prefix}"
system "make"
python do
ohai ENV['PATH']
system "./configure", "--prefix=#{prefix}"
system "make"
end
system "make test" if build.include? "run-tests"
system "make install"
end
Expand Down
1 change: 1 addition & 0 deletions Library/Formula/cantera.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Cantera < Formula
head 'http://cantera.googlecode.com/svn/cantera18/trunk/'

depends_on 'numpy' => :python
depends_on :python
depends_on 'graphviz'

# fixes the Makefiles in Cantera/cxx/demos/ that have broken install commands
Expand Down
1 change: 1 addition & 0 deletions Library/Formula/cmu-sphinxbase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CmuSphinxbase < Formula
sha1 'c0c4d52e143d07cd593bd6bcaeb92b9a8a5a8c8e'

depends_on 'pkg-config' => :build
depends_on :python
depends_on HomebrewedPython

def install
Expand Down
3 changes: 2 additions & 1 deletion Library/Formula/collectd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Collectd < Formula
option "java", "Enable Java 1.6 support"

depends_on 'pkg-config' => :build
depends_on :python

fails_with :clang do
build 318
Expand All @@ -26,7 +27,7 @@ def install
--disable-dependency-tracking
--prefix=#{prefix}
--localstatedir=#{var}
--with-python=/usr/bin]
--with-python=#{python}]

args << "--disable-embedded-perl" if MacOS.version == :leopard
args << "--disable-java" unless build.include? "java"
Expand Down
20 changes: 12 additions & 8 deletions Library/Formula/cvs2svn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class PythonWithGdbm < Requirement
fatal true

satisfy { quiet_system "python", "-c", "import gdbm" }
satisfy(:build_env => false) { quiet_system "python", "-c", "import gdbm" }

def message; <<-EOS.undent
The Python being used does not include gdbm support,
Expand All @@ -21,16 +21,20 @@ class Cvs2svn < Formula
url 'http://trac.macports.org/export/70472/distfiles/cvs2svn/cvs2svn-2.3.0.tar.gz'
sha1 '545237805ddb241054ba40b105b9c29b705539b8'

depends_on :python
depends_on PythonWithGdbm

def install
system "python", "setup.py", "install", "--prefix=#{prefix}"
system "make man"
man1.install gzip('cvs2svn.1', 'cvs2git.1', 'cvs2bzr.1')
prefix.install %w[ BUGS COMMITTERS HACKING
cvs2bzr-example.options cvs2git-example.options cvs2hg-example.options
cvs2svn-example.options contrib ]

python do
system python, "setup.py", "install", "--prefix=#{prefix}"
system "make man"
man1.install gzip('cvs2svn.1', 'cvs2git.1', 'cvs2bzr.1')
prefix.install %w[ BUGS COMMITTERS HACKING
cvs2bzr-example.options
cvs2git-example.options
cvs2hg-example.options
cvs2svn-example.options contrib ]
end
doc.install Dir['{doc,www}/*']
end

Expand Down
13 changes: 8 additions & 5 deletions Library/Formula/denyhosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Denyhosts < Formula
url 'http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz'
sha1 '02143843cb7c37c986c222b7acc11f7b75eb7373'

depends_on :python

# Copies of daemon-control-dist & denyhosts.cfg-dist edited for OS X.
def patches; DATA; end

Expand All @@ -30,11 +32,12 @@ def install
end

# Install mostly into libexec (a la Duplicity)
system "python", "setup.py", "install",
"--prefix=#{prefix}",
"--install-lib=#{libexec}",
"--install-scripts=#{libexec}",
"--install-data=#{libexec}"
python do
system python, "setup.py", "install",
"--prefix=#{prefix}",
"--install-scripts=#{bin}",
"--install-data=#{libexec}"
end
libexec.install 'daemon-control'
(libexec+'daemon-control').chmod 0755

Expand Down
Loading

0 comments on commit 0b50110

Please sign in to comment.