Skip to content

Commit c74d4d9

Browse files
authored
CI-630 - Add tags to dataset create methods (#152)
* add example for tags and bump api client * add example for import dataset * add to sdk * --help so exit code is 0
1 parent 9bbb0f1 commit c74d4d9

File tree

5 files changed

+450
-405
lines changed

5 files changed

+450
-405
lines changed

.github/workflows/package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Test install
3434
run: |
3535
poetry install --all-extras
36-
poetry run cirro
36+
poetry run cirro --help
3737
3838
- name: Build python package
3939
run: |

cirro/sdk/project.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from time import sleep
33
from typing import List, Union
44

5-
from cirro_api_client.v1.models import Project, UploadDatasetRequest, Dataset, Sample
5+
from cirro_api_client.v1.models import Project, UploadDatasetRequest, Dataset, Sample, Tag
66

77
from cirro.cirro_client import CirroApi
88
from cirro.file_utils import get_files_in_directory
@@ -145,7 +145,8 @@ def upload_dataset(
145145
description='',
146146
process: Union[DataPortalProcess, str] = None,
147147
upload_folder: str = None,
148-
files: list = None
148+
files: List[str] = None,
149+
tags: List[str] = None,
149150
):
150151
"""
151152
Upload a set of files to the Data Portal, creating a new dataset.
@@ -158,6 +159,7 @@ def upload_dataset(
158159
process (str | DataPortalProcess): Process to run may be referenced by name, ID, or object
159160
upload_folder (str): Folder containing files to upload
160161
files (List[str]): Optional subset of files to upload from the folder
162+
tags (List[str]): Optional list of tags to apply to the dataset
161163
"""
162164

163165
if name is None:
@@ -178,6 +180,10 @@ def upload_dataset(
178180
if files is None or len(files) == 0:
179181
raise RuntimeWarning("No files to upload, exiting")
180182

183+
# Normalize into Tag object
184+
if tags is not None:
185+
tags = [Tag(value=value) for value in tags]
186+
181187
# Make sure that the files match the expected pattern
182188
self._client.processes.check_dataset_files(files, process.id, upload_folder)
183189

@@ -186,7 +192,8 @@ def upload_dataset(
186192
process_id=process.id,
187193
name=name,
188194
description=description,
189-
expected_files=files
195+
expected_files=files,
196+
tags=tags,
190197
)
191198

192199
# Get the response

cirro/services/dataset.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ def import_public(self, project_id: str, import_request: ImportDataRequest) -> C
7878
7979
Returns:
8080
ID of the created dataset
81+
82+
```python
83+
from cirro_api_client.v1.models import ImportDataRequest, Tag
84+
from cirro.cirro_client import CirroApi
85+
86+
cirro = CirroApi()
87+
request = ImportDataRequest(
88+
name="Imported dataset",
89+
description="Description of the dataset",
90+
public_ids=["SRR123456", "SRR123457"],
91+
tags=[Tag(value="tag1")]
92+
)
93+
cirro.datasets.import_public("project-id", request)
94+
```
8195
"""
8296
return import_public_dataset.sync(project_id=project_id, client=self._api_client, body=import_request)
8397

@@ -93,15 +107,16 @@ def create(self, project_id: str, upload_request: UploadDatasetRequest) -> Uploa
93107
ID of the created dataset and the path to upload files
94108
95109
```python
96-
from cirro_api_client.v1.models import UploadDatasetRequest
110+
from cirro_api_client.v1.models import UploadDatasetRequest, Tag
97111
from cirro.cirro_client import CirroApi
98112
99113
cirro = CirroApi()
100114
request = UploadDatasetRequest(
101115
name="Name of new dataset",
102116
process_id="paired_dnaseq",
103117
expected_files=["read_1.fastq.gz", "read_2.fastq.gz"],
104-
description="Description of the dataset"
118+
description="Description of the dataset",
119+
tags=[Tag(value="tag1"), Tag(value="tag2")]
105120
)
106121
cirro.datasets.create("project-id", request)
107122
```

0 commit comments

Comments
 (0)