[yt-svn] commit/yt: 8 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Jul 1 10:20:57 PDT 2013


8 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/7be3be563bc3/
Changeset:   7be3be563bc3
Branch:      yt
User:        xarthisius
Date:        2013-06-22 11:12:31
Summary:     Search for hdf5 library/headers in default paths on posix systems. Fixes #597
Affected #:  1 file

diff -r 3a638f82a37eb6a647ca4cda18446d94a055f221 -r 7be3be563bc3d0d2d94b3c1e0956649a3bbe6969 yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -1,6 +1,64 @@
 #!/usr/bin/env python
 import setuptools
-import os, sys, os.path, glob
+import os
+import sys
+import os.path
+import glob
+
+
+# snatched from PyTables
+def add_from_path(envname, dirs):
+    try:
+        dirs.extend(os.environ[envname].split(os.pathsep))
+    except KeyError:
+        pass
+
+
+# snatched from PyTables
+def add_from_flags(envname, flag_key, dirs):
+    for flag in os.environ.get(envname, "").split():
+        if flag.startswith(flag_key):
+            dirs.append(flag[len(flag_key):])
+
+
+# snatched from PyTables
+def get_default_dirs():
+    default_header_dirs = []
+    add_from_path("CPATH", default_header_dirs)
+    add_from_path("C_INCLUDE_PATH", default_header_dirs)
+    add_from_flags("CPPFLAGS", "-I", default_header_dirs)
+    default_header_dirs.extend(['/usr/include', '/usr/local/include'])
+
+    default_library_dirs = []
+    add_from_flags("LDFLAGS", "-L", default_library_dirs)
+    default_library_dirs.extend(
+        os.path.join(_tree, _arch)
+        for _tree in ('/', '/usr', '/usr/local')
+        for _arch in ('lib64', 'lib')
+    )
+    return default_header_dirs, default_library_dirs
+
+
+def get_hdf5_include(header_dirs):
+    for inc_prefix in header_dirs:
+        if os.path.isfile(os.path.join(inc_prefix, "hdf5.h")):
+            return inc_prefix
+    return None
+
+
+def get_hdf5_lib(lib_dirs):
+    import ctypes
+    hdf5_libfile = ctypes.util.find_library("hdf5")
+    if os.path.isfile(hdf5_libfile):
+        return os.path.dirname(hdf5_libfile)
+    for lib_dir in lib_dirs:
+        try:
+            ctypes.CDLL(os.path.join(lib_dir, hdf5_libfile))
+            return lib_dir
+        except OSError:
+            pass
+    return None
+
 
 def check_for_hdf5():
     # First up: HDF5_DIR in environment
@@ -17,7 +75,16 @@
         hdf5_lib = os.path.join(hdf5_dir, "lib")
         print "HDF5_LOCATION: hdf5.cfg: %s, %s" % (hdf5_inc, hdf5_lib)
         return (hdf5_inc, hdf5_lib)
-    # Now we see if ctypes can help us:
+    if os.name == 'posix':
+        default_header_dirs, default_library_dirs = get_default_dirs()
+        hdf5_inc = get_hdf5_include(default_header_dirs)
+        hdf5_lib = get_hdf5_lib(default_library_dirs)
+        if None not in (hdf5_inc, hdf5_lib):
+            print(
+                "HDF5_LOCATION: HDF5 found in: %s, %s" % (hdf5_inc, hdf5_lib))
+            return (hdf5_inc, hdf5_lib)
+
+    # Now we see if ctypes can help us on non posix platform
     try:
         import ctypes.util
         hdf5_libfile = ctypes.util.find_library("hdf5")
@@ -31,8 +98,8 @@
                 hdf5_inc = os.path.join(hdf5_dir, "include")
                 hdf5_lib = os.path.join(hdf5_dir, "lib")
                 print "HDF5_LOCATION: HDF5 found in: %s, %s" % (hdf5_inc,
-                    hdf5_lib)
-                return hdf5_inc, hdf5_lib
+                                                                hdf5_lib)
+                return (hdf5_inc, hdf5_lib)
     except ImportError:
         pass
     print "Reading HDF5 location from hdf5.cfg failed."
@@ -55,22 +122,23 @@
     config.add_subpackage("parallel_tools")
     config.add_subpackage("lib")
     config.add_extension("data_point_utilities",
-                "yt/utilities/data_point_utilities.c", libraries=["m"])
+                         "yt/utilities/data_point_utilities.c",
+                         libraries=["m"])
     config.add_subpackage("tests")
     hdf5_inc, hdf5_lib = check_for_hdf5()
     include_dirs = [hdf5_inc]
     library_dirs = [hdf5_lib]
     config.add_extension("hdf5_light_reader",
-                        "yt/utilities/hdf5_light_reader.c",
+                         "yt/utilities/hdf5_light_reader.c",
                          define_macros=[("H5_USE_16_API", True)],
                          libraries=["m", "hdf5"],
                          library_dirs=library_dirs, include_dirs=include_dirs)
     config.add_extension("libconfig_wrapper",
-        ["yt/utilities/libconfig_wrapper.pyx"] +
-         glob.glob("yt/utilities/_libconfig/*.c"),
-        include_dirs=["yt/utilities/_libconfig/"],
-        define_macros=[("HAVE_XLOCALE_H", True)]
-        )
+                         ["yt/utilities/libconfig_wrapper.pyx"] +
+                         glob.glob("yt/utilities/_libconfig/*.c"),
+                         include_dirs=["yt/utilities/_libconfig/"],
+                         define_macros=[("HAVE_XLOCALE_H", True)]
+                         )
     config.make_config_py()  # installs __config__.py
