[h5py] 132/455: More setup fixes; revert deprecation of 1.6.X functions

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit e0b7b40d1724060774bf86866df99b0175c024d7
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Sep 30 06:42:55 2008 +0000

    More setup fixes; revert deprecation of 1.6.X functions
---
 h5py/h5g.pyx      | 442 ++++++++++++++++++++++++++----------------------------
 h5py/highlevel.py |  31 +++-
 setup.py          |  46 +++---
 3 files changed, 263 insertions(+), 256 deletions(-)

diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index b505af4..5fcf333 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -182,66 +182,63 @@ cdef herr_t iter_cb_helper(hid_t gid, char *name, object int_tpl) except -1:
 
     return 0
 
-# COMPAT: 1.8 deprecation
-IF H5PY_16API:
-    @sync
-    def iterate(GroupID loc not None, char* name, object func, object data=None, 
-                int startidx=0):
-        """ (GroupID loc, STRING name, FUNCTION func, OBJECT data=None, 
-                UINT startidx=0) => INT last_index_processed
-
-            Iterate an arbitrary Python function over a group.  Note that the
-            group is specified by a parent and a name; if you have a group
-            identifier and want to iterate over it; pass in "." for the name.
-            You can also start at an arbitrary member by specifying its 
-            (zero-based) index.
-
-            Your function:
-            1.  Should accept three arguments: the GroupID of the group, the 
-                (STRING) name of the member, and an arbitary Python object you 
-                provide as data.  Any return value is ignored.
-            2.  Raise StopIteration to bail out before all members are processed.
-            3.  Raising anything else immediately aborts iteration, and the
-                exception is propagated.
-        """
-        cdef int i
-        cdef list err_list
-        err_list = []
+ at sync
+def iterate(GroupID loc not None, char* name, object func, object data=None, 
+            int startidx=0):
+    """ (GroupID loc, STRING name, FUNCTION func, OBJECT data=None, 
+            UINT startidx=0) => INT last_index_processed
+
+        Iterate an arbitrary Python function over a group.  Note that the
+        group is specified by a parent and a name; if you have a group
+        identifier and want to iterate over it; pass in "." for the name.
+        You can also start at an arbitrary member by specifying its 
+        (zero-based) index.
+
+        Your function:
+        1.  Should accept three arguments: the GroupID of the group, the 
+            (STRING) name of the member, and an arbitary Python object you 
+            provide as data.  Any return value is ignored.
+        2.  Raise StopIteration to bail out before all members are processed.
+        3.  Raising anything else immediately aborts iteration, and the
+            exception is propagated.
+    """
+    cdef int i
+    cdef list err_list
+    err_list = []
 
-        if startidx < 0:
-            raise ValueError("Starting index must be non-negative.")
-        i = startidx
+    if startidx < 0:
+        raise ValueError("Starting index must be non-negative.")
+    i = startidx
 
-        int_tpl = (loc, func, data, err_list)
+    int_tpl = (loc, func, data, err_list)
 
-        H5Giterate(loc.id, name, &i, <H5G_iterate_t>iter_cb_helper, int_tpl)
+    H5Giterate(loc.id, name, &i, <H5G_iterate_t>iter_cb_helper, int_tpl)
 
-        if len(err_list) > 0:
-            raise err_list[0]
+    if len(err_list) > 0:
+        raise err_list[0]
 
-# COMPAT: 1.8 deprecation
-IF H5PY_16API:
-    @sync
-    def get_objinfo(ObjectID obj not None, object name='.', int follow_link=1):
-        """ (ObjectID obj, STRING name='.', BOOL follow_link=True) => GroupStat object
 
-            Obtain information about a named object.  If "name" is provided,
-            "obj" is taken to be a GroupID object containing the target.
-            The return value is a GroupStat object; see that class's docstring
-            for a description of its attributes.  
+ at sync
+def get_objinfo(ObjectID obj not None, object name='.', int follow_link=1):
+    """ (ObjectID obj, STRING name='.', BOOL follow_link=True) => GroupStat object
 
