From 7885dd1fae2cee7b33d05bb90a9bd96972d68a0e Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Fri, 10 Nov 2023 11:20:43 +0100 Subject: [PATCH] Fix linking for FSSpec --- src/hdmf_zarr/backend.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/hdmf_zarr/backend.py b/src/hdmf_zarr/backend.py index 34f963e1..737aca22 100644 --- a/src/hdmf_zarr/backend.py +++ b/src/hdmf_zarr/backend.py @@ -133,7 +133,7 @@ def file(self): @property def path(self): - """The path to the Zarr file as set by the use""" + """The path to the Zarr file as set by the user""" return self.__path @property @@ -161,6 +161,14 @@ def close(self): self.__file = None return + def is_remote(self): + """Return True if the file is remote, False otherwise""" + from zarr.storage import FSStore + if isinstance(self.file.store, FSStore): + return True + else: + return False + @classmethod @docval({'name': 'namespace_catalog', 'type': (NamespaceCatalog, TypeMap), @@ -624,18 +632,20 @@ def resolve_ref(self, zarr_ref): else: source_file = str(zarr_ref['source']) # Resolve the path relative to the current file - source_file = os.path.abspath(os.path.join(self.source, source_file)) + if not self.is_remote(): + source_file = os.path.abspath(os.path.join(self.source, source_file)) + else: + # get rid of extra "/" and "./" in the path root and source_file + root_path = str(self.path)[:-1] if str(self.path).endswith("/") else str(self.path) + source_path = str(source_file)[1:] if str(source_file).startswith(".") else str(source_file) + source_file = root_path + source_path + object_path = zarr_ref.get('path', None) - # full_path = None - # if os.path.isdir(source_file): - # if object_path is not None: - # full_path = os.path.join(source_file, object_path.lstrip('/')) - # else: - # full_path = source_file if object_path: target_name = os.path.basename(object_path) else: target_name = ROOT_NAME + target_zarr_obj = zarr.open(source_file, mode='r') if object_path is not None: try: