|
| 1 | +from collections import OrderedDict |
| 2 | +from dataclasses import dataclass, field |
| 3 | +from datetime import date, datetime |
| 4 | +from typing import Dict, List, Optional, Protocol, TypeVar, Union |
| 5 | + |
| 6 | +from typing_extensions import Self |
| 7 | + |
| 8 | +from synapseclient import Synapse |
| 9 | +from synapseclient.core.async_utils import async_to_sync |
| 10 | +from synapseclient.core.constants import concrete_types |
| 11 | +from synapseclient.core.utils import delete_none_keys |
| 12 | +from synapseclient.models import Activity, Annotations |
| 13 | +from synapseclient.models.mixins.access_control import AccessControllable |
| 14 | +from synapseclient.models.mixins.table_components import ( |
| 15 | + DeleteMixin, |
| 16 | + GetMixin, |
| 17 | +) |
| 18 | + |
| 19 | + |
| 20 | +class SubmissionSynchronousProtocol(Protocol): |
| 21 | + """Protocol defining the synchronous interface for Submission operations.""" |
| 22 | + |
| 23 | + def get( |
| 24 | + self, |
| 25 | + include_activity: bool = False, |
| 26 | + *, |
| 27 | + synapse_client: Optional[Synapse] = None, |
| 28 | + ) -> "Self": |
| 29 | + """ |
| 30 | + Retrieve a Submission from Synapse. |
| 31 | +
|
| 32 | + Arguments: |
| 33 | + include_activity: Whether to include the activity in the returned submission. |
| 34 | + Defaults to False. Setting this to True will include the activity |
| 35 | + record associated with this submission. |
| 36 | + synapse_client: If not passed in and caching was not disabled by |
| 37 | + `Synapse.allow_client_caching(False)` this will use the last created |
| 38 | + instance from the Synapse class constructor. |
| 39 | +
|
| 40 | + Returns: |
| 41 | + The Submission instance retrieved from Synapse. |
| 42 | +
|
| 43 | + Example: Retrieving a submission by ID. |
| 44 | + |
| 45 | +
|
| 46 | + ```python |
| 47 | + from synapseclient import Synapse |
| 48 | + from synapseclient.models import Submission |
| 49 | +
|
| 50 | + syn = Synapse() |
| 51 | + syn.login() |
| 52 | +
|
| 53 | + submission = Submission(id="syn1234").get() |
| 54 | + print(submission) |
| 55 | + ``` |
| 56 | + """ |
| 57 | + return self |
| 58 | + |
| 59 | + def delete(self, *, synapse_client: Optional[Synapse] = None) -> None: |
| 60 | + """ |
| 61 | + Delete a Submission from Synapse. |
| 62 | +
|
| 63 | + Arguments: |
| 64 | + synapse_client: If not passed in and caching was not disabled by |
| 65 | + `Synapse.allow_client_caching(False)` this will use the last created |
| 66 | + instance from the Synapse class constructor. |
| 67 | +
|
| 68 | + Example: Delete a submission. |
| 69 | + |
| 70 | +
|
| 71 | + ```python |
| 72 | + from synapseclient import Synapse |
| 73 | + from synapseclient.models import Submission |
| 74 | +
|
| 75 | + syn = Synapse() |
| 76 | + syn.login() |
| 77 | +
|
| 78 | + submission = Submission(id="syn1234") |
| 79 | + submission.delete() |
| 80 | + print("Deleted Submission.") |
| 81 | + ``` |
| 82 | + """ |
| 83 | + pass |
| 84 | + |
| 85 | + |
| 86 | +@dataclass |
| 87 | +@async_to_sync |
| 88 | +class Submission( |
| 89 | + SubmissionSynchronousProtocol, |
| 90 | + AccessControllable, |
| 91 | + GetMixin, |
| 92 | + DeleteMixin, |
| 93 | +): |
| 94 | + """A `Submission` object represents a Synapse Submission, which is created when a user |
| 95 | + submits an entity to an evaluation queue. |
| 96 | + <https://rest-docs.synapse.org/rest/org/sagebionetworks/evaluation/model/Submission.html> |
| 97 | +
|
| 98 | + Attributes: |
| 99 | + id: The unique ID of this Submission. |
| 100 | + user_id: The ID of the user that submitted this Submission. |
| 101 | + submitter_alias: The name of the user that submitted this Submission. |
| 102 | + entity_id: The ID of the entity being submitted. |
| 103 | + version_number: The version number of the entity at submission. |
| 104 | + evaluation_id: The ID of the Evaluation to which this Submission belongs. |
| 105 | + name: The name of this Submission. |
| 106 | + created_on: The date this Submission was created. |
| 107 | + team_id: The ID of the team that submitted this submission (if it's a team submission). |
| 108 | + contributors: User IDs of team members who contributed to this submission (if it's a team submission). |
| 109 | + submission_status: The status of this Submission. |
| 110 | + entity_bundle_json: The bundled entity information at submission. This includes the entity, annotations, |
| 111 | + file handles, and other metadata. |
| 112 | + docker_repository_name: For Docker repositories, the repository name. |
| 113 | + docker_digest: For Docker repositories, the digest of the submitted Docker image. |
| 114 | + activity: The Activity model represents the main record of Provenance in Synapse. |
| 115 | + |
| 116 | + Example: Retrieve a Submission. |
| 117 | + ```python |
| 118 | + from synapseclient import Synapse |
| 119 | + from synapseclient.models import Submission |
| 120 | +
|
| 121 | + syn = Synapse() |
| 122 | + syn.login() |
| 123 | +
|
| 124 | + submission = Submission(id="syn123456").get() |
| 125 | + print(submission) |
| 126 | + ``` |
| 127 | + """ |
| 128 | + |
| 129 | + id: Optional[str] = None |
| 130 | + """ |
| 131 | + The unique ID of this Submission. |
| 132 | + """ |
| 133 | + |
| 134 | + user_id: Optional[str] = None |
| 135 | + """ |
| 136 | + The ID of the user that submitted this Submission. |
| 137 | + """ |
| 138 | + |
| 139 | + submitter_alias: Optional[str] = None |
| 140 | + """ |
| 141 | + The name of the user that submitted this Submission. |
| 142 | + """ |
| 143 | + |
| 144 | + entity_id: Optional[str] = None |
| 145 | + """ |
| 146 | + The ID of the entity being submitted. |
| 147 | + """ |
| 148 | + |
| 149 | + version_number: Optional[int] = field(default=None, compare=False) |
| 150 | + """ |
| 151 | + The version number of the entity at submission. |
| 152 | + """ |
| 153 | + |
| 154 | + evaluation_id: Optional[str] = None |
| 155 | + """ |
| 156 | + The ID of the Evaluation to which this Submission belongs. |
| 157 | + """ |
| 158 | + |
| 159 | + name: Optional[str] = None |
| 160 | + """ |
| 161 | + The name of this Submission. |
| 162 | + """ |
| 163 | + |
| 164 | + created_on: Optional[str] = field(default=None, compare=False) |
| 165 | + """ |
| 166 | + The date this Submission was created. |
| 167 | + """ |
| 168 | + |
| 169 | + team_id: Optional[str] = None |
| 170 | + """ |
| 171 | + The ID of the team that submitted this submission (if it's a team submission). |
| 172 | + """ |
| 173 | + |
| 174 | + contributors: List[str] = field(default_factory=list) |
| 175 | + """ |
| 176 | + User IDs of team members who contributed to this submission (if it's a team submission). |
| 177 | + """ |
| 178 | + |
| 179 | + submission_status: Optional[Dict] = None |
| 180 | + """ |
| 181 | + The status of this Submission. |
| 182 | + """ |
| 183 | + |
| 184 | + entity_bundle_json: Optional[str] = None |
| 185 | + """ |
| 186 | + The bundled entity information at submission. This includes the entity, annotations, |
| 187 | + file handles, and other metadata. |
| 188 | + """ |
| 189 | + |
| 190 | + docker_repository_name: Optional[str] = None |
| 191 | + """ |
| 192 | + For Docker repositories, the repository name. |
| 193 | + """ |
| 194 | + |
| 195 | + docker_digest: Optional[str] = None |
| 196 | + """ |
| 197 | + For Docker repositories, the digest of the submitted Docker image. |
| 198 | + """ |
| 199 | + |
| 200 | + activity: Optional[Activity] = field(default=None, compare=False) |
| 201 | + """The Activity model represents the main record of Provenance in Synapse. It is |
| 202 | + analogous to the Activity defined in the |
| 203 | + [W3C Specification](https://www.w3.org/TR/prov-n/) on Provenance.""" |
| 204 | + |
| 205 | + _last_persistent_instance: Optional["Submission"] = field( |
| 206 | + default=None, repr=False, compare=False |
| 207 | + ) |
| 208 | + """The last persistent instance of this object. This is used to determine if the |
| 209 | + object has been changed and needs to be updated in Synapse.""" |
0 commit comments