Skip to content

Commit

Permalink
Fix export cache spec and fix read cached spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rly committed Nov 10, 2024
1 parent 049402f commit 1443799
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,13 @@ def export(self, **kwargs):
ckwargs['clear_cache'] = True
super().export(**ckwargs)
if cache_spec:
# add any namespaces from the src_io that have not yet been loaded
for namespace in src_io.manager.namespace_catalog.namespaces:
if namespace not in self.manager.namespace_catalog.namespaces:
self.manager.namespace_catalog.add_namespace(
name=namespace,
namespace=src_io.manager.namespace_catalog.get_namespace(namespace)
)
self.__cache_spec()

def get_written(self, builder, check_on_disk=False):
Expand Down
16 changes: 9 additions & 7 deletions src/hdmf_zarr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math
import json
import logging
import os
from collections import deque
from collections.abc import Iterable
from typing import Optional, Union, Literal, Tuple, Dict, Any
Expand Down Expand Up @@ -373,12 +374,12 @@ class ZarrSpecReader(SpecReader):
Class to read format specs from Zarr
"""

@docval({'name': 'group', 'type': Group, 'doc': 'the Zarr file to read specs from'},
{'name': 'source', 'type': str, 'doc': 'the path spec files are relative to', 'default': '.'})
@docval({'name': 'group', 'type': Group, 'doc': 'the Zarr file to read specs from'})
def __init__(self, **kwargs):
self.__group, source = getargs('group', 'source', kwargs)
super_kwargs = {'source': source}
super(ZarrSpecReader, self).__init__(**super_kwargs)
self.__group = getargs('group', kwargs)
source = "%s:%s" % (os.path.abspath(self.__group.store.path), self.__group.name)
super().__init__(source=source)
self.__cache = None

def __read(self, path):
s = self.__group[path][0]
Expand All @@ -391,8 +392,9 @@ def read_spec(self, spec_path):

def read_namespace(self, ns_path):
"""Read a namespace from the given path"""
ret = self.__read(ns_path)
ret = ret['namespaces']
if self.__cache is None:
self.__cache = self.__read(ns_path)
ret = self.__cache['namespaces']
return ret


Expand Down

0 comments on commit 1443799

Please sign in to comment.