def duplicate(self, new_id, include_versions=True, client=None): """ Duplicate this `Workflow` object with a new ID. This does not save the new object to the backend; to do so, call `~.save`. Parameters ---------- new_id: str ID for the copied `Workflow` include_versions: bool, optional, default True Whether to also copy over all the versions currently set on this `Workflow` Returns ------- new_workflow: Workflow Copy of ``self`` with a new ID """ if client is None: client = self._client new_message = workflow_pb2.Workflow() new_message.CopyFrom(self._message) new_message.id = new_id if not include_versions: new_message.ClearField("versioned_grafts") return self._from_proto(new_message, client)
def build(cls, proxy_object, name="", description="", client=None): """ Construct a new Workflow from a proxy object. Note that this does not persist the `Workflow`, call `save()` on the returned `Workflow` to do that. Parameters ---------- proxy_object: Proxytype The proxy object to store in this Workflow name: str, default "" Name for the new Workflow description: str, default "" Long-form description of this Workflow. Markdown is supported. client : Compute, optional Allows you to use a specific client instance with non-default auth and parameters Returns ------- Workflow Example ------- >>> from descarteslabs.workflows import Workflow, Int >>> my_int = Int(1) + 1 >>> workflow = Workflow.build(my_int, name="one-plus-one", description="The result of 1 plus 1") >>> workflow <descarteslabs.workflows.models.workflow.Workflow object at 0x...> """ typespec = serialize_typespec(type(proxy_object)) graft = proxy_object.graft message = workflow_pb2.Workflow( name=name, description=description, serialized_graft=json.dumps(graft), typespec=typespec, channel=_channel.__channel__, ) return cls(proxy_object, message, client=client)
def duplicate(self, new_id, include_versions=True, client=None): """ Duplicate this `Workflow` object with a new ID. This does not save the new object to the backend; to do so, call `~.save`. Parameters ---------- new_id: str ID for the copied `Workflow` include_versions: bool, optional, default True Whether to also copy over all the versions currently set on this `Workflow` Returns ------- new_workflow: Workflow Copy of ``self`` with a new ID Example ------- >>> from descarteslabs.workflows import Workflow >>> workflow = Workflow.get("[email protected]:cool_model") # doctest: +SKIP >>> new_workflow = workflow.duplicate("[email protected]:even_cooler_model") # doctest: +SKIP >>> new_workflow.id # doctest: +SKIP "[email protected]:even_cooler_model" >>> new_workflow.save() # doctest: +SKIP >>> # ^ save the duplicated workflow to the backend """ if client is None: client = self._client new_message = workflow_pb2.Workflow() new_message.CopyFrom(self._message) new_message.id = new_id if not include_versions: new_message.ClearField("versioned_grafts") return self._from_proto(new_message, client)
def __init__( self, id, title="", description="", labels=None, tags=None, client=None, ): """ Construct a `Workflow` object referencing a new or existing Workflow. Parameters ---------- id: str ID for the new `Workflow`. This should be of the form ``"email:workflow_name"`` and should be globally unique. If this ID is not of the proper format, you will not be able to save the `Workflow`. Cannot be changed once set. title: str, default "" User-friendly title for the `Workflow`. description: str, default "" Long-form description of this `Workflow`. Markdown is supported. labels: dict, optional Key-value pair labels to add to the `Workflow`. tags: list, optional A list of strings of tags to add to the `Workflow`. client: `.workflows.client.Client`, optional Allows you to use a specific client instance with non-default auth and parameters. Returns ------- Workflow Example ------- >>> from descarteslabs.workflows import Workflow, Int >>> workflow = Workflow( ... id="[email protected]:cool_addition_model", ... title="Bob's Super Cool Addition Model", ... description="The result of 1 plus 1", ... labels={"project": "arithmetic"}, ... tags=["test", "cool", "deep learning", "AI", "digital twin"]) # doctest: +SKIP >>> workflow # doctest: +SKIP Workflow: "Bob's Super Cool Addition Model" - id: [email protected]:cool_addition_model - labels: {'project': 'arithmetic'} - tags: ['test', 'cool', 'deep learning', 'AI', 'digital twin'] - versions: '0.0.1', '0.0.2' The result of 1 plus 1 """ if client is None: client = get_global_grpc_client() message = workflow_pb2.Workflow( id=id, title=title, description=textwrap.dedent(description), labels=labels, tags=tags, ) self._message = message self._client = client