<jupyter_start><jupyter_text>Table of Contents<jupyter_code>%load_ext autoreload
%autoreload 2
from argo.workflows.dsl import Workflow

from argo.workflows.dsl.tasks import *
from argo.workflows.dsl.templates import *
import yaml

from pprint import pprint

from argo.workflows.dsl._utils import sanitize_for_serialization<jupyter_output><empty_output><jupyter_text>---<jupyter_code>!sh -c '[ -f "artifacts.yaml" ] || curl -LO https://raw.githubusercontent.com/CermakM/argo-python-dsl/master/examples/artifacts.yaml'
from pathlib import Path

manifest = Path("./artifacts.yaml").read_text()
print(manifest)
class ArtifactPassing(Workflow):
    
    @task
    def generate_artifact(self) -> V1alpha1Template:
        return self.whalesay()
    
    @task
    @artifact(
        name="message",
        _from="{{tasks.generate-artifact.outputs.artifacts.hello-art}}"
    )
    def consume_artifact(self, message: V1alpha1Artifact) -> V1alpha1Template:
        return self.print_message(message=message)
    
    @template
    @outputs.artifact(name="hello-art", path="/tmp/hello_world.txt")
    def whalesay(self) -> V1Container:
        container = V1Container(
            name="whalesay",
            image="docker/whalesay:latest",
            command=["sh", "-c"],
            args=["cowsay hello world | tee /tmp/hello_world.txt"]
        )
        
        return container
    
    @template
    @inputs.artifact(name="message", path="/tmp/message")
    def print_message(self, message: V1alpha1Artifact) -> V1Container:
        container = V1Container(
            name="print-message",
            image="alpine:latest",
            command=["sh", "-c"],
            args=["cat", "/tmp/message"],
        )
        
        return container

wf = ArtifactPassing()
wf
print(wf.to_yaml())<jupyter_output>api_version: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generate_name: artifact-passing-
  name: artifact-passing
spec:
  entrypoint: main
  templates:
  - dag:
      tasks:
      - name: generate-artifact
        template: whalesay
      - arguments:
          artifacts:
          - _from: '{{tasks.generate-artifact.outputs.artifacts.hello-art}}'
            name: message
        name: consume-artifact
        template: print-message
    name: main
  - container:
      args:
      - cowsay hello world | tee /tmp/hello_world.txt
      command:
      - sh
      - -c
      image: docker/whalesay:latest
      name: whalesay
    name: whalesay
    outputs:
      artifacts:
      - name: hello-art
        path: /tmp/hello_world.txt
  - container:
      args:
      - cat
      - /tmp/message
      command:
      - sh
      - -c
      image: alpine:latest
      name: print-message
    inputs:
      artifacts:
      - name: message
        path: /tmp/message
    name: print-message
status[...]<jupyter_text>---<jupyter_code>pprint(sanitize_for_serialization(wf))
pprint(yaml.safe_load(manifest))
from deepdiff import DeepDiff

diff = DeepDiff(sanitize_for_serialization(wf), yaml.safe_load(manifest))
diff
assert not diff, "Manifests don't match."<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11774193548387096, 'fraction_numerical': 0.004838709677419355, 'mean_word_length': 2.674170616113744, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '130602', 'license': 'Apache-2.0', 'n_tokens_mistral': 1033, 'n_tokens_neox': 992, 'n_words': 186, 'path': 'examples/artifacts.ipynb', 'repo_name': 'asavpatel92/argo-python-dsl', 'size': '3100'}