From bdf89505a7f33a5b47233e366d34db3748c19c98 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sun, 10 Nov 2024 15:05:47 -0500 Subject: [PATCH 1/2] Fix export cache spec and fix read cached spec (#232) * Fix export cache spec and fix read cached spec * Update changelog --- CHANGELOG.md | 4 ++++ src/hdmf_zarr/backend.py | 7 +++++++ src/hdmf_zarr/utils.py | 16 +++++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc12b091..bf89d97f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,15 @@ # HDMF-ZARR Changelog ## 1.0.0 (Upcoming) + ### Enhancements * Added support for Pathlib paths. @mavaylon1 [#212](https://github.com/hdmf-dev/hdmf-zarr/pull/212) * Updated packages used for testing and readthedocs configuration. @mavaylon1, @rly [#214](https://github.com/hdmf-dev/hdmf-zarr/pull/214) * Add `force_overwite` parameter for `ZarrIO.__init__` to allow overwriting an existing file or directory. @oruebel [#229](https://github.com/hdmf-dev/hdmf-zarr/pull/229) +### Bug Fixes +* Fix reading of cached specs and caching of specs during export. @rly [#232](https://github.com/hdmf-dev/hdmf-zarr/pull/232) + ## 0.9.0 (September 16, 2024) ### Enhancements * Added support for appending a dataset of references. @mavaylon1 [#203](https://github.com/hdmf-dev/hdmf-zarr/pull/203) diff --git a/src/hdmf_zarr/backend.py b/src/hdmf_zarr/backend.py index f320683c..726bf39e 100644 --- a/src/hdmf_zarr/backend.py +++ b/src/hdmf_zarr/backend.py @@ -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): diff --git a/src/hdmf_zarr/utils.py b/src/hdmf_zarr/utils.py index 19bf75b9..1c012a22 100644 --- a/src/hdmf_zarr/utils.py +++ b/src/hdmf_zarr/utils.py @@ -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 @@ -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] @@ -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 From b69c3e0b0526c5a01d2ec217c5cfdf68da724b4b Mon Sep 17 00:00:00 2001 From: Paul Adkisson Date: Tue, 12 Nov 2024 08:25:21 +1100 Subject: [PATCH 2/2] Updated dev install instructions (#233) --- docs/source/installation.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 2727acfe..fc55f947 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -32,7 +32,6 @@ in a Conda environment. Normally we don't need to install ``hdmf`` directly, but conda create --name hdmf-zarr-test python=3.9 conda activate hdmf-zarr-test - conda install h5py git clone --recurse-submodules https://github.com/hdmf-dev/hdmf.git cd hdmf