Skip to content

Commit

Permalink
Fix script_annotations_artifact_passing example (#786)
Browse files Browse the repository at this point in the history
**Pull Request Checklist**
- [x] Fixes example
- [x] Tests added
- [x] Documentation/examples added
- [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR
title

**Description of PR**
Currently, the script annotation artifact passing example is wrong
because it doesn't specify a Path in the input or use an ArtifactLoader.
However, the path will not generally be used in the function, so in
future we might populate this automatically.

The Script guide was correct, so didn't need to change anything there.

Signed-off-by: Elliot Gunton <egunton@bloomberg.net>
  • Loading branch information
elliotgunton authored Sep 27, 2023
1 parent 013445e commit 650063e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions docs/examples/workflows/script_annotations_artifact_passing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ This example will reuse the outputs volume across script steps.
=== "Hera"

```python linenums="1"
from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore


from pathlib import Path
from hera.shared import global_config
from hera.workflows import (
Artifact,
ArtifactLoader,
Parameter,
Steps,
Workflow,
models as m,
script,
)

Expand All @@ -38,8 +37,14 @@ This example will reuse the outputs volume across script steps.


@script(constructor="runner")
def use_artifact(successor_in: Annotated[int, Artifact(name="successor_in")]):
def use_artifact(
successor_in: Annotated[
int,
Artifact(name="successor_in", path="/my-path", loader=ArtifactLoader.json),
]
):
print(successor_in)
print(Path("/my-path").read_text()) # if you still need the actual path, it is still mounted where you specify


with Workflow(
Expand Down Expand Up @@ -101,6 +106,7 @@ This example will reuse the outputs volume across script steps.
- inputs:
artifacts:
- name: successor_in
path: /my-path
name: use-artifact
script:
args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spec:
- inputs:
artifacts:
- name: successor_in
path: /my-path
name: use-artifact
script:
args:
Expand Down
13 changes: 9 additions & 4 deletions examples/workflows/script_annotations_artifact_passing.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"""This example will reuse the outputs volume across script steps."""


from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore


from pathlib import Path
from hera.shared import global_config
from hera.workflows import (
Artifact,
ArtifactLoader,
Parameter,
Steps,
Workflow,
models as m,
script,
)

Expand All @@ -31,8 +30,14 @@ def output_artifact(


@script(constructor="runner")
def use_artifact(successor_in: Annotated[int, Artifact(name="successor_in")]):
def use_artifact(
successor_in: Annotated[
int,
Artifact(name="successor_in", path="/my-path", loader=ArtifactLoader.json),
]
):
print(successor_in)
print(Path("/my-path").read_text()) # if you still need the actual path, it is still mounted where you specify


with Workflow(
Expand Down

0 comments on commit 650063e

Please sign in to comment.