-    #config.make_svn_version_py()
+    # config.make_svn_version_py()
     return config


https://bitbucket.org/yt_analysis/yt/commits/19b30715ff0e/
Changeset:   19b30715ff0e
Branch:      yt
User:        xarthisius
Date:        2013-06-23 13:40:41
Summary:     Refactor code responsible for detecting lib/include paths from env var, cfg file and by using ctypes respectively
Affected #:  2 files

diff -r 7be3be563bc3d0d2d94b3c1e0956649a3bbe6969 -r 19b30715ff0e758fddbcb8ee077279d2497918c4 yt/utilities/lib/setup.py
--- a/yt/utilities/lib/setup.py
+++ b/yt/utilities/lib/setup.py
@@ -1,24 +1,27 @@
 #!/usr/bin/env python
 import setuptools
 import os, sys, os.path, glob, \
-  tempfile, subprocess, shutil
+    tempfile, subprocess, shutil
+from yt.utilities.setup import \
+    get_location_from_env, get_location_from_cfg, get_location_from_ctypes
 
 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)
+        return get_location_from_env("PNG_DIR")
     # 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 get_location_from_cfg("png.cfg")
+    if os.name == 'posix':
+        png_inc, png_lib = get_location_from_ctypes("png.h", "png")
+    if None not in (png_inc, png_lib):
+        print(
+            "PNG_LOCATION: PNG found via ctypes in: %s, %s" \
+                % (png_inc, png_lib)
+        )
         return (png_inc, png_lib)
-    # Now we see if ctypes can help us:
+
+    # Now we see if ctypes can help us on non posix platform
     try:
         import ctypes.util
         png_libfile = ctypes.util.find_library("png")
@@ -53,19 +56,20 @@
 def check_for_freetype():
     # First up: environment
     if "FTYPE_DIR" in os.environ:
-        freetype_dir = os.environ["FTYPE_DIR"]
-        freetype_inc = os.path.join(freetype_dir, "include")
-        freetype_lib = os.path.join(freetype_dir, "lib")
-        print "FTYPE_LOCATION: FTYPE_DIR: %s, %s" % (freetype_inc, freetype_lib)
-        return (freetype_inc, freetype_lib)
+        return get_location_from_env("FTYPE_DIR")
     # Next up, we try freetype.cfg
     elif os.path.exists("freetype.cfg"):
-        freetype_dir = open("freetype.cfg").read().strip()
-        freetype_inc = os.path.join(freetype_dir, "include")
-        freetype_lib = os.path.join(freetype_dir, "lib")
-        print "FTYPE_LOCATION: freetype.cfg: %s, %s" % (freetype_inc, freetype_lib)
+        return get_location_from_cfg("freetype.cfg")
+    if os.name == 'posix':
+        freetype_inc, freetype_lib = \
+                get_location_from_ctypes("ft2build.h", "freetype")
+    if None not in (freetype_inc, freetype_lib):
+        print(
+            "FTYPE_LOCATION: freetype found via ctypes in: %s, %s" \
+                % (freetype_inc, freetype_lib)
+        )
         return (freetype_inc, freetype_lib)
-    # Now we see if ctypes can help us:
+    # Now we see if ctypes can help us on non posix platform
     try:
         import ctypes.util
         freetype_libfile = ctypes.util.find_library("freetype")
@@ -122,7 +126,7 @@
     with open(os.devnull, 'w') as fnull:
         exit_code = subprocess.call([compiler, '-fopenmp', filename],
                                     stdout=fnull, stderr=fnull)
-        
+
     # Clean up
     file.close()
     os.chdir(curdir)

diff -r 7be3be563bc3d0d2d94b3c1e0956649a3bbe6969 -r 19b30715ff0e758fddbcb8ee077279d2497918c4 yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -39,50 +39,64 @@
     return default_header_dirs, default_library_dirs
 
 
-def get_hdf5_include(header_dirs):
-    for inc_prefix in header_dirs:
-        if os.path.isfile(os.path.join(inc_prefix, "hdf5.h")):
-            return inc_prefix
-    return None
+def get_location_from_env(env):
+    env_dir = os.environ[env]
+    env_inc = os.path.join(env_dir, "include")
+    env_lib = os.path.join(env_dir, "lib")
+    print "%s_LOCATION: %s: %s, %s" \
+        % (env.split('_')[0], env, env_inc, env_lib)
+    return (env_inc, env_lib)
 
 
-def get_hdf5_lib(lib_dirs):
-    import ctypes
-    hdf5_libfile = ctypes.util.find_library("hdf5")
-    if os.path.isfile(hdf5_libfile):
-        return os.path.dirname(hdf5_libfile)
-    for lib_dir in lib_dirs:
+def get_location_from_cfg(cfg):
+    cfg_dir = open(cfg).read().strip()
+    cfg_inc = os.path.join(cfg_dir, "include")
+    cfg_lib = os.path.join(cfg_dir, "lib")
+    print "%s_LOCATION: %s: %s, %s" \
+        % (cfg.split('.')[0].upper(), cfg, cfg_inc, cfg_lib)
+    return (cfg_inc, cfg_lib)
+
+
+def get_location_from_ctypes(header, library):
+    try:
+        import ctypes
+        import ctypes.util
+    except ImportError:
+        return (None, None)
+
+    target_libfile = ctypes.util.find_library(library)
+    default_header_dirs, default_library_dirs = get_default_dirs()
+    target_inc, target_libdir = None, None
+    for inc_prefix in default_header_dirs:
+        if os.path.isfile(os.path.join(inc_prefix, header)):
+            target_inc = inc_prefix
+
+    if os.path.isfile(target_libfile):
+        return os.path.dirname(target_libfile)
+    for lib_dir in default_library_dirs:
         try:
-            ctypes.CDLL(os.path.join(lib_dir, hdf5_libfile))
-            return lib_dir
+            ctypes.CDLL(os.path.join(lib_dir, target_libfile))
+            target_libdir = lib_dir
         except OSError:
             pass
-    return None
+    return (target_inc, target_libdir)
 
 
 def check_for_hdf5():
     # First up: HDF5_DIR in environment
     if "HDF5_DIR" in os.environ:
-        hdf5_dir = os.environ["HDF5_DIR"]
-        hdf5_inc = os.path.join(hdf5_dir, "include")
-        hdf5_lib = os.path.join(hdf5_dir, "lib")
-        print "HDF5_LOCATION: HDF5_DIR: %s, %s" % (hdf5_inc, hdf5_lib)
-        return (hdf5_inc, hdf5_lib)
+        return get_location_from_env("HDF5_DIR")
     # Next up, we try hdf5.cfg
     elif os.path.exists("hdf5.cfg"):
-        hdf5_dir = open("hdf5.cfg").read().strip()
-        hdf5_inc = os.path.join(hdf5_dir, "include")
-        hdf5_lib = os.path.join(hdf5_dir, "lib")
-        print "HDF5_LOCATION: hdf5.cfg: %s, %s" % (hdf5_inc, hdf5_lib)
+        return get_location_from_cfg("hdf5.cfg")
+    if os.name == 'posix':
+        hdf5_inc, hdf5_lib = get_location_from_ctypes("hdf5.h", "hdf5")
+    if None not in (hdf5_inc, hdf5_lib):
+        print(
+            "HDF5_LOCATION: HDF5 found via ctypes in: %s, %s"
+            % (hdf5_inc, hdf5_lib)
+        )
         return (hdf5_inc, hdf5_lib)
-    if os.name == 'posix':
-        default_header_dirs, default_library_dirs = get_default_dirs()
-        hdf5_inc = get_hdf5_include(default_header_dirs)
-        hdf5_lib = get_hdf5_lib(default_library_dirs)
-        if None not in (hdf5_inc, hdf5_lib):
-            print(
-                "HDF5_LOCATION: HDF5 found in: %s, %s" % (hdf5_inc, hdf5_lib))
-            return (hdf5_inc, hdf5_lib)
 
     # Now we see if ctypes can help us on non posix platform
     try:


https://bitbucket.org/yt_analysis/yt/commits/39b9d0d919db/
Changeset:   39b9d0d919db
Branch:      yt
User:        xarthisius
Date:        2013-06-23 13:48:21
Summary:     Add /usr/X11 to default search paths, remove duplicated code
Affected #:  2 files

diff -r 19b30715ff0e758fddbcb8ee077279d2497918c4 -r 39b9d0d919db0d9891e701daabda700f75114495 yt/utilities/lib/setup.py
--- a/yt/utilities/lib/setup.py
+++ b/yt/utilities/lib/setup.py
@@ -12,6 +12,7 @@
     # Next up, we try png.cfg
     elif os.path.exists("png.cfg"):
         return get_location_from_cfg("png.cfg")
+    # Now we see if ctypes can help us
     if os.name == 'posix':
         png_inc, png_lib = get_location_from_ctypes("png.h", "png")
     if None not in (png_inc, png_lib):
@@ -21,33 +22,6 @@
         )
         return (png_inc, png_lib)
 
-    # Now we see if ctypes can help us on non posix platform
-    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\" )"
@@ -60,6 +34,7 @@
     # Next up, we try freetype.cfg
     elif os.path.exists("freetype.cfg"):
         return get_location_from_cfg("freetype.cfg")
+    # Now we see if ctypes can help us
     if os.name == 'posix':
         freetype_inc, freetype_lib = \
                 get_location_from_ctypes("ft2build.h", "freetype")
@@ -69,33 +44,7 @@
                 % (freetype_inc, freetype_lib)
         )
         return (freetype_inc, freetype_lib)
