Skip to content

Commit 0ad8804

Browse files
markbaderfm3
andauthored
Fix cli download (#1083)
* Start implementing logic for distinguish annotation and dataset download. * Update download cli function. * Update changelog * Update webknossos/Changelog.md Co-authored-by: Florian M <[email protected]> * Raising errors when download fails instead of printing a message. --------- Co-authored-by: Florian M <[email protected]>
1 parent cc09811 commit 0ad8804

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
2121
- Moved functional parts of merge volume annotation CLI to Dataset and Annotation classes. [1055](https://github.com/scalableminds/webknossos-libs/pull/1055)
2222

2323
### Fixed
24+
- Fixed an issue with downloading annotations through the Command Line Interface. [#1083](https://github.com/scalableminds/webknossos-libs/pull/1083)
2425

2526

2627
## [0.14.22](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.14.22) - 2024-05-13

webknossos/webknossos/cli/download.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""This module takes care of downloading WEBKNOSSOS datasets."""
22

3+
import re
34
from typing import Any, List, Optional
45

56
import typer
67
from typing_extensions import Annotated
78

8-
from ..annotation import Annotation
9+
from ..annotation.annotation import _ANNOTATION_URL_REGEX, Annotation
910
from ..client import webknossos_context
10-
from ..dataset import Dataset
11+
from ..client._resolve_short_link import resolve_short_link
12+
from ..dataset.dataset import _DATASET_URL_REGEX, Dataset
1113
from ..geometry import BoundingBox, Mag
1214
from ._utils import parse_bbox, parse_mag, parse_path
1315

@@ -72,15 +74,24 @@ def main(
7274

7375
layers = layer if layer else None
7476
mags = mag if mag else None
77+
url = resolve_short_link(url)
7578

7679
with webknossos_context(token=token):
77-
try:
80+
if re.match(_DATASET_URL_REGEX, url):
7881
Dataset.download(
7982
dataset_name_or_url=url,
8083
path=target,
8184
bbox=bbox,
8285
layers=layers,
8386
mags=mags,
8487
)
85-
except AssertionError:
88+
elif re.match(_ANNOTATION_URL_REGEX, url):
8689
Annotation.download(annotation_id_or_url=url).save(target)
90+
else:
91+
raise RuntimeError(
92+
"The provided URL does not lead to a dataset or annotation."
93+
)
94+
95+
96+
if __name__ == "__main__":
97+
typer.run(main)

0 commit comments

Comments
 (0)