-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check that auto-genned params do not have already set artifact na…
…mes (#544) Noticed that when adding a param to a script and then setting an artifact as the value of that script input can result in both an artifact and a parameter added to the template. # Reproducible example (main) ```python from hera.workflows import DAG, Artifact, Workflow, script @script(outputs=Artifact(name="result", path="/tmp/result")) def produce(): import pickle result = "foo testing" with open("/tmp/result", "wb") as f: pickle.dump(result, f) @script(inputs=Artifact(name="i", path="/tmp/i")) def consume(i): import pickle with open("/tmp/i", "rb") as f: i = pickle.load(f) print(i) with Workflow(generate_name="fv-test-", entrypoint="d") as w: with DAG(name="d"): p = produce() c = consume(arguments=Artifact(name="i", from_="{{tasks.produce.outputs.artifacts.result}}")) p >> c print(w.to_yaml()) ``` Above results in: ```yaml ... image: python:3.7 source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport pickle\n\ \nresult = \"foo testing\"\nwith open(\"/tmp/result\", \"wb\") as f:\n \ \ pickle.dump(result, f)\n" - inputs: artifacts: - name: i path: /tmp/i parameters: - name: i name: consume script: command: ... ``` # Post-fix (this branch, isolated to problem section) ```yaml ... \nresult = \"foo testing\"\nwith open(\"/tmp/result\", \"wb\") as f:\n \ \ pickle.dump(result, f)\n" - inputs: artifacts: - name: i path: /tmp/i name: consume script: command: ... ``` --------- Signed-off-by: Flaviu Vadan <[email protected]> Signed-off-by: Sambhav Kothari <[email protected]> Co-authored-by: Sambhav Kothari <[email protected]>
- Loading branch information
1 parent
fe6ef10
commit ef328d2
Showing
5 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Script Auto Infer | ||
|
||
|
||
|
||
|
||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from hera.workflows import DAG, Artifact, Workflow, script | ||
|
||
|
||
@script(outputs=Artifact(name="result", path="/tmp/result")) | ||
def produce(): | ||
import pickle | ||
|
||
result = "foo testing" | ||
with open("/tmp/result", "wb") as f: | ||
pickle.dump(result, f) | ||
|
||
|
||
@script(inputs=Artifact(name="i", path="/tmp/i")) | ||
def consume(i): | ||
import pickle | ||
|
||
with open("/tmp/i", "rb") as f: | ||
i = pickle.load(f) | ||
print(i) | ||
|
||
|
||
with Workflow(generate_name="fv-test-", entrypoint="d") as w: | ||
with DAG(name="d"): | ||
p = produce() | ||
c = consume(arguments=Artifact(name="i", from_="{{tasks.produce.outputs.artifacts.result}}")) | ||
p >> c | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: fv-test- | ||
spec: | ||
entrypoint: d | ||
templates: | ||
- dag: | ||
tasks: | ||
- name: produce | ||
template: produce | ||
- arguments: | ||
artifacts: | ||
- from: '{{tasks.produce.outputs.artifacts.result}}' | ||
name: i | ||
depends: produce | ||
name: consume | ||
template: consume | ||
name: d | ||
- name: produce | ||
outputs: | ||
artifacts: | ||
- name: result | ||
path: /tmp/result | ||
script: | ||
command: | ||
- python | ||
image: python:3.7 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport pickle\n\ | ||
\nresult = \"foo testing\"\nwith open(\"/tmp/result\", \"wb\") as f:\n \ | ||
\ pickle.dump(result, f)\n" | ||
- inputs: | ||
artifacts: | ||
- name: i | ||
path: /tmp/i | ||
name: consume | ||
script: | ||
command: | ||
- python | ||
image: python:3.7 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport json\n\n\ | ||
import pickle\n\nwith open(\"/tmp/i\", \"rb\") as f:\n i = pickle.load(f)\n\ | ||
print(i)\n" | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: fv-test- | ||
spec: | ||
entrypoint: d | ||
templates: | ||
- dag: | ||
tasks: | ||
- name: produce | ||
template: produce | ||
- arguments: | ||
artifacts: | ||
- from: '{{tasks.produce.outputs.artifacts.result}}' | ||
name: i | ||
depends: produce | ||
name: consume | ||
template: consume | ||
name: d | ||
- name: produce | ||
outputs: | ||
artifacts: | ||
- name: result | ||
path: /tmp/result | ||
script: | ||
command: | ||
- python | ||
image: python:3.7 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport pickle\n\ | ||
\nresult = \"foo testing\"\nwith open(\"/tmp/result\", \"wb\") as f:\n \ | ||
\ pickle.dump(result, f)\n" | ||
- inputs: | ||
artifacts: | ||
- name: i | ||
path: /tmp/i | ||
name: consume | ||
script: | ||
command: | ||
- python | ||
image: python:3.7 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport json\n\n\ | ||
import pickle\n\nwith open(\"/tmp/i\", \"rb\") as f:\n i = pickle.load(f)\n\ | ||
print(i)\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from hera.workflows import DAG, Artifact, Workflow, script | ||
|
||
|
||
@script(outputs=Artifact(name="result", path="/tmp/result")) | ||
def produce(): | ||
import pickle | ||
|
||
result = "foo testing" | ||
with open("/tmp/result", "wb") as f: | ||
pickle.dump(result, f) | ||
|
||
|
||
@script(inputs=Artifact(name="i", path="/tmp/i")) | ||
def consume(i): | ||
import pickle | ||
|
||
with open("/tmp/i", "rb") as f: | ||
i = pickle.load(f) | ||
print(i) | ||
|
||
|
||
with Workflow(generate_name="fv-test-", entrypoint="d") as w: | ||
with DAG(name="d"): | ||
p = produce() | ||
c = consume(arguments=Artifact(name="i", from_="{{tasks.produce.outputs.artifacts.result}}")) | ||
p >> c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters