Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose AWS Region to HDF5IO #1040

Merged
merged 26 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# HDMF Changelog

## HDMF 3.12.3 (Upcoming)

### Bug fixes
- Exposed `aws_region` to `HDF5IO` and downstream passes to `h5py.File`. @codycbakerphd [#1040](https://github.com/hdmf-dev/hdmf/pull/1040)

## HDMF 3.12.2 (February 9, 2024)

### Bug fixes
Expand Down
22 changes: 18 additions & 4 deletions src/hdmf/backends/hdf5/h5tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ def can_read(path):
{'name': 'file', 'type': [File, "S3File", "RemFile"],
'doc': 'a pre-existing h5py.File, S3File, or RemFile object', 'default': None},
{'name': 'driver', 'type': str, 'doc': 'driver for h5py to use when opening HDF5 file', 'default': None},
{
'name': 'aws_region',
'type': str,
'doc': 'If driver is ros3, then specify the aws region of the url.',
'default': None
},
{'name': 'herd_path', 'type': str,
'doc': 'The path to read/write the HERD file', 'default': None},)
def __init__(self, **kwargs):
"""Open an HDF5 file for IO.
"""
self.logger = logging.getLogger('%s.%s' % (self.__class__.__module__, self.__class__.__qualname__))
path, manager, mode, comm, file_obj, driver, herd_path = popargs('path', 'manager', 'mode',
path, manager, mode, comm, file_obj, driver, aws_region, herd_path = popargs('path', 'manager', 'mode',
'comm', 'file', 'driver',
'herd_path',
'aws_region', 'herd_path',
kwargs)

self.__open_links = [] # keep track of other files opened from links in this file
Expand All @@ -92,6 +98,7 @@ def __init__(self, **kwargs):
elif isinstance(manager, TypeMap):
manager = BuildManager(manager)
self.__driver = driver
self.__aws_region = aws_region
self.__comm = comm
self.__mode = mode
self.__file = file_obj
Expand All @@ -117,6 +124,10 @@ def _file(self):
def driver(self):
return self.__driver

@property
def aws_region(self):
return self.__aws_region

@classmethod
def __check_path_file_obj(cls, path, file_obj):
if isinstance(path, Path):
Expand All @@ -134,13 +145,13 @@ def __check_path_file_obj(cls, path, file_obj):
return path

@classmethod
def __resolve_file_obj(cls, path, file_obj, driver):
def __resolve_file_obj(cls, path, file_obj, driver, aws_region=None):
rly marked this conversation as resolved.
Show resolved Hide resolved
path = cls.__check_path_file_obj(path, file_obj)

if file_obj is None:
file_kwargs = dict()
if driver is not None:
file_kwargs.update(driver=driver)
file_kwargs.update(driver=driver, aws_region=bytes(aws_region, "ascii"))
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
file_obj = File(path, 'r', **file_kwargs)
return file_obj

Expand Down Expand Up @@ -757,6 +768,9 @@ def open(self):
if self.driver is not None:
kwargs.update(driver=self.driver)

if self.driver == "ros3" and self.aws_region is not None:
kwargs.update(aws_region=bytes(self.aws_region, "ascii"))
rly marked this conversation as resolved.
Show resolved Hide resolved

self.__file = File(self.source, open_flag, **kwargs)

def close(self, close_links=True):
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_io_hdf5_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def test_basic_read(self):
with get_hdf5io(s3_path, "r", manager=self.manager, driver="ros3") as io:
io.read()

def test_basic_read_with_aws_region(self):
s3_path = "https://dandiarchive.s3.amazonaws.com/blobs/11e/c89/11ec8933-1456-4942-922b-94e5878bb991"

with get_hdf5io(s3_path, "r", manager=self.manager, driver="ros3", aws_region="us-east-2") as io:
io.read()

# Util functions and classes to enable loading of the NWB namespace -- see pynwb/src/pynwb/spec.py


Expand Down
Loading