-            If follow_link is True (default) and the object is a symbolic link, 
-            the information returned describes its target.  Otherwise the 
-            information describes the link itself.
-        """
-        cdef GroupStat statobj
-        statobj = GroupStat()
-        cdef char* _name
-        _name = name
+        Obtain information about a named object.  If "name" is provided,
+        "obj" is taken to be a GroupID object containing the target.
+        The return value is a GroupStat object; see that class's docstring
+        for a description of its attributes.  
+
+        If follow_link is True (default) and the object is a symbolic link, 
+        the information returned describes its target.  Otherwise the 
+        information describes the link itself.
+    """
+    cdef GroupStat statobj
+    statobj = GroupStat()
+    cdef char* _name
+    _name = name
 
-        H5Gget_objinfo(obj.id, _name, follow_link, &statobj.infostruct)
+    H5Gget_objinfo(obj.id, _name, follow_link, &statobj.infostruct)
 
-        return statobj
+    return statobj
 
 # === Group member management =================================================
 
@@ -280,184 +277,173 @@ cdef class GroupID(ObjectID):
         IF H5PY_18API:
             H5Gclose(self.id)  # extra ref in the LinkProxy
 
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def link(self, char* current_name, char* new_name, 
-                 int link_type=H5G_LINK_HARD, GroupID remote=None):
-            """ (STRING current_name, STRING new_name, INT link_type=LINK_HARD, 
-                 GroupID remote=None)
-
-                Create a new hard or soft link.  current_name identifies
-                the link target (object the link will point to).  The new link is
-                identified by new_name and (optionally) another group "remote".
-
-                Link types are:
-                    LINK_HARD:  Hard link to existing object (default)
-                    LINK_SOFT:  Symbolic link; link target need not exist.
-            """
-            cdef hid_t remote_id
-            if remote is None:
-                remote_id = self.id
-            else:
-                remote_id = remote.id
-
-            H5Glink2(self.id, current_name, <H5G_link_t>link_type, remote_id, new_name)
-
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def unlink(self, char* name):
-            """ (STRING name)
-
-                Remove a link to an object from this group.
-            """
-            H5Gunlink(self.id, name)
+
+    @sync
+    def link(self, char* current_name, char* new_name, 
+             int link_type=H5G_LINK_HARD, GroupID remote=None):
+        """ (STRING current_name, STRING new_name, INT link_type=LINK_HARD, 
+             GroupID remote=None)
+
+            Create a new hard or soft link.  current_name identifies
+            the link target (object the link will point to).  The new link is
+            identified by new_name and (optionally) another group "remote".
+
+            Link types are:
+                LINK_HARD:  Hard link to existing object (default)
+                LINK_SOFT:  Symbolic link; link target need not exist.
+        """
+        cdef hid_t remote_id
+        if remote is None:
+            remote_id = self.id
+        else:
+            remote_id = remote.id
+
+        H5Glink2(self.id, current_name, <H5G_link_t>link_type, remote_id, new_name)
+
+
+    @sync
+    def unlink(self, char* name):
+        """ (STRING name)
+
+            Remove a link to an object from this group.
+        """
+        H5Gunlink(self.id, name)
    
