[Yt-svn] yt: Adding libpng support, including guessing of the location of...

hg at spacepope.org hg at spacepope.org
Wed Apr 14 06:33:07 PDT 2010


hg Repository: yt
details:   yt/rev/9d03b622255d
changeset: 1561:9d03b622255d
user:      Matthew Turk <matthewturk at gmail.com>
date:
Wed Apr 14 09:32:50 2010 -0400
description:
Adding libpng support, including guessing of the location of the library,
inclusion of the png writer in amr_utils, and additional installation in the
installation script.

diffstat:

 doc/install_script.sh        |  20 ++++++++++
 doc/install_script_osx.sh    |   1 +
 doc/install_script_osx106.sh |   1 +
 yt/amr_utils.pyx             |   1 +
 yt/lagos/setup.py            |   4 +-
 yt/setup.py                  |  57 +++++++++++++++++++++++++++-
 6 files changed, 79 insertions(+), 5 deletions(-)

diffs (169 lines):

diff -r bc63818ccbdc -r 9d03b622255d doc/install_script.sh
--- a/doc/install_script.sh	Wed Apr 14 00:51:48 2010 -0400
+++ b/doc/install_script.sh	Wed Apr 14 09:32:50 2010 -0400
@@ -32,6 +32,7 @@
 INST_ZLIB=1     # On some systems (Kraken) matplotlib has issues with 
                 # the system zlib, which is compiled statically.
                 # If need be, you can turn this off.
+INST_PNG=0      # Install a local libpng?  Same things apply as with zlib.
 INST_TRAITS=1   # Experimental TraitsUI installation
 INST_HG=1       # Install Mercurial or not?
 
@@ -229,6 +230,7 @@
 fi
 
 [ $INST_ZLIB -eq 1 ] && get_enzotools zlib-1.2.3.tar.bz2 
+[ $INST_PNG -eq 1 ] && get_enzotools libpng-1.2.43.tar.gz
 [ $INST_WXPYTHON -eq 1 ] && get_enzotools wxPython-src-2.8.10.1.tar.bz2
 get_enzotools Python-2.6.3.tgz
 get_enzotools numpy-1.3.0.tar.gz
@@ -272,6 +274,23 @@
     LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ZLIB_DIR}/lib/"
 fi
 
+if [ $INST_PNG -eq 1 ]
+then
+    if [ ! -e libpng-1.2.43/done ]
+    then
+        [ ! -e libpng-1.2.43 ] && tar xfj libpng-1.2.43.tar.bz2
+        echo "Installing PNG"
+        cd libpng-1.2.43
+        ( ./configure --prefix=${DEST_DIR}/ 2>&1 ) 1>> ${LOG_FILE} || do_exit
+        ( make install 2>&1 ) 1>> ${LOG_FILE} || do_exit
+        touch done
+        cd ..
+    fi
+    PNG_DIR=${DEST_DIR}
+    export LDFLAGS="${LDFLAGS} -L${PNG_DIR}/lib/ -L${PNG_DIR}/lib64/"
+    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${PNG_DIR}/lib/"
+fi
+
 if [ -z "$HDF5_DIR" ]
 then
     if [ ! -e hdf5-1.6.9/done ]
@@ -350,6 +369,7 @@
 
 echo "Installing yt"
 echo $HDF5_DIR > hdf5.cfg
+[ $INST_PNG -eq 1 ] && echo $PNG_DIR > png.cfg
 ( ${DEST_DIR}/bin/python2.6 setup.py develop 2>&1 ) 1>> ${LOG_FILE} || do_exit
 touch done
 cd $MY_PWD
diff -r bc63818ccbdc -r 9d03b622255d doc/install_script_osx.sh
--- a/doc/install_script_osx.sh	Wed Apr 14 00:51:48 2010 -0400
+++ b/doc/install_script_osx.sh	Wed Apr 14 09:32:50 2010 -0400
@@ -203,6 +203,7 @@
 
 echo "Installing yt (may need sudo)"
 echo $HDF5_DIR > hdf5.cfg
+echo /usr/X11 > png.cfg # I think this should work everywhere
 ( ${PY_DIR}/bin/python2.5 setup.py build_ext -i 2>&1 ) 1>> ${LOG_FILE} || do_exit
 ( sudo ${PY_DIR}/bin/python2.5 setup.py develop 2>&1 ) 1>> ${LOG_FILE} || do_exit
 touch done
diff -r bc63818ccbdc -r 9d03b622255d doc/install_script_osx106.sh
--- a/doc/install_script_osx106.sh	Wed Apr 14 00:51:48 2010 -0400
+++ b/doc/install_script_osx106.sh	Wed Apr 14 09:32:50 2010 -0400
@@ -204,6 +204,7 @@
 
 echo "Installing yt (may need sudo)"
 echo $HDF5_DIR > hdf5.cfg
