Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to control the link access/creation property lists in groups #2258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions h5py/_hl/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def __init__(self, name, mode='r', driver=None, libver=None, userblock_size=None
rdcc_nslots=None, rdcc_nbytes=None, rdcc_w0=None, track_order=None,
fs_strategy=None, fs_persist=False, fs_threshold=1, fs_page_size=None,
page_buf_size=None, min_meta_keep=0, min_raw_keep=0, locking=None,
alignment_threshold=1, alignment_interval=1, meta_block_size=None, **kwds):
alignment_threshold=1, alignment_interval=1, meta_block_size=None, lapl=None, lcpl=None, **kwds):
"""Create a new file object.

See the h5py user guide for a detailed explanation of the options.
Expand Down Expand Up @@ -493,6 +493,12 @@ def __init__(self, name, mode='r', driver=None, libver=None, userblock_size=None
Set the current minimum size, in bytes, of new metadata block allocations.
See https://portal.hdfgroup.org/display/HDF5/H5P_SET_META_BLOCK_SIZE

lapl
Set the link access property list

lcpl
Set the link creation property list

Additional keywords
Passed on to the selected file driver.
"""
Expand Down Expand Up @@ -571,7 +577,7 @@ def __init__(self, name, mode='r', driver=None, libver=None, userblock_size=None
else:
self._libver = (libver, 'latest')

super().__init__(fid)
super().__init__(fid, lapl, lcpl)

def close(self):
""" Close the file. All open objects become invalid """
Expand Down
26 changes: 22 additions & 4 deletions h5py/_hl/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,38 @@ class Group(HLObject, MutableMappingHDF5):
""" Represents an HDF5 group.
"""

def __init__(self, bind):
def __init__(self, bind, lapl=None, lcpl=None):
""" Create a new Group object by binding to a low-level GroupID.
"""
with phil:
if not isinstance(bind, h5g.GroupID):
raise ValueError("%s is not a GroupID" % bind)
super().__init__(bind)
self._lapl_ = lapl
self._lcpl_ = lcpl

_gcpl_crt_order = h5p.create(h5p.GROUP_CREATE)
_gcpl_crt_order.set_link_creation_order(
h5p.CRT_ORDER_TRACKED | h5p.CRT_ORDER_INDEXED)
_gcpl_crt_order.set_attr_creation_order(
h5p.CRT_ORDER_TRACKED | h5p.CRT_ORDER_INDEXED)

@property
def _lapl(self):
""" Fetch the link access property list appropriate for this object
"""
if self._lapl_ is not None:
return self._lapl_
return super()._lapl

@property
def _lcpl(self):
""" Fetch the link creation property list appropriate for this object
"""
if self._lcpl_ is not None:
return self._lcpl_
return super()._lcpl

def create_group(self, name, track_order=None):
""" Create and return a new subgroup.

Expand All @@ -62,7 +80,7 @@ def create_group(self, name, track_order=None):
name, lcpl = self._e(name, lcpl=True)
gcpl = Group._gcpl_crt_order if track_order else None
gid = h5g.create(self.id, name, lcpl=lcpl, gcpl=gcpl)
return Group(gid)
return Group(gid, self._lapl_, self._lcpl_)

def create_dataset(self, name, shape=None, dtype=None, data=None, **kwds):
""" Create a new HDF5 dataset
Expand Down Expand Up @@ -361,7 +379,7 @@ def __getitem__(self, name):

otype = h5i.get_type(oid)
if otype == h5i.GROUP:
return Group(oid)
return Group(oid, self._lapl_, self._lcpl_)
elif otype == h5i.DATASET:
return dataset.Dataset(oid, readonly=(self.file.mode == 'r'))
elif otype == h5i.DATATYPE:
Expand Down Expand Up @@ -595,7 +613,7 @@ def copy(self, source, dest, name=None,
copypl = None

h5o.copy(source.id, self._e(source_path), dest.id, self._e(dest_path),
copypl, base.dlcpl)
copypl, self._lcpl)

def move(self, source, dest):
""" Move a link to a new location in the file.
Expand Down