Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix artifact example #719

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions docs/examples/workflows/artifact.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ task, consumer, takes this artifact, places it at its own `/file` path, and prin
=== "Hera"

```python linenums="1"
from hera.workflows import DAG, Artifact, Workflow, script
from hera.workflows import DAG, Artifact, NoneArchiveStrategy, Workflow, script


@script(outputs=Artifact(name="test", path="/file"))
@script(outputs=Artifact(name="out-art", path="/tmp/file", archive=NoneArchiveStrategy()))
def writer():
with open("/file", "w+") as f:
with open("/tmp/file", "w+") as f:
f.write("Hello, world!")


@script(inputs=Artifact(name="test", path="/file"))
@script(inputs=Artifact(name="in-art", path="/tmp/file"))
def consumer():
with open("/file", "r") as f:
with open("/tmp/file", "r") as f:
print(f.readlines()) # prints `Hello, world!` to `stdout`


with Workflow(generate_name="artifact-", entrypoint="d") as w:
with DAG(name="d"):
w_ = writer()
c = consumer(arguments={"test": w_.get_artifact("test")})
c = consumer(arguments=w_.get_artifact("out-art").as_name("in-art"))
w_ >> c
```

Expand All @@ -47,37 +47,37 @@ task, consumer, takes this artifact, places it at its own `/file` path, and prin
- name: writer
template: writer
- arguments:
parameters:
- name: test
value: '{"name": "test", "archive": null, "archive_logs": null, "artifact_gc":
null, "deleted": null, "from_": "{{tasks.writer.outputs.artifacts.test}}",
"from_expression": null, "global_name": null, "mode": null, "path":
"/file", "recurse_mode": null, "sub_path": null}'
artifacts:
- from: '{{tasks.writer.outputs.artifacts.out-art}}'
name: in-art
path: /tmp/file
depends: writer
name: consumer
template: consumer
name: d
- name: writer
outputs:
artifacts:
- name: test
path: /file
- archive:
none: {}
name: out-art
path: /tmp/file
script:
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/file',\
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/file',\
\ 'w+') as f:\n f.write('Hello, world!')"
- inputs:
artifacts:
- name: test
path: /file
- name: in-art
path: /tmp/file
name: consumer
script:
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/file',\
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/file',\
\ 'r') as f:\n print(f.readlines())"
```

12 changes: 6 additions & 6 deletions examples/workflows/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
task, consumer, takes this artifact, places it at its own `/file` path, and print out the content.
"""

from hera.workflows import DAG, Artifact, Workflow, script
from hera.workflows import DAG, Artifact, NoneArchiveStrategy, Workflow, script


@script(outputs=Artifact(name="test", path="/file"))
@script(outputs=Artifact(name="out-art", path="/tmp/file", archive=NoneArchiveStrategy()))
def writer():
with open("/file", "w+") as f:
with open("/tmp/file", "w+") as f:
f.write("Hello, world!")


@script(inputs=Artifact(name="test", path="/file"))
@script(inputs=Artifact(name="in-art", path="/tmp/file"))
def consumer():
with open("/file", "r") as f:
with open("/tmp/file", "r") as f:
print(f.readlines()) # prints `Hello, world!` to `stdout`


with Workflow(generate_name="artifact-", entrypoint="d") as w:
with DAG(name="d"):
w_ = writer()
c = consumer(arguments={"test": w_.get_artifact("test")})
c = consumer(arguments=w_.get_artifact("out-art").as_name("in-art"))
w_ >> c
24 changes: 12 additions & 12 deletions examples/workflows/artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ spec:
- name: writer
template: writer
- arguments:
parameters:
- name: test
value: '{"name": "test", "archive": null, "archive_logs": null, "artifact_gc":
null, "deleted": null, "from_": "{{tasks.writer.outputs.artifacts.test}}",
"from_expression": null, "global_name": null, "mode": null, "path":
"/file", "recurse_mode": null, "sub_path": null}'
artifacts:
- from: '{{tasks.writer.outputs.artifacts.out-art}}'
name: in-art
path: /tmp/file
depends: writer
name: consumer
template: consumer
name: d
- name: writer
outputs:
artifacts:
- name: test
path: /file
- archive:
none: {}
name: out-art
path: /tmp/file
script:
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/file',\
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/file',\
\ 'w+') as f:\n f.write('Hello, world!')"
- inputs:
artifacts:
- name: test
path: /file
- name: in-art
path: /tmp/file
name: consumer
script:
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/file',\
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/file',\
\ 'r') as f:\n print(f.readlines())"
Loading