Skip to content

Commit 2d810e3

Browse files
authored
fix: s3 access #453 (#459)
## Description Fix for issue #453 ## What problem does this change solve? <!-- Describe if it's a bugfix, new feature, doc update, or breaking change --> ## What issue or task does this change relate to? <!-- link to Issue Number --> ## Additional notes ## <!-- Include any additional information, caveats, or considerations that the reviewer should be aware of. --> ***As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/*** By opening this pull request, I affirm that all authors agree to the [Contributor License Agreement.](https://github.com/ecmwf/codex/blob/main/Legal/contributor_license_agreement.md)
1 parent 16b5c83 commit 2d810e3

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dynamic = [
4949
]
5050
dependencies = [
5151
"anemoi-transform>=0.1.10",
52-
"anemoi-utils[provenance]>=0.4.32",
52+
"anemoi-utils[provenance]>=0.4.38",
5353
"cfunits",
5454
"glom",
5555
"jsonschema",

src/anemoi/datasets/data/stores.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,20 @@ class S3Store(ReadOnlyStore):
8585
options using the anemoi configs.
8686
"""
8787

88-
def __init__(self, url: str, region: str | None = None) -> None:
89-
"""Initialize the S3Store with a URL and optional region."""
90-
from anemoi.utils.remote.s3 import s3_client
88+
def __init__(self, url: str) -> None:
89+
"""Initialize the S3Store with a URL."""
9190

92-
_, _, self.bucket, self.key = url.split("/", 3)
93-
self.s3 = s3_client(self.bucket, region=region)
91+
self.url = url
9492

9593
def __getitem__(self, key: str) -> bytes:
9694
"""Retrieve an item from the store."""
95+
from anemoi.utils.remote.s3 import get_object
96+
9797
try:
98-
response = self.s3.get_object(Bucket=self.bucket, Key=self.key + "/" + key)
99-
except self.s3.exceptions.NoSuchKey:
98+
return get_object(os.path.join(self.url, key))
99+
except FileNotFoundError:
100100
raise KeyError(key)
101101

102-
return response["Body"].read()
103-
104102

105103
class DebugStore(ReadOnlyStore):
106104
"""A store to debug the zarr loading."""

0 commit comments

Comments
 (0)