-
Notifications
You must be signed in to change notification settings - Fork 13
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
Better S3 Support for MagViews #1278
Draft
Tobias314
wants to merge
7
commits into
master
Choose a base branch
from
better_s3_mag_views
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1925417
WIP
Tobias314 fea5fd7
Merge branch 'master' of github.com:scalableminds/webknossos-libs
Tobias314 54e9111
Simplify layer path definition
Tobias314 cb170b1
Remove print
Tobias314 545ae51
Merge branch 'master' into better_s3_mag_views
Tobias314 dacbbda
Merge branch 'master' of github.com:scalableminds/webknossos-libs int…
Tobias314 be3f219
Reset dataset.py
Tobias314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import os | ||
import re | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Iterable, Iterator | ||
|
@@ -431,8 +432,14 @@ def _make_kvstore(path: Path) -> str | dict[str, str | list[str]]: | |
"path": parsed_url.path.lstrip("/"), | ||
"bucket": parsed_url.netloc, | ||
} | ||
if endpoint_url := path.storage_options.get("client_kwargs", {}).get( | ||
"endpoint_url", None | ||
if ( | ||
( | ||
endpoint_url := path.storage_options.get("client_kwargs", {}).get( | ||
"endpoint_url", None | ||
) | ||
) | ||
or (endpoint_url := path.storage_options.get("endpoint_url", None)) | ||
or (endpoint_url := os.environ.get("S3_ENDPOINT_URL", None)) | ||
): | ||
kvstore_spec["endpoint"] = endpoint_url | ||
if "key" in path.storage_options and "secret" in path.storage_options: | ||
|
@@ -780,6 +787,7 @@ def create(cls, path: Path, array_info: ArrayInfo) -> "Zarr3Array": | |
], | ||
}, | ||
"create": True, | ||
"open": True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm? |
||
} | ||
).result() | ||
return cls(path, _array) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,40 +226,13 @@ def __init__(self, dataset: "Dataset", properties: LayerProperties) -> None: | |
|
||
@property | ||
def path(self) -> Path: | ||
"""Gets the filesystem path to this layer's data. | ||
|
||
The path is determined from the first mag's path parent directory if mags have paths, | ||
otherwise uses the dataset path combined with layer name. Remote paths are handled | ||
specially. | ||
"""Gets the filesystem path to this layer's data. This is defined as a subdirectory of the dataset directory named like the layer. | ||
Therefore, this directory does not contain the actual data of any linked or remote layers or mags. | ||
|
||
Returns: | ||
Path: Filesystem path to this layer's data directory | ||
|
||
Raises: | ||
AssertionError: If mags in layer point to different layers | ||
""" | ||
|
||
# Assume that all mags belong to the same layer. If they have a path use them as this layers path. | ||
# This is necessary for remote layer / mag support. | ||
maybe_mag_path_str = ( | ||
self._properties.mags[0].path if len(self._properties.mags) > 0 else None | ||
) | ||
maybe_layer_path = ( | ||
strip_trailing_slash(UPath(maybe_mag_path_str)).parent | ||
if maybe_mag_path_str | ||
else None | ||
) | ||
for mag in self._properties.mags: | ||
is_same_layer = ( | ||
mag.path is None and maybe_layer_path is None | ||
) or strip_trailing_slash(UPath(mag.path)).parent == maybe_layer_path | ||
assert is_same_layer, "All mags of a layer must point to the same layer." | ||
is_remote = maybe_layer_path and is_remote_path(maybe_layer_path) | ||
return ( | ||
maybe_layer_path | ||
if maybe_layer_path and is_remote | ||
else self.dataset.path / self.name | ||
) | ||
return self.dataset.path / self.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you checked the usages of |
||
|
||
@property | ||
def resolved_path(self) -> Path: | ||
|
@@ -691,7 +664,15 @@ def add_existing_remote_mag_view( | |
f"Cannot add mag {mag} as it already exists for layer {self}" | ||
) | ||
self._setup_mag(mag, mag_path) | ||
self._properties.mags.append(mag_view._properties) | ||
# since the remote mag view might belong to another dataset, it's property's path might be None, therefore, we get the path from the mag_view itself instead of it's properties | ||
self._properties.mags.append( | ||
MagViewProperties( | ||
mag=mag_view.mag, | ||
path=str(mag_view.path), | ||
normanrz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cube_length=mag_view._properties.cube_length, | ||
axis_order=mag_view._properties.axis_order, | ||
) | ||
) | ||
self.dataset._export_as_json() | ||
|
||
return mag_view | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check whether this is required, would be better to always infer endpoint_url from UPath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rely on the UPath