Skip to content

Commit

Permalink
Fix linking for FSSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 committed Nov 10, 2023
1 parent efe83d1 commit 7885dd1
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7885dd1

Please sign in to comment.