-    # Now we see if ctypes can help us on non posix platform
-    try:
-        import ctypes.util
-        freetype_libfile = ctypes.util.find_library("freetype")
-        if freetype_libfile is not None and os.path.isfile(freetype_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.
-            freetype_dir = os.path.dirname(os.path.dirname(freetype_libfile))
-            if os.path.isdir(os.path.join(freetype_dir, "include")) and \
-               os.path.isfile(os.path.join(freetype_dir, "include", "ft2build.h")):
-                freetype_inc = os.path.join(freetype_dir, "include")
-                freetype_lib = os.path.join(freetype_dir, "lib")
-                print "FTYPE_LOCATION: freetype found in: %s, %s" % (freetype_inc, freetype_lib)
-                return freetype_inc, freetype_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 freetype_dir in ["/usr/", "/usr/local/", "/usr/X11/"]:
-        if os.path.isfile(os.path.join(freetype_dir, "include", "ft2build.h")):
-            if os.path.isdir(os.path.join(freetype_dir, "include")) and \
-               os.path.isfile(os.path.join(freetype_dir, "include", "ft2build.h")):
-                freetype_inc = os.path.join(freetype_dir, "include")
-                freetype_lib = os.path.join(freetype_dir, "lib")
-                print "FTYPE_LOCATION: freetype found in: %s, %s" % (freetype_inc, freetype_lib)
-                return freetype_inc, freetype_lib
+
     print "Reading freetype location from freetype.cfg failed."
     print "Please place the base directory of your freetype install in freetype.cfg and restart."
     print "(ex: \"echo '/usr/local/' > freetype.cfg\" )"

diff -r 19b30715ff0e758fddbcb8ee077279d2497918c4 -r 39b9d0d919db0d9891e701daabda700f75114495 yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -27,13 +27,15 @@
     add_from_path("CPATH", default_header_dirs)
     add_from_path("C_INCLUDE_PATH", default_header_dirs)
     add_from_flags("CPPFLAGS", "-I", default_header_dirs)
-    default_header_dirs.extend(['/usr/include', '/usr/local/include'])
+    default_header_dirs.extend(
+        ['/usr/include', '/usr/local/include', '/usr/X11']
+    )
 
     default_library_dirs = []
     add_from_flags("LDFLAGS", "-L", default_library_dirs)
     default_library_dirs.extend(
         os.path.join(_tree, _arch)
-        for _tree in ('/', '/usr', '/usr/local')
+        for _tree in ('/', '/usr', '/usr/local', '/usr/X11')
         for _arch in ('lib64', 'lib')
     )
     return default_header_dirs, default_library_dirs
@@ -89,6 +91,7 @@
     # Next up, we try hdf5.cfg
     elif os.path.exists("hdf5.cfg"):
         return get_location_from_cfg("hdf5.cfg")
+    # Now we see if ctypes can help us
     if os.name == 'posix':
         hdf5_inc, hdf5_lib = get_location_from_ctypes("hdf5.h", "hdf5")
     if None not in (hdf5_inc, hdf5_lib):
@@ -98,24 +101,6 @@
         )
         return (hdf5_inc, hdf5_lib)
 