-    # COMPAT: 1.8 deprecation 
-    IF H5PY_16API:
-        @sync
-        def move(self, char* current_name, char* new_name, GroupID remote=None):
-            """ (STRING current_name, STRING new_name, GroupID remote=None)
-
-                Relink an object.  current_name identifies the object.
-                new_name and (optionally) another group "remote" determine
-                where it should be moved.
-            """
-            cdef hid_t remote_id
-            if remote is None:
-                remote_id = self.id
-            else:
-                remote_id = remote.id
-
-            H5Gmove2(self.id, current_name, remote_id, new_name)
-
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def get_num_objs(self):
-            """ () => INT number_of_objects
-
-                Get the number of objects directly attached to a given group.
-            """
-            cdef hsize_t size
-            H5Gget_num_objs(self.id, &size)
-            return size
-
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def get_objname_by_idx(self, hsize_t idx):
-            """ (INT idx) => STRING object_name
-
-                Get the name of a group member given its zero-based index.
-
-                Due to a limitation of the HDF5 library, the generic exception
-                H5Error is raised if the idx parameter is out-of-range.
-            """
-            cdef int size
-            cdef char* buf
-            buf = NULL
-
-            # This function does not properly raise an exception
-            size = H5Gget_objname_by_idx(self.id, idx, NULL, 0)
-            if size < 0:
-                raise H5Error("Invalid index")
-
-            buf = <char*>emalloc(sizeof(char)*(size+1))
-            try:
-                H5Gget_objname_by_idx(self.id, idx, buf, size+1)
-                pystring = buf
-                return pystring
-            finally:
-                efree(buf)
-
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def get_objtype_by_idx(self, hsize_t idx):
-            """ (INT idx) => INT object_type_code
-
-                Get the type of an object attached to a group, given its zero-based
-                index.  Possible return values are:
-                    - LINK
-                    - GROUP
-                    - DATASET
-                    - DATATYPE
-
-                Due to a limitation of the HDF5 library, the generic exception
-                H5Error is raised if the idx parameter is out-of-range.
-            """
-            # This function does not properly raise an exception
-            cdef herr_t retval
-            retval = H5Gget_objtype_by_idx(self.id, idx)
-            if retval < 0:
-                raise H5Error("Invalid index")
-            return retval
-
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def get_linkval(self, char* name):
-            """ (STRING name) => STRING link_value
-
-                Retrieve the value (target name) of a symbolic link.
-                Limited to 2048 characters on Windows.
-            """
-            cdef char* value
-            cdef H5G_stat_t statbuf
-            value = NULL
-
-            H5Gget_objinfo(self.id, name, 0, &statbuf)
-
-            if statbuf.type != H5G_LINK:
-                raise ValueError('"%s" is not a symbolic link.' % name)
-
-            IF UNAME_SYSNAME == "Windows":
-                linklen = 2049  # Windows statbuf.linklen seems broken
-            ELSE:
-                linklen = statbuf.linklen+1
-            value = <char*>emalloc(sizeof(char)*linklen)
-            try:
-                H5Gget_linkval(self.id, name, linklen, value)
-                value[linklen-1] = c'\0'  # in case HDF5 doesn't null terminate on Windows
-                pyvalue = value
-                return pyvalue
-            finally:
-                efree(value)
-
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def set_comment(self, char* name, char* comment):
-            """ (STRING name, STRING comment)
-
-                Set the comment on a group member.
-            """
-            H5Gset_comment(self.id, name, comment)
-
-    # COMPAT: 1.8 deprecation
-    IF H5PY_16API:
-        @sync
-        def get_comment(self, char* name):
-            """ (STRING name) => STRING comment
-
-                Retrieve the comment for a group member.
-            """
-            cdef int cmnt_len
-            cdef char* cmnt
-            cmnt = NULL
-
-            cmnt_len = H5Gget_comment(self.id, name, 0, NULL)
-            assert cmnt_len >= 0
-
-            cmnt = <char*>emalloc(sizeof(char)*(cmnt_len+1))
-            try:
-                H5Gget_comment(self.id, name, cmnt_len+1, cmnt)
-                py_cmnt = cmnt
-                return py_cmnt
-            finally:
-                efree(cmnt)
+
+    @sync
+    def move(self, char* current_name, char* new_name, GroupID remote=None):
+        """ (STRING current_name, STRING new_name, GroupID remote=None)
+
+            Relink an object.  current_name identifies the object.
+            new_name and (optionally) another group "remote" determine
+            where it should be moved.
+        """
+        cdef hid_t remote_id
+        if remote is None:
+            remote_id = self.id
+        else:
+            remote_id = remote.id
+
+        H5Gmove2(self.id, current_name, remote_id, new_name)
+
+
+    @sync
+    def get_num_objs(self):
+        """ () => INT number_of_objects
+
+            Get the number of objects directly attached to a given group.
+        """
+        cdef hsize_t size
+        H5Gget_num_objs(self.id, &size)
+        return size
+
+
+    @sync
+    def get_objname_by_idx(self, hsize_t idx):
+        """ (INT idx) => STRING object_name
+
+            Get the name of a group member given its zero-based index.
+
+            Due to a limitation of the HDF5 library, the generic exception
+            H5Error is raised if the idx parameter is out-of-range.
+        """
+        cdef int size
+        cdef char* buf
+        buf = NULL
+
+        # This function does not properly raise an exception
+        size = H5Gget_objname_by_idx(self.id, idx, NULL, 0)
+        if size < 0:
+            raise H5Error("Invalid index")
+
+        buf = <char*>emalloc(sizeof(char)*(size+1))
+        try:
+            H5Gget_objname_by_idx(self.id, idx, buf, size+1)
+            pystring = buf
+            return pystring
+        finally:
+            efree(buf)
+
+
+    @sync
+    def get_objtype_by_idx(self, hsize_t idx):
+        """ (INT idx) => INT object_type_code
+
+            Get the type of an object attached to a group, given its zero-based
+            index.  Possible return values are:
+                - LINK
+                - GROUP
+                - DATASET
+                - DATATYPE
+
+            Due to a limitation of the HDF5 library, the generic exception
+            H5Error is raised if the idx parameter is out-of-range.
+        """
+        # This function does not properly raise an exception
+        cdef herr_t retval
+        retval = H5Gget_objtype_by_idx(self.id, idx)
+        if retval < 0:
+            raise H5Error("Invalid index")
+        return retval
+
+
+    @sync
+    def get_linkval(self, char* name):
+        """ (STRING name) => STRING link_value
+
+            Retrieve the value (target name) of a symbolic link.
+            Limited to 2048 characters on Windows.
+        """
+        cdef char* value
+        cdef H5G_stat_t statbuf
+        value = NULL
+
+        H5Gget_objinfo(self.id, name, 0, &statbuf)
+
+        if statbuf.type != H5G_LINK:
+            raise ValueError('"%s" is not a symbolic link.' % name)
+
+        IF UNAME_SYSNAME == "Windows":
+            linklen = 2049  # Windows statbuf.linklen seems broken
+        ELSE:
+            linklen = statbuf.linklen+1
+        value = <char*>emalloc(sizeof(char)*linklen)
+        try:
+            H5Gget_linkval(self.id, name, linklen, value)
+            value[linklen-1] = c'\0'  # in case HDF5 doesn't null terminate on Windows
+            pyvalue = value
+            return pyvalue
+        finally:
+            efree(value)
+
+    @sync
+    def set_comment(self, char* name, char* comment):
+        """ (STRING name, STRING comment)
+
+            Set the comment on a group member.
+        """
+        H5Gset_comment(self.id, name, comment)
+
+    @sync
+    def get_comment(self, char* name):
+        """ (STRING name) => STRING comment
+
+            Retrieve the comment for a group member.
+        """
+        cdef int cmnt_len
+        cdef char* cmnt
+        cmnt = NULL
+
+        cmnt_len = H5Gget_comment(self.id, name, 0, NULL)
+        assert cmnt_len >= 0
+
+        cmnt = <char*>emalloc(sizeof(char)*(cmnt_len+1))
+        try:
+            H5Gget_comment(self.id, name, cmnt_len+1, cmnt)
+            py_cmnt = cmnt
+            return py_cmnt
+        finally:
+            efree(cmnt)
 
     # === Special methods =====================================================
 
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index f3cf176..907e8e9 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -281,11 +281,15 @@ class Group(HLObject):
 
     def visit(self, func):
         """ Recursively iterate a function or callable object over the file,
-            calling it exactly once with each object name.  Return None to
-            continue iteration, or anything else to immediately return that
-            value.
+            calling it exactly once for each object with the signature:
+
+                func(<name>) => <None or return value>
+
+            Returning None continues iteration, returning anything else stops
+            and immediately returns that value from Group.visit.
 
             Example:
+
             # List the entire contents of the file
             >>> list_of_names = []
             >>> grp.visit(list_of_names.append)
@@ -301,6 +305,27 @@ class Group(HLObject):
 
             return h5o.visit(self.id, call_proxy)
 
+    def visititems(self, func):
+        """ Recursively iterate a function or callable object over the file,
+            calling it exactly once for each object, with the signature::
+    
+                func(<name>, <object instance>) => <None or return value>
+
+            Returning None continues iteration, returning anything else stops
+            and immediately returns that value from Group.visit.
+
+            Only available with HDF5 1.8.X.
+        """
+        if not config.API_18:
+            raise NotImplementedError("This feature is only available with HDF5 1.8.0 and later")
+
+        with self._lock:
+            def call_proxy(name, info):
+                return func(name, self[name])
+
+            return h5o.visit(self.id, call_proxy)
+
+
     def __str__(self):
         with self._lock:
             try:
diff --git a/setup.py b/setup.py
index 0ea984e..9c31407 100644
--- a/setup.py
+++ b/setup.py
@@ -50,7 +50,6 @@ NAME = 'h5py'
 VERSION = '0.4.0'
 MIN_NUMPY = '1.0.3'
 MIN_CYTHON = '0.9.8.1.1'
-KNOWN_API = (16,18)    # Legal API levels (1.8.X or 1.6.X)
 SRC_PATH = 'h5py'      # Name of directory with .pyx files
 CMD_CLASS = {}         # Custom command classes for setup()
 
@@ -67,6 +66,7 @@ def fatal(instring, code=1):
 def warn(instring):
     print >> sys.stderr, "Warning: "+instring
 
+
 # === Required imports ========================================================
 
 # Check Python version (2.5 or greater required)
@@ -124,7 +124,7 @@ class ExtensionCreator(object):
             provided.
         """
         sources = [op.join(SRC_PATH, name+'.c')]+[op.join(SRC_PATH,x) for x in extra_src]
