|
3 | 3 | from dataclasses import dataclass, field |
4 | 4 | from dataclasses_json import dataclass_json |
5 | 5 | from requests_toolbelt.sessions import BaseUrlSession |
6 | | -from typing import Optional |
| 6 | +from typing import Optional, TYPE_CHECKING |
7 | 7 | from time import sleep, time |
8 | 8 | from warnings import warn |
9 | 9 |
|
10 | 10 | from codeocean.enum import StrEnum |
11 | 11 | from codeocean.folder import FileURLs, Folder, DownloadFileURL |
12 | 12 |
|
| 13 | +if TYPE_CHECKING: |
| 14 | + from codeocean.data_asset import DataAssetAttachParams, DataAssetAttachResults |
| 15 | + |
13 | 16 |
|
14 | 17 | class ComputationState(StrEnum): |
15 | 18 | """Current state of a computation during its execution lifecycle.""" |
@@ -324,6 +327,27 @@ def wait_until_completed( |
324 | 327 |
|
325 | 328 | sleep(polling_interval) |
326 | 329 |
|
| 330 | + def attach_data_assets( |
| 331 | + self, |
| 332 | + computation_id: str, |
| 333 | + attach_params: list["DataAssetAttachParams"], |
| 334 | + ) -> list["DataAssetAttachResults"]: |
| 335 | + """Attach one or more data assets to a cloud workstation session computation.""" |
| 336 | + from codeocean.data_asset import DataAssetAttachResults |
| 337 | + |
| 338 | + res = self.client.post( |
| 339 | + f"computations/{computation_id}/data_assets", |
| 340 | + json=[j.to_dict() for j in attach_params], |
| 341 | + ) |
| 342 | + return [DataAssetAttachResults.from_dict(c) for c in res.json()] |
| 343 | + |
| 344 | + def detach_data_assets(self, computation_id: str, data_assets: list[str]): |
| 345 | + """Detach one or more data assets from a cloud workstation session computation by their IDs.""" |
| 346 | + self.client.delete( |
| 347 | + f"computations/{computation_id}/data_assets/", |
| 348 | + json=data_assets, |
| 349 | + ) |
| 350 | + |
327 | 351 | def list_computation_results(self, computation_id: str, path: str = "") -> Folder: |
328 | 352 | """List result files and folders generated by a computation |
329 | 353 | at the specified path. Empty path retrieves the /results root folder.""" |
|
0 commit comments