-    # Now we see if ctypes can help us on non posix platform
-    try:
-        import ctypes.util
-        hdf5_libfile = ctypes.util.find_library("hdf5")
-        if hdf5_libfile is not None and os.path.isfile(hdf5_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.
-            hdf5_dir = os.path.dirname(os.path.dirname(hdf5_libfile))
-            if os.path.isdir(os.path.join(hdf5_dir, "include")) and \
-               os.path.isfile(os.path.join(hdf5_dir, "include", "hdf5.h")):
-                hdf5_inc = os.path.join(hdf5_dir, "include")
-                hdf5_lib = os.path.join(hdf5_dir, "lib")
-                print "HDF5_LOCATION: HDF5 found in: %s, %s" % (hdf5_inc,
-                                                                hdf5_lib)
-                return (hdf5_inc, hdf5_lib)
-    except ImportError:
-        pass
     print "Reading HDF5 location from hdf5.cfg failed."
     print "Please place the base directory of your"
     print "HDF5 install in hdf5.cfg and restart."


https://bitbucket.org/yt_analysis/yt/commits/7bdf4e01e6cf/
Changeset:   7bdf4e01e6cf
Branch:      yt
User:        xarthisius
Date:        2013-06-23 13:59:18
Summary:     Further refactoring of the code that checks for dependencies
Affected #:  2 files

diff -r 39b9d0d919db0d9891e701daabda700f75114495 -r 7bdf4e01e6cfd57df79ebfb7ee7e3b3eb67a294c yt/utilities/lib/setup.py
--- a/yt/utilities/lib/setup.py
+++ b/yt/utilities/lib/setup.py
@@ -3,53 +3,18 @@
 import os, sys, os.path, glob, \
     tempfile, subprocess, shutil
 from yt.utilities.setup import \
-    get_location_from_env, get_location_from_cfg, get_location_from_ctypes
+    check_for_dependencies
+
 
 def check_for_png():
-    # First up: HDF5_DIR in environment
-    if "PNG_DIR" in os.environ:
-        return get_location_from_env("PNG_DIR")
-    # Next up, we try png.cfg
-    elif os.path.exists("png.cfg"):
-        return get_location_from_cfg("png.cfg")
-    # Now we see if ctypes can help us
-    if os.name == 'posix':
-        png_inc, png_lib = get_location_from_ctypes("png.h", "png")
-    if None not in (png_inc, png_lib):
-        print(
-            "PNG_LOCATION: PNG found via ctypes in: %s, %s" \
-                % (png_inc, png_lib)
-        )
-        return (png_inc, png_lib)
+    return check_for_dependencies("PNG_DIR", "png.cfg", "png.h", "png")
 
-    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 check_for_freetype():
-    # First up: environment
-    if "FTYPE_DIR" in os.environ:
-        return get_location_from_env("FTYPE_DIR")
-    # Next up, we try freetype.cfg
-    elif os.path.exists("freetype.cfg"):
-        return get_location_from_cfg("freetype.cfg")
-    # Now we see if ctypes can help us
-    if os.name == 'posix':
-        freetype_inc, freetype_lib = \
-                get_location_from_ctypes("ft2build.h", "freetype")
-    if None not in (freetype_inc, freetype_lib):
-        print(
-            "FTYPE_LOCATION: freetype found via ctypes in: %s, %s" \
-                % (freetype_inc, freetype_lib)
-        )
-        return (freetype_inc, freetype_lib)
+    return check_for_dependencies(
+        "FTYPE_DIR", "freetype.cfg", "ft2build.h", "freetype"
+    )
 
-    print "Reading freetype location from freetype.cfg failed."
-    print "Please place the base directory of your freetype install in freetype.cfg and restart."
-    print "(ex: \"echo '/usr/local/' > freetype.cfg\" )"
-    print "You can locate this by looking for the file ft2build.h"
-    sys.exit(1)
 
 def check_for_openmp():
     # Create a temporary directory

diff -r 39b9d0d919db0d9891e701daabda700f75114495 -r 7bdf4e01e6cfd57df79ebfb7ee7e3b3eb67a294c yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -84,30 +84,34 @@
     return (target_inc, target_libdir)
 
 
-def check_for_hdf5():
-    # First up: HDF5_DIR in environment
-    if "HDF5_DIR" in os.environ:
-        return get_location_from_env("HDF5_DIR")
-    # Next up, we try hdf5.cfg
-    elif os.path.exists("hdf5.cfg"):
-        return get_location_from_cfg("hdf5.cfg")
+def check_for_dependencies(env, cfg, header, library):
+    # First up: check in environment
+    if env in os.environ:
+        return get_location_from_env(env)
+    # Next up, we try config file
+    elif os.path.exists(cfg):
+        return get_location_from_cfg(cfg)
     # Now we see if ctypes can help us
     if os.name == 'posix':
-        hdf5_inc, hdf5_lib = get_location_from_ctypes("hdf5.h", "hdf5")
-    if None not in (hdf5_inc, hdf5_lib):
+        target_inc, target_lib = get_location_from_ctypes(header, library)
+    if None not in (target_inc, target_lib):
         print(
-            "HDF5_LOCATION: HDF5 found via ctypes in: %s, %s"
-            % (hdf5_inc, hdf5_lib)
+            "%s_LOCATION: %s found via ctypes in: %s, %s"
+            % (env.split('_')[0], env.split('_')[0], target_inc, target_lib)
         )
-        return (hdf5_inc, hdf5_lib)
+        return (target_inc, target_lib)
 
-    print "Reading HDF5 location from hdf5.cfg failed."
-    print "Please place the base directory of your"
-    print "HDF5 install in hdf5.cfg and restart."
-    print "(ex: \"echo '/usr/local/' > hdf5.cfg\" )"
+    print("Reading %s location from %s failed." % (env.split('_')[0], cfg))
+    print("Please place the base directory of your")
+    print("%s install in %s and restart." % (env.split('_')[0], cfg))
+    print("(ex: \"echo '/usr/local/' > %s\" )" % cfg)
+    print("You can locate the path by looking for %s" % header)
     sys.exit(1)
 
 
+def check_for_hdf5():
+    return check_for_dependencies("HDF5_DIR", "hdf5.cfg", "hdf5.h", "hdf5")
+
 def configuration(parent_package='', top_path=None):
     from numpy.distutils.misc_util import Configuration
     config = Configuration('utilities', parent_package, top_path)


https://bitbucket.org/yt_analysis/yt/commits/b66b8940338f/
Changeset:   b66b8940338f
Branch:      yt
User:        xarthisius
Date:        2013-06-25 10:28:34
Summary:     Return a proper tuple of header and libdir if libfile is found directly via ctypes.util. Thanks Nathan!
Affected #:  1 file

diff -r 7bdf4e01e6cfd57df79ebfb7ee7e3b3eb67a294c -r b66b8940338fe8d36a768668983fe007fff0241c yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -74,7 +74,7 @@
             target_inc = inc_prefix
 
     if os.path.isfile(target_libfile):
-        return os.path.dirname(target_libfile)
+        return (target_inc, os.path.dirname(target_libfile))
     for lib_dir in default_library_dirs:
         try:
             ctypes.CDLL(os.path.join(lib_dir, target_libfile))


https://bitbucket.org/yt_analysis/yt/commits/6ac34027d89b/
Changeset:   6ac34027d89b
Branch:      yt
User:        xarthisius
Date:        2013-06-27 07:57:05
Summary:     Check if target_libfile is not None before trying to invoke isfile on it. Thanks to Nathan for catching this. Remove unused setuptools
Affected #:  1 file

diff -r b66b8940338fe8d36a768668983fe007fff0241c -r 6ac34027d89b1dad038ae127066206df4ff4a0b0 yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-import setuptools
 import os
 import sys
 import os.path
@@ -66,14 +65,14 @@
     except ImportError:
         return (None, None)
 
-    target_libfile = ctypes.util.find_library(library)
     default_header_dirs, default_library_dirs = get_default_dirs()
     target_inc, target_libdir = None, None
     for inc_prefix in default_header_dirs:
         if os.path.isfile(os.path.join(inc_prefix, header)):
             target_inc = inc_prefix
 
-    if os.path.isfile(target_libfile):
+    target_libfile = ctypes.util.find_library(library)
+    if target_libfile is not None and os.path.isfile(target_libfile):
         return (target_inc, os.path.dirname(target_libfile))
     for lib_dir in default_library_dirs:
         try:


https://bitbucket.org/yt_analysis/yt/commits/ac8b89a5f6ed/
Changeset:   ac8b89a5f6ed
Branch:      yt
User:        xarthisius
Date:        2013-06-30 11:49:11
Summary:     Sanitize get_location_from_ctypes
Affected #:  1 file

diff -r 6ac34027d89b1dad038ae127066206df4ff4a0b0 -r ac8b89a5f6ed1199a94efef0c4915430bbd5dffb yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -44,8 +44,8 @@
     env_dir = os.environ[env]
     env_inc = os.path.join(env_dir, "include")
     env_lib = os.path.join(env_dir, "lib")
-    print "%s_LOCATION: %s: %s, %s" \
-        % (env.split('_')[0], env, env_inc, env_lib)
+    print("%s_LOCATION: %s: %s, %s"
+          % (env.split('_')[0], env, env_inc, env_lib))
     return (env_inc, env_lib)
 
 
@@ -53,11 +53,21 @@
     cfg_dir = open(cfg).read().strip()
     cfg_inc = os.path.join(cfg_dir, "include")
     cfg_lib = os.path.join(cfg_dir, "lib")
-    print "%s_LOCATION: %s: %s, %s" \
-        % (cfg.split('.')[0].upper(), cfg, cfg_inc, cfg_lib)
+    print("%s_LOCATION: %s: %s, %s"
+          % (cfg.split('.')[0].upper(), cfg, cfg_inc, cfg_lib))
     return (cfg_inc, cfg_lib)
 
 
+def check_prefix(inc_dir, lib_dir):
+    prefix = os.path.commonprefix([inc_dir, lib_dir]).rstrip('/\\')
+    if prefix is not '' and prefix == os.path.dirname(inc_dir):
+        return (inc_dir, lib_dir)
+    else:
+        print("It seems that include prefix is different from lib prefix")
+        print("Please use either env variable or cfg to set proper path")
+        return (None, None)
+
+
 def get_location_from_ctypes(header, library):
     try:
         import ctypes
@@ -73,14 +83,14 @@
 
     target_libfile = ctypes.util.find_library(library)
     if target_libfile is not None and os.path.isfile(target_libfile):
-        return (target_inc, os.path.dirname(target_libfile))
+        return check_prefix(target_inc, os.path.dirname(target_libfile))
     for lib_dir in default_library_dirs:
         try:
             ctypes.CDLL(os.path.join(lib_dir, target_libfile))
             target_libdir = lib_dir
         except OSError:
             pass
-    return (target_inc, target_libdir)
+    return check_prefix(target_inc, target_libdir)
 
 
 def check_for_dependencies(env, cfg, header, library):
@@ -111,6 +121,7 @@
 def check_for_hdf5():
     return check_for_dependencies("HDF5_DIR", "hdf5.cfg", "hdf5.h", "hdf5")
 
+
 def configuration(parent_package='', top_path=None):
     from numpy.distutils.misc_util import Configuration
     config = Configuration('utilities', parent_package, top_path)


https://bitbucket.org/yt_analysis/yt/commits/b67a988e966d/
Changeset:   b67a988e966d
Branch:      yt
User:        ngoldbaum
Date:        2013-07-01 19:20:54
Summary:     Merged in xarthisius/yt (pull request #534)

Search for hdf5 library/headers in default paths on posix systems. Fixes #597
Affected #:  2 files

diff -r 74891da30e86ad33ecad7614e1e10e832ff9bab2 -r b67a988e966df8f09e6783ca78f5d7050fd1b14d yt/utilities/lib/setup.py
--- a/yt/utilities/lib/setup.py
+++ b/yt/utilities/lib/setup.py
@@ -1,102 +1,20 @@
 #!/usr/bin/env python
 import setuptools
 import os, sys, os.path, glob, \
-  tempfile, subprocess, shutil
+    tempfile, subprocess, shutil
+from yt.utilities.setup import \
+    check_for_dependencies
+
 
 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)
+    return check_for_dependencies("PNG_DIR", "png.cfg", "png.h", "png")
+
 
 def check_for_freetype():
-    # First up: environment
-    if "FTYPE_DIR" in os.environ:
-        freetype_dir = os.environ["FTYPE_DIR"]
-        freetype_inc = os.path.join(freetype_dir, "include")
-        freetype_lib = os.path.join(freetype_dir, "lib")
-        print "FTYPE_LOCATION: FTYPE_DIR: %s, %s" % (freetype_inc, freetype_lib)
-        return (freetype_inc, freetype_lib)
-    # Next up, we try freetype.cfg
-    elif os.path.exists("freetype.cfg"):
-        freetype_dir = open("freetype.cfg").read().strip()
-        freetype_inc = os.path.join(freetype_dir, "include")
-        freetype_lib = os.path.join(freetype_dir, "lib")
-        print "FTYPE_LOCATION: freetype.cfg: %s, %s" % (freetype_inc, freetype_lib)
-        return (freetype_inc, freetype_lib)
-    # Now we see if ctypes can help us:
-    try:
-        import ctypes.util
-        freetype_libfile = ctypes.util.find_library("freetype")
-        if freetype_libfile is not None and os.path.isfile(freetype_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.
-            freetype_dir = os.path.dirname(os.path.dirname(freetype_libfile))
-            if os.path.isdir(os.path.join(freetype_dir, "include")) and \
-               os.path.isfile(os.path.join(freetype_dir, "include", "ft2build.h")):
-                freetype_inc = os.path.join(freetype_dir, "include")
-                freetype_lib = os.path.join(freetype_dir, "lib")
-                print "FTYPE_LOCATION: freetype found in: %s, %s" % (freetype_inc, freetype_lib)
-                return freetype_inc, freetype_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 freetype_dir in ["/usr/", "/usr/local/", "/usr/X11/"]:
-        if os.path.isfile(os.path.join(freetype_dir, "include", "ft2build.h")):
-            if os.path.isdir(os.path.join(freetype_dir, "include")) and \
-               os.path.isfile(os.path.join(freetype_dir, "include", "ft2build.h")):
-                freetype_inc = os.path.join(freetype_dir, "include")
-                freetype_lib = os.path.join(freetype_dir, "lib")
-                print "FTYPE_LOCATION: freetype found in: %s, %s" % (freetype_inc, freetype_lib)
-                return freetype_inc, freetype_lib
-    print "Reading freetype location from freetype.cfg failed."
-    print "Please place the base directory of your freetype install in freetype.cfg and restart."
-    print "(ex: \"echo '/usr/local/' > freetype.cfg\" )"
-    print "You can locate this by looking for the file ft2build.h"
-    sys.exit(1)
+    return check_for_dependencies(
+        "FTYPE_DIR", "freetype.cfg", "ft2build.h", "freetype"
+    )
+
 
 def check_for_openmp():
     # Create a temporary directory
@@ -122,7 +40,7 @@
     with open(os.devnull, 'w') as fnull:
         exit_code = subprocess.call([compiler, '-fopenmp', filename],
                                     stdout=fnull, stderr=fnull)
-        
+
     # Clean up
     file.close()
     os.chdir(curdir)

diff -r 74891da30e86ad33ecad7614e1e10e832ff9bab2 -r b67a988e966df8f09e6783ca78f5d7050fd1b14d yt/utilities/setup.py
--- a/yt/utilities/setup.py
+++ b/yt/utilities/setup.py
@@ -1,45 +1,125 @@
 #!/usr/bin/env python
-import setuptools
-import os, sys, os.path, glob
+import os
+import sys
+import os.path
+import glob
+
+
+# snatched from PyTables
+def add_from_path(envname, dirs):
+    try:
+        dirs.extend(os.environ[envname].split(os.pathsep))
+    except KeyError:
+        pass
+
+
+# snatched from PyTables
+def add_from_flags(envname, flag_key, dirs):
+    for flag in os.environ.get(envname, "").split():
+        if flag.startswith(flag_key):
+            dirs.append(flag[len(flag_key):])
+
+
+# snatched from PyTables
+def get_default_dirs():
+    default_header_dirs = []
+    add_from_path("CPATH", default_header_dirs)
+    add_from_path("C_INCLUDE_PATH", default_header_dirs)
+    add_from_flags("CPPFLAGS", "-I", default_header_dirs)
+    default_header_dirs.extend(
+        ['/usr/include', '/usr/local/include', '/usr/X11']
+    )
+
+    default_library_dirs = []
+    add_from_flags("LDFLAGS", "-L", default_library_dirs)
+    default_library_dirs.extend(
+        os.path.join(_tree, _arch)
+        for _tree in ('/', '/usr', '/usr/local', '/usr/X11')
+        for _arch in ('lib64', 'lib')
+    )
+    return default_header_dirs, default_library_dirs
+
+
+def get_location_from_env(env):
+    env_dir = os.environ[env]
+    env_inc = os.path.join(env_dir, "include")
+    env_lib = os.path.join(env_dir, "lib")
+    print("%s_LOCATION: %s: %s, %s"
+          % (env.split('_')[0], env, env_inc, env_lib))
+    return (env_inc, env_lib)
+
+
+def get_location_from_cfg(cfg):
+    cfg_dir = open(cfg).read().strip()
+    cfg_inc = os.path.join(cfg_dir, "include")
+    cfg_lib = os.path.join(cfg_dir, "lib")
+    print("%s_LOCATION: %s: %s, %s"
+          % (cfg.split('.')[0].upper(), cfg, cfg_inc, cfg_lib))
+    return (cfg_inc, cfg_lib)
+
+
+def check_prefix(inc_dir, lib_dir):
+    prefix = os.path.commonprefix([inc_dir, lib_dir]).rstrip('/\\')
+    if prefix is not '' and prefix == os.path.dirname(inc_dir):
+        return (inc_dir, lib_dir)
+    else:
+        print("It seems that include prefix is different from lib prefix")
+        print("Please use either env variable or cfg to set proper path")
+        return (None, None)
+
+
+def get_location_from_ctypes(header, library):
+    try:
+        import ctypes
+        import ctypes.util
+    except ImportError:
+        return (None, None)
+
+    default_header_dirs, default_library_dirs = get_default_dirs()
+    target_inc, target_libdir = None, None
+    for inc_prefix in default_header_dirs:
+        if os.path.isfile(os.path.join(inc_prefix, header)):
+            target_inc = inc_prefix
+
+    target_libfile = ctypes.util.find_library(library)
+    if target_libfile is not None and os.path.isfile(target_libfile):
+        return check_prefix(target_inc, os.path.dirname(target_libfile))
+    for lib_dir in default_library_dirs:
+        try:
+            ctypes.CDLL(os.path.join(lib_dir, target_libfile))
+            target_libdir = lib_dir
+        except OSError:
+            pass
+    return check_prefix(target_inc, target_libdir)
+
+
+def check_for_dependencies(env, cfg, header, library):
+    # First up: check in environment
+    if env in os.environ:
+        return get_location_from_env(env)
+    # Next up, we try config file
+    elif os.path.exists(cfg):
+        return get_location_from_cfg(cfg)
+    # Now we see if ctypes can help us
+    if os.name == 'posix':
+        target_inc, target_lib = get_location_from_ctypes(header, library)
+    if None not in (target_inc, target_lib):
+        print(
+            "%s_LOCATION: %s found via ctypes in: %s, %s"
+            % (env.split('_')[0], env.split('_')[0], target_inc, target_lib)
+        )
+        return (target_inc, target_lib)
+
+    print("Reading %s location from %s failed." % (env.split('_')[0], cfg))
+    print("Please place the base directory of your")
+    print("%s install in %s and restart." % (env.split('_')[0], cfg))
+    print("(ex: \"echo '/usr/local/' > %s\" )" % cfg)
+    print("You can locate the path by looking for %s" % header)
+    sys.exit(1)
+
 
 def check_for_hdf5():
-    # First up: HDF5_DIR in environment
-    if "HDF5_DIR" in os.environ:
-        hdf5_dir = os.environ["HDF5_DIR"]
-        hdf5_inc = os.path.join(hdf5_dir, "include")
-        hdf5_lib = os.path.join(hdf5_dir, "lib")
-        print "HDF5_LOCATION: HDF5_DIR: %s, %s" % (hdf5_inc, hdf5_lib)
-        return (hdf5_inc, hdf5_lib)
-    # Next up, we try hdf5.cfg
-    elif os.path.exists("hdf5.cfg"):
-        hdf5_dir = open("hdf5.cfg").read().strip()
-        hdf5_inc = os.path.join(hdf5_dir, "include")
-        hdf5_lib = os.path.join(hdf5_dir, "lib")
-        print "HDF5_LOCATION: hdf5.cfg: %s, %s" % (hdf5_inc, hdf5_lib)
-        return (hdf5_inc, hdf5_lib)
-    # Now we see if ctypes can help us:
-    try:
-        import ctypes.util
-        hdf5_libfile = ctypes.util.find_library("hdf5")
-        if hdf5_libfile is not None and os.path.isfile(hdf5_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.
-            hdf5_dir = os.path.dirname(os.path.dirname(hdf5_libfile))
-            if os.path.isdir(os.path.join(hdf5_dir, "include")) and \
-               os.path.isfile(os.path.join(hdf5_dir, "include", "hdf5.h")):
-                hdf5_inc = os.path.join(hdf5_dir, "include")
-                hdf5_lib = os.path.join(hdf5_dir, "lib")
-                print "HDF5_LOCATION: HDF5 found in: %s, %s" % (hdf5_inc,
-                    hdf5_lib)
-                return hdf5_inc, hdf5_lib
-    except ImportError:
-        pass
-    print "Reading HDF5 location from hdf5.cfg failed."
-    print "Please place the base directory of your"
-    print "HDF5 install in hdf5.cfg and restart."
-    print "(ex: \"echo '/usr/local/' > hdf5.cfg\" )"
-    sys.exit(1)
+    return check_for_dependencies("HDF5_DIR", "hdf5.cfg", "hdf5.h", "hdf5")
 
 
 def configuration(parent_package='', top_path=None):
@@ -55,22 +135,23 @@
     config.add_subpackage("parallel_tools")
     config.add_subpackage("lib")
     config.add_extension("data_point_utilities",
-                "yt/utilities/data_point_utilities.c", libraries=["m"])
+                         "yt/utilities/data_point_utilities.c",
+                         libraries=["m"])
     config.add_subpackage("tests")
     hdf5_inc, hdf5_lib = check_for_hdf5()
     include_dirs = [hdf5_inc]
     library_dirs = [hdf5_lib]
     config.add_extension("hdf5_light_reader",
-                        "yt/utilities/hdf5_light_reader.c",
+                         "yt/utilities/hdf5_light_reader.c",
                          define_macros=[("H5_USE_16_API", True)],
                          libraries=["m", "hdf5"],
                          library_dirs=library_dirs, include_dirs=include_dirs)
     config.add_extension("libconfig_wrapper",
-        ["yt/utilities/libconfig_wrapper.pyx"] +
-         glob.glob("yt/utilities/_libconfig/*.c"),
-        include_dirs=["yt/utilities/_libconfig/"],
-        define_macros=[("HAVE_XLOCALE_H", True)]
-        )
+                         ["yt/utilities/libconfig_wrapper.pyx"] +
+                         glob.glob("yt/utilities/_libconfig/*.c"),
+                         include_dirs=["yt/utilities/_libconfig/"],
+                         define_macros=[("HAVE_XLOCALE_H", True)]
+                         )
     config.make_config_py()  # installs __config__.py
-    #config.make_svn_version_py()
+    # config.make_svn_version_py()
     return config

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list