Skip to content

Commit

Permalink
added objid functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jreadey committed Feb 4, 2025
1 parent 8474272 commit be22083
Show file tree
Hide file tree
Showing 5 changed files with 707 additions and 13 deletions.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ authors = [{ "name" = "The HDF Group", "email" = "help@hdfgroup.org" }]
keywords = ["json", "hdf5", "multidimensional array", "data", "datacube"]
requires-python = ">=3.8"
dependencies = [
"h5py >=3.10",
"h5py >= 3.10",
"numpy >= 2.0; python_version>='3.9'",
"jsonschema >=4.4.0",
"tomli; python_version<'3.11'",
"numpy >=1.20,<2.0.0; python_version=='3.8'",
]

dynamic = ["version"]

[project.urls]
Homepage = "https://hdf5-json.readthedocs.io"
Documentation = "https://hdf5-json.readthedocs.io"
Homepage = "https://support.hdfgroup.org/documentation/hdf5-json/latest/"
Documentation = "https://support.hdfgroup.org/documentation/hdf5-json/latest/"
Source = "https://github.com/HDFGroup/hdf5-json"
"Bug Reports" = "https://github.com/HDFGroup/hdf5-json/issues"
Social = "https://twitter.com/hdf5"
Expand Down
8 changes: 8 additions & 0 deletions src/h5json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
from .hdf5dtype import getTypeResponse
from .hdf5dtype import getItemSize
from .hdf5dtype import createDataType
from .objid import createObjId
from .objid import getCollectionForId
from .objid import isObjId
from .objid import isS3ObjKey
from .objid import getS3Key
from .objid import getObjId
from .objid import isSchema2Id
from .objid import isRootObjId
from .hdf5db import Hdf5db
from . import _version

Expand Down
21 changes: 11 additions & 10 deletions src/h5json/hdf5db.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import json
import logging
from .hdf5dtype import getTypeItem, createDataType, getItemSize
from .objid import createObjId
from .apiversion import _apiver


Expand Down Expand Up @@ -561,7 +562,7 @@ def initFile(self):

self.log.info("initializing file")
if not self.root_uuid:
self.root_uuid = str(uuid.uuid1())
self.root_uuid = createObjId()
self.dbGrp.attrs["rootUUID"] = self.root_uuid
self.dbGrp.create_group("{groups}")
self.dbGrp.create_group("{datasets}")
Expand Down Expand Up @@ -593,21 +594,21 @@ def visit(self, path, obj):
msg = "Unknown object type: " + __name__ + " found during scan of HDF5 file"
self.log.error(msg)
raise IOError(errno.EIO, msg)
uuid1 = uuid.uuid1() # create uuid
id = str(uuid1)
obj_id = createObjId() # create uuid

addrGrp = self.dbGrp["{addr}"]
if not self.readonly:
# storing db in the file itself, so we can link to the object directly
col[id] = obj.ref # save attribute ref to object
col[obj_id] = obj.ref # save attribute ref to object
else:
# store path to object
col[id] = obj.name
col[obj_id] = obj.name
addr = h5py.h5o.get_info(obj.id).addr
# store reverse map as an attribute
addrGrp.attrs[str(addr)] = id
addrGrp.attrs[str(addr)] = obj_id

#
# Get Datset creation properties
# Get Dataset creation properties
#
def getDatasetCreationProps(self, dset_uuid):
prop_list = {}
Expand Down Expand Up @@ -1087,7 +1088,7 @@ def createCommittedType(self, datatype, obj_uuid=None):
raise IOError(errno.EPERM, msg)
datatypes = self.dbGrp["{datatypes}"]
if not obj_uuid:
obj_uuid = str(uuid.uuid1())
obj_uuid = createObjId()
dt = self.createTypeFromItem(datatype)

datatypes[obj_uuid] = dt
Expand Down Expand Up @@ -2715,7 +2716,7 @@ def createDataset(
raise IOError(errno.EPERM, msg)
datasets = self.dbGrp["{datasets}"]
if not obj_uuid:
obj_uuid = str(uuid.uuid1())
obj_uuid = createObjId()
dt = None
item = {}
fillvalue = None
Expand Down Expand Up @@ -3490,7 +3491,7 @@ def createGroup(self, obj_uuid=None):
raise IOError(errno.EPERM, msg)
groups = self.dbGrp["{groups}"]
if not obj_uuid:
obj_uuid = str(uuid.uuid1())
obj_uuid = createObjId()
newGroup = groups.create_group(obj_uuid)
# store reverse map as an attribute
addr = h5py.h5o.get_info(newGroup.id).addr
Expand Down
Loading

0 comments on commit be22083

Please sign in to comment.