-        ext = Extension(NAME+'.'+name,
+        return Extension(NAME+'.'+name,
                             sources, 
                             include_dirs = self.include_dirs, 
                             libraries = self.libraries,
@@ -132,7 +132,6 @@ class ExtensionCreator(object):
                             runtime_library_dirs = self.runtime_dirs,
                             extra_compile_args = self.extra_compile_args,
                             extra_link_args = self.extra_link_args)
-        return ext
 
 
 # === Custom extensions for distutils =========================================
@@ -144,7 +143,7 @@ class cybuild(build):
 
     user_options = build.user_options + \
                     [('hdf5=', '5', 'Custom location for HDF5'),
-                     ('api=', 'a', 'Set API levels (--api=16,18)'),
+                     ('api=', 'a', 'Set API levels (--api=16 or --api=18)'),
                      ('cython','y','Run Cython'),
                      ('cython-only','Y', 'Run Cython and stop'),
                      ('diag', 'd','Enable library debug logging'),
@@ -166,9 +165,9 @@ class cybuild(build):
         l = output.find("HDF5 Version")
         if l > 0:
             if output[l:l+30].find('1.8') > 0:
-                return (16,18)
+                return 18
             elif output[l:l+30].find('1.6') > 0:
-                return (16,)
+                return 16
         return None
 
     def initialize_options(self):
@@ -190,6 +189,10 @@ class cybuild(build):
 
         build.finalize_options(self)
 
+        if self.cython_only or self.diag or self.threads or self.api or self.hdf5:
+            self._default = False
+            self.cython = True
+
         if self.hdf5 is not None:
             self._default = False
             self.hdf5 = op.abspath(self.hdf5)
@@ -201,21 +204,17 @@ class cybuild(build):
             self.api = self.get_hdf5_version()
             if self.api is None:
                 warn("Can't determine HDF5 version, assuming 1.6 (use --api= to override)")
-                self.api = (16,)
+                self.api = 16
         else:
             # User specified the API levels
             self._default = False
             try:
-                self.api = tuple(int(x) for x in self.api.split(',') if len(x) > 0)
-                if len(self.api) == 0 or not all(x in KNOWN_API for x in self.api):
+                self.api = int(self.api)
+                if self.api not in (16,18):
                     raise Exception
             except Exception:
                 fatal('Illegal option %s to --api= (legal values are %s)' % (self.api, ','.join(str(x) for x in KNOWN_API)))
 
-        if self.cython_only or self.diag or self.threads:
-            self._default = False
-            self.cython = True
-
     def run(self):
 
         if self._default and op.exists('buildconf.pickle'):
@@ -226,7 +225,7 @@ class cybuild(build):
         else:
             print "=> Creating new build configuration"
 
-            modules = MODULES[max(self.api)]
+            modules = MODULES[self.api]
             creator = ExtensionCreator(self.hdf5)
             extensions = [creator.create_extension(x) for x in modules]            
             with open('buildconf.pickle','w') as f:
@@ -253,20 +252,20 @@ class cybuild(build):
 DEF H5PY_VERSION = "%(VERSION)s"
 
 DEF H5PY_API = %(API_MAX)d     # Highest API level (i.e. 18 or 16)
-DEF H5PY_16API = %(API_16)d    # 1.6.X API available
+DEF H5PY_16API = %(API_16)d    # 1.6.X API available (always true, for now)
 DEF H5PY_18API = %(API_18)d    # 1.8.X API available
 
 DEF H5PY_DEBUG = %(DEBUG)d    # Logging-level number, or 0 to disable
 
 DEF H5PY_THREADS = %(THREADS)d  # Enable thread-safety and non-blocking reads
 """
-        return pxi_str % {"VERSION": VERSION, "API_MAX": max(self.api),
-                    "API_16": 16 in self.api, "API_18": 18 in self.api,
+        return pxi_str % {"VERSION": VERSION, "API_MAX": self.api,
+                    "API_16": True, "API_18": self.api == 18,
                     "DEBUG": 10 if self.diag else 0, "THREADS": self.threads,
                     "HDF5": "Default" if self.hdf5 is None else self.hdf5}
 
     def compile_cython(self, modules):
-        """ If needed, regenerate the C source files for the build process
+        """ Regenerate the C source files for the build process.
         """
 
         try:
@@ -278,7 +277,7 @@ DEF H5PY_THREADS = %(THREADS)d  # Enable thread-safety and non-blocking reads
             fatal("Old Cython version detected; at least %s required" % MIN_CYTHON)
 
         print "Running Cython (%s)..." % Version.version
-        print "  API levels: %s" % ','.join(str(x) for x in self.api)
+        print "  API level: %d" % self.api
         print "  Thread-aware: %s" % ('yes' if self.threads else 'no')
         print "  Diagnostic mode: %s" % ('yes' if self.diag else 'no')
         print "  HDF5: %s" % ('default' if self.hdf5 is None else self.hdf5)
@@ -335,11 +334,9 @@ DEF H5PY_THREADS = %(THREADS)d  # Enable thread-safety and non-blocking reads
 
 class test(cybuild):
 
-    """ Run unit tests.  As a special case, won't run Cython unless --cython
-        or --cython-only are specified.
-    """
+    """ Run unit tests """
 
-    description = "Build and run unit tests"
+    description = "Run unit tests in-place"
     user_options = cybuild.user_options + \
                    [('sections=','s','Comma separated list of tests ("-" prefix to NOT run)')]
 
@@ -393,8 +390,7 @@ class doc(cybuild):
 
 class cyclean(clean):
 
-    """ Standard distutils clean extended to clean up Cython-generated files.
-    """
+    """ Distutils clean extended to clean up Cython-generated files """
 
     user_options = clean.user_options + \
                    [('doc','d','Also destroy compiled documentation')]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list