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

properly handle region_name in MPath for S3 paths #667

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions mapchete/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ def fs(self) -> fsspec.AbstractFileSystem:
if self._fs is not None:
return self._fs
elif self._path_str.startswith("s3://"):
# move 'region_name' up to client_kwargs in order to have effect
if self._storage_options.get("region_name"):
client_kwargs = self._storage_options.get("client_kwargs", {})
client_kwargs.update(
region_name=self._storage_options.pop("region_name")
)
self._storage_options.update(client_kwargs=client_kwargs)
return fsspec.filesystem(
"s3",
requester_pays=self._storage_options.get(
Expand Down
8 changes: 8 additions & 0 deletions test/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,11 @@ def test_with_protocol_http():
def test_with_protocol_relative():
path = MPath("foo/bar")
assert path.with_protocol("https") == "https://foo/bar"


def test_s3_region_name():
path = MPath("s3://foo", storage_options=dict(region_name="bar"))
# trigger a rewrite of storage options to fit with S3FS
path.fs
# not an ideal way to test this, but the storage_options are passed on to S3FS that way
assert path._storage_options.get("client_kwargs", {}).get("region_name") == "bar"
Loading