Permalink
Browse files

Added working --HEAD option to open-babel, because 2.2.3 is getting old.

The most recent official release of Open Babel is 2.3.1, but this requires
Eigen 2, which is not in homebrew (Eigen 3 does not work with Open Babel 2.3.1).
The --HEAD, however, works fine with Eigen 3.
  • Loading branch information...
1 parent 5f9e348 commit 448308e64ac16479ac75a1629c0a81ac75fff453 @rwest committed Apr 30, 2012
Showing with 83 additions and 1 deletion.
  1. +83 −1 Library/Formula/open-babel.rb
@@ -5,6 +5,8 @@ def message; <<-EOS.undent
The oasa Python module is required for some operations.
It can be downloaded from:
http://bkchem.zirael.org/oasa_en.html
+ Or with the command:
+ pip install -f http://bkchem.zirael.org/ oasa==0.13.1
EOS
end
def satisfied?
@@ -13,15 +15,87 @@ def satisfied?
end
end
+def which_python
+ "python" + `python -c 'import sys;print(sys.version[:3])'`.strip
+end
+
+def site_package_dir
+ "#{lib}/#{which_python}/site-packages"
+end
+
class OpenBabel < Formula
homepage 'http://openbabel.org/'
url 'http://sourceforge.net/projects/openbabel/files/openbabel/2.2.3/openbabel-2.2.3.tar.gz'
md5 '7ea8845c54d6d3a9be378c78088af804'
-
head 'https://openbabel.svn.sourceforge.net/svnroot/openbabel/openbabel/trunk'
depends_on OasaPythonModule.new
+ if ARGV.build_head? ##### FOR BUILDING THE HEAD ONLY #####
+ depends_on 'cmake' => :build
+ depends_on 'swig' => :build
+ depends_on 'eigen'
+
+ def install
+ ENV.deparallelize
+ args = std_cmake_parameters.split
+ args << "-DEIGEN3_INCLUDE_DIR='#{HOMEBREW_PREFIX}/include/eigen3'"
+ args << '-DPYTHON_BINDINGS=ON'
+ args << '-DRUN_SWIG=TRUE' if ARGV.build_head?
+
+ # This block is copied from opencv.rb formula:
+ #
+ # The CMake `FindPythonLibs` Module is dumber than a bag of hammers when
+ # more than one python installation is available---for example, it clings
+ # to the Header folder of the system Python Framework like a drowning
+ # sailor.
+ #
+ # This code was cribbed from the VTK formula and uses the output to
+ # `python-config` to do the job FindPythonLibs should be doing in the first
+ # place.
+ python_prefix = `python-config --prefix`.strip
+ # Python is actually a library. The libpythonX.Y.dylib points to this lib, too.
+ if File.exist? "#{python_prefix}/Python"
+ # Python was compiled with --framework:
+ args << "-DPYTHON_LIBRARY='#{python_prefix}/Python'"
+ args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/Headers'"
+ else
+ python_lib = "#{python_prefix}/lib/lib#{which_python}"
+ if File.exists? "#{python_lib}.a"
+ args << "-DPYTHON_LIBRARY='#{python_lib}.a'"
+ else
+ args << "-DPYTHON_LIBRARY='#{python_lib}.dylib'"
+ end
+ args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/include/#{which_python}'"
+ end
+
+ args << '.'
+ system "cmake", *args
+ system "make"
+ system "make install"
+
+ # move python stuff into #{site_package_dir}
+ mkdir_p site_package_dir
+ mv ["#{lib}/_openbabel.so", "#{lib}/openbabel.py", "#{lib}/pybel.py"], site_package_dir
+ # remove the spurious cmake and pkgconfig folders from lib
+ rmtree "#{lib}/cmake"
+ rmtree "#{lib}/pkgconfig"
+
+ end
+
+ def caveats; <<-EOS.undent
+ The Python bindings were installed to #{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages
+ so you may need to update your PYTHONPATH like so:
+ export PYTHONPATH="#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages:$PYTHONPATH"
+ To make this permanent, put it in your shell's profile (e.g. ~/.profile).
+
+ To draw images from python, you will need to get the oasa Python module:
+ pip install -f http://bkchem.zirael.org/ oasa==0.13.1
+ EOS
+ end
+
+ else ##### ONLY FOR BUILDING 2.2.3 #####
+
def options
[
["--perl", "Perl bindings"],
@@ -91,4 +165,12 @@ def install
end
end
end
+
+ def caveats; <<-EOS.undent
+ This is version 2.2.3 of Open Babel, which is a bit old.
+ You may want to install with --HEAD to get the latest developer version.
+ (The most recent official release, 2.3.1, is not available through homebrew).
+ EOS
+ end
+ end
end

0 comments on commit 448308e

Please sign in to comment.