|
1 | 1 | """Top-level class for all data concepts objects and collections thereof."""
|
2 |
| -from abc import abstractmethod, ABC |
3 | 2 | import re
|
| 3 | +from abc import abstractmethod, ABC |
4 | 4 | from typing import TypeVar, Type, List, Union, Optional, Iterator, Iterable
|
5 | 5 | from uuid import UUID, uuid4
|
6 | 6 |
|
|
18 | 18 | from citrine._serialization.properties import UUID as PropertyUUID
|
19 | 19 | from citrine._serialization.serializable import Serializable
|
20 | 20 | from citrine._session import Session
|
21 |
| -from citrine._utils.functions import scrub_none, replace_objects_with_links, \ |
22 |
| - format_escaped_url |
| 21 | +from citrine._utils.functions import _data_manager_deprecation_checks, format_escaped_url, \ |
| 22 | + _pad_positional_args, replace_objects_with_links, scrub_none |
23 | 23 | from citrine.exceptions import BadRequest
|
24 | 24 | from citrine.resources.audit_info import AuditInfo
|
25 | 25 | from citrine.jobs.job import _poll_for_job_completion
|
@@ -202,28 +202,56 @@ class DataConceptsCollection(Collection[ResourceType], ABC):
|
202 | 202 |
|
203 | 203 | Parameters
|
204 | 204 | ----------
|
205 |
| - project_id: UUID |
206 |
| - The uid of the project that this collection belongs to. |
| 205 | + team_id: UUID |
| 206 | + The uid of the team that this collection belongs to. |
207 | 207 | dataset_id: UUID
|
208 | 208 | The uid of the dataset that this collection belongs to. If None then the collection
|
209 |
| - ranges over all datasets in the project. Note that this is only allowed for certain |
| 209 | + ranges over all datasets in the team. Note that this is only allowed for certain |
210 | 210 | actions. For example, you can use :func:`list_by_tag` to search over all datasets,
|
211 | 211 | but when using :func:`register` to upload or update an object, a dataset must be specified.
|
212 | 212 | session: Session
|
213 | 213 | The Citrine session used to connect to the database.
|
214 | 214 |
|
215 | 215 | """
|
216 | 216 |
|
217 |
| - def __init__(self, project_id: UUID, dataset_id: UUID, session: Session): |
218 |
| - self.project_id = project_id |
219 |
| - self.dataset_id = dataset_id |
220 |
| - self.session = session |
| 217 | + def __init__(self, |
| 218 | + *args, |
| 219 | + session: Session = None, |
| 220 | + dataset_id: Optional[UUID] = None, |
| 221 | + team_id: Optional[UUID] = None, |
| 222 | + project_id: Optional[UUID] = None): |
| 223 | + # Handle positional arguments for backward compatibility |
| 224 | + args = _pad_positional_args(args, 3) |
| 225 | + self.project_id = project_id or args[0] |
| 226 | + self.dataset_id = dataset_id or args[1] |
| 227 | + self.session = session or args[2] |
| 228 | + if self.session is None: |
| 229 | + raise TypeError("Missing one required argument: session.") |
| 230 | + |
| 231 | + self.team_id = _data_manager_deprecation_checks( |
| 232 | + session=self.session, |
| 233 | + project_id=self.project_id, |
| 234 | + team_id=team_id, |
| 235 | + obj_type="GEMD Objects") |
221 | 236 |
|
222 | 237 | @classmethod
|
223 | 238 | @abstractmethod
|
224 | 239 | def get_type(cls) -> Type[Serializable]:
|
225 | 240 | """Return the resource type in the collection."""
|
226 | 241 |
|
| 242 | + @property |
| 243 | + def _path_template(self): |
| 244 | + collection_key = self._collection_key.replace("_", "-") |
| 245 | + return f'teams/{self.team_id}/datasets/{self.dataset_id}/{collection_key}' |
| 246 | + |
| 247 | + # After Data Manager deprecation, both can use the `teams/...` path. |
| 248 | + @property |
| 249 | + def _dataset_agnostic_path_template(self): |
| 250 | + if self.project_id is None: |
| 251 | + return f'teams/{self.team_id}/{self._collection_key.replace("_","-")}' |
| 252 | + else: |
| 253 | + return f'projects/{self.project_id}/{self._collection_key.replace("_","-")}' |
| 254 | + |
227 | 255 | def build(self, data: dict) -> ResourceType:
|
228 | 256 | """
|
229 | 257 | Build an object of type ResourceType from a serialized dictionary.
|
@@ -390,7 +418,9 @@ def register_all(self,
|
390 | 418 |
|
391 | 419 | """
|
392 | 420 | from citrine.resources.gemd_resource import GEMDResourceCollection
|
393 |
| - gemd_collection = GEMDResourceCollection(self.project_id, self.dataset_id, self.session) |
| 421 | + gemd_collection = GEMDResourceCollection(team_id=self.team_id, |
| 422 | + dataset_id=self.dataset_id, |
| 423 | + session=self.session) |
394 | 424 | return gemd_collection.register_all(
|
395 | 425 | models,
|
396 | 426 | dry_run=dry_run,
|
@@ -482,7 +512,7 @@ def async_update(self, model: ResourceType, *,
|
482 | 512 | job_id = response_json["job_id"]
|
483 | 513 |
|
484 | 514 | if wait_for_response:
|
485 |
| - self.poll_async_update_job(job_id, timeout=timeout, |
| 515 | + self.poll_async_update_job(job_id=job_id, timeout=timeout, |
486 | 516 | polling_delay=polling_delay)
|
487 | 517 |
|
488 | 518 | # That worked, return nothing or return the object
|
@@ -525,8 +555,12 @@ def poll_async_update_job(self, job_id: UUID, *, timeout: float = 2 * 60,
|
525 | 555 |
|
526 | 556 | """
|
527 | 557 | # Poll for job completion - this will raise an error if the job failed
|
528 |
| - _poll_for_job_completion(self.session, self.project_id, job_id, timeout=timeout, |
529 |
| - polling_delay=polling_delay) |
| 558 | + _poll_for_job_completion( |
| 559 | + session=self.session, |
| 560 | + team_id=self.team_id, |
| 561 | + project_id=self.project_id, |
| 562 | + job=job_id, timeout=timeout, |
| 563 | + polling_delay=polling_delay) |
530 | 564 |
|
531 | 565 | # That worked, nothing returned in this case
|
532 | 566 | return None
|
@@ -675,8 +709,8 @@ def _get_relation(self, relation: str, uid: Union[UUID, str, LinkByUID, BaseEnti
|
675 | 709 | link = _make_link_by_uid(uid)
|
676 | 710 | raw_objects = self.session.cursor_paged_resource(
|
677 | 711 | self.session.get_resource,
|
678 |
| - format_escaped_url('projects/{}/{}/{}/{}/{}', |
679 |
| - self.project_id, |
| 712 | + format_escaped_url('teams/{}/{}/{}/{}/{}', |
| 713 | + self.team_id, |
680 | 714 | relation,
|
681 | 715 | link.scope,
|
682 | 716 | link.id,
|
|
0 commit comments