+echo /usr/X11 > png.cfg # I think this should work everywhere
 ( ${PY_DIR}/bin/python2.6 setup.py build_ext -i 2>&1 ) 1>> ${LOG_FILE} || do_exit
 ( sudo ${PY_DIR}/bin/python2.6 setup.py develop 2>&1 ) 1>> ${LOG_FILE} || do_exit
 touch done
diff -r bc63818ccbdc -r 9d03b622255d yt/amr_utils.pyx
--- a/yt/amr_utils.pyx	Wed Apr 14 00:51:48 2010 -0400
+++ b/yt/amr_utils.pyx	Wed Apr 14 09:32:50 2010 -0400
@@ -42,3 +42,4 @@
 include "_amr_utils/VolumeIntegrator.pyx"
 include "_amr_utils/CICDeposit.pyx"
 include "_amr_utils/ContourFinding.pyx"
+include "_amr_utils/png_writer.pyx"
diff -r bc63818ccbdc -r 9d03b622255d yt/lagos/setup.py
--- a/yt/lagos/setup.py	Wed Apr 14 00:51:48 2010 -0400
+++ b/yt/lagos/setup.py	Wed Apr 14 09:32:50 2010 -0400
@@ -1,8 +1,6 @@
 #!/usr/bin/env python
 import setuptools
-import os, sys, os.path
-
-import os.path
+import os, sys
 
 def check_for_hdf5():
     # First up: HDF5_DIR in environment
diff -r bc63818ccbdc -r 9d03b622255d yt/setup.py
--- a/yt/setup.py	Wed Apr 14 00:51:48 2010 -0400
+++ b/yt/setup.py	Wed Apr 14 09:32:50 2010 -0400
@@ -1,5 +1,54 @@
 #!/usr/bin/env python
 import setuptools
+import os, sys
+
+def check_for_png():
+    # First up: HDF5_DIR in environment
+    if "PNG_DIR" in os.environ:
+        png_dir = os.environ["PNG_DIR"]
+        png_inc = os.path.join(png_dir, "include")
+        png_lib = os.path.join(png_dir, "lib")
+        print "PNG_LOCATION: PNG_DIR: %s, %s" % (png_inc, png_lib)
+        return (png_inc, png_lib)
+    # Next up, we try png.cfg
+    elif os.path.exists("png.cfg"):
+        png_dir = open("png.cfg").read().strip()
+        png_inc = os.path.join(png_dir, "include")
+        png_lib = os.path.join(png_dir, "lib")
+        print "PNG_LOCATION: png.cfg: %s, %s" % (png_inc, png_lib)
+        return (png_inc, png_lib)
+    # Now we see if ctypes can help us:
+    try:
+        import ctypes.util
+        png_libfile = ctypes.util.find_library("png")
+        if png_libfile is not None and os.path.isfile(png_libfile):
+            # Now we've gotten a library, but we'll need to figure out the
+            # includes if this is going to work.  It feels like there is a
+            # better way to pull off two directory names.
+            png_dir = os.path.dirname(os.path.dirname(png_libfile))
+            if os.path.isdir(os.path.join(png_dir, "include")) and \
+               os.path.isfile(os.path.join(png_dir, "include", "png.h")):
+                png_inc = os.path.join(png_dir, "include")
+                png_lib = os.path.join(png_dir, "lib")
+                print "PNG_LOCATION: png found in: %s, %s" % (png_inc, png_lib)
+                return png_inc, png_lib
+    except ImportError:
+        pass
+    # X11 is where it's located by default on OSX, although I am slightly
+    # reluctant to link against that one.
+    for png_dir in ["/usr/", "/usr/local/", "/usr/X11/"]:
+        if os.path.isfile(os.path.join(png_dir, "include", "png.h")):
+            if os.path.isdir(os.path.join(png_dir, "include")) and \
+               os.path.isfile(os.path.join(png_dir, "include", "png.h")):
+                png_inc = os.path.join(png_dir, "include")
+                png_lib = os.path.join(png_dir, "lib")
+                print "PNG_LOCATION: png found in: %s, %s" % (png_inc, png_lib)
+                return png_inc, png_lib
+    print "Reading png location from png.cfg failed."
+    print "Please place the base directory of your png install in png.cfg and restart."
+    print "(ex: \"echo '/usr/local/' > png.cfg\" )"
+    sys.exit(1)
+
 
 def configuration(parent_package='', top_path=None):
     from numpy.distutils.misc_util import Configuration
@@ -11,10 +60,14 @@
     config.add_subpackage('extensions')
     config.add_subpackage('parallel_tools')
     config.add_subpackage('data_objects')
+    png_inc, png_lib = check_for_png()
+    include_dirs=[png_inc]
+    library_dirs=[png_lib]
     config.add_extension("amr_utils", 
         ["yt/amr_utils.c", "yt/_amr_utils/FixedInterpolator.c"], 
-        include_dirs=["yt/_amr_utils/"],
-        libraries=["m"])
+        include_dirs=["yt/_amr_utils/", png_inc],
+        library_dirs=[png_lib],
+        libraries=["m", "png"])
     config.make_config_py()
     config.make_svn_version_py()
     return config



More information about the yt-svn mailing list