Skip to content

Commit 67483f0

Browse files
normanrzfm3
andauthored
add --folder to upload (#1408)
* add --folder-name to upload * changelog * --folder * pass folder id to reserve dataset upload api call * docs --------- Co-authored-by: Florian M <[email protected]>
1 parent d7b7a39 commit 67483f0

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

docs/src/cli/upload.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ webknossos upload [OPTIONS] SOURCE
3232
Number of processes to spawn for parallel upload execution.
3333
Default: 5.
3434

35+
- `--folder`
36+
WEBKNOSSOS dataset folder in which the dataset should be placed. Specify the folder path as a string, separated by `/`. Note that this is about the folders listed in the dataset dashboard, and is independent of the underlying storage location. Example: `Datasets/mySubfolder`.
37+
If not provided, the root folder is used.
38+
3539
### Environment Variables for Remote Paths
3640

3741
When using remote paths (e.g., HTTP or S3), configure the following environment variables:

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1515
### Breaking Changes
1616

1717
### Added
18+
- Added `--folder` option to `upload` CLI command. [#1408](https://github.com/scalableminds/webknossos-libs/pull/1408)
1819

1920
### Changed
2021
- Relaxed layer name validation to match WEBKNOSSOS behavior. [#1402](https://github.com/scalableminds/webknossos-libs/pull/1402)

webknossos/webknossos/cli/upload.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ..client import webknossos_context
88
from ..client._defaults import DEFAULT_WEBKNOSSOS_URL
99
from ..client._upload_dataset import DEFAULT_SIMULTANEOUS_UPLOADS
10-
from ..dataset import Dataset
10+
from ..dataset import Dataset, RemoteFolder
1111
from ._utils import parse_path
1212

1313

@@ -42,7 +42,14 @@ def main(
4242
str | None,
4343
typer.Option(
4444
help="Alternative name to rename your dataset on upload to WEBKNOSSOS. "
45-
"(if not provided, current name of dataset is used)",
45+
"If not provided, current dataset name is used.",
46+
),
47+
] = None,
48+
folder: Annotated[
49+
str | None,
50+
typer.Option(
51+
help="WEBKNOSSOS dataset folder in which the dataset should be placed. Specify the folder path as a string, separated by `/`. Note that this is about the folders listed in the dataset dashboard, and is independent of the underlying storage location. Example: `Datasets/mySubfolder`. "
52+
"If not provided, the root folder is used.",
4653
),
4754
] = None,
4855
jobs: Annotated[
@@ -56,6 +63,9 @@ def main(
5663
"""Upload a dataset to a WEBKNOSSOS server."""
5764

5865
with webknossos_context(url=webknossos_url, token=token):
66+
folder_id: None | RemoteFolder = None
67+
if folder is not None:
68+
folder_id = RemoteFolder.get_by_path(folder)
5969
Dataset.open(dataset_path=source).upload(
60-
new_dataset_name=dataset_name, jobs=jobs
70+
new_dataset_name=dataset_name, jobs=jobs, folder_id=folder_id
6171
)

webknossos/webknossos/client/_upload_dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def upload_dataset(
4949
layers_to_link: list[LayerToLink] | None = None,
5050
jobs: int | None = None,
5151
datastore_url: str | None = None,
52+
folder_id: str | None = None,
5253
) -> str:
5354
if new_dataset_name is None:
5455
new_dataset_name = dataset.name
@@ -103,7 +104,7 @@ def upload_dataset(
103104
layers_to_link=[
104105
layer._as_api_linked_layer_identifier() for layer in layers_to_link
105106
],
106-
folder_id=None,
107+
folder_id=folder_id,
107108
initial_teams=[],
108109
),
109110
retry_count=MAXIMUM_RETRY_COUNT,

webknossos/webknossos/dataset/dataset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,11 @@ def upload(
707707
from ..client._upload_dataset import upload_dataset
708708

709709
new_dataset_id = upload_dataset(
710-
self, new_dataset_name, converted_layers_to_link, jobs
710+
self,
711+
new_dataset_name,
712+
converted_layers_to_link,
713+
jobs,
714+
folder_id=folder_id,
711715
)
712716

713717
return RemoteDataset.open(dataset_id=new_dataset_id)

0 commit comments

Comments
 (0)