-
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.
Copy Literals to input Parameter enum field
Signed-off-by: Alice Purcell <[email protected]>
- Loading branch information
1 parent
e9e774f
commit 3aa8505
Showing
5 changed files
with
94 additions
and
5 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
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,18 @@ | ||
from typing import Annotated, Literal | ||
|
||
from hera.shared import global_config | ||
from hera.workflows import Parameter, Steps, Workflow, script | ||
|
||
global_config.experimental_features["script_annotations"] = True | ||
|
||
|
||
@script(constructor="runner") | ||
def literal_str( | ||
my_str: Annotated[Literal["foo", "bar"], Parameter(name="my-str")], | ||
) -> Annotated[Literal[1, 2], Parameter(name="index")]: | ||
return {"foo": 1, "bar": 2}[my_str] | ||
|
||
|
||
with Workflow(name="my-workflow", entrypoint="steps") as w: | ||
with Steps(name="steps"): | ||
literal_str() |
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,13 @@ | ||
from typing import Literal | ||
|
||
from hera.workflows import Steps, Workflow, script | ||
|
||
|
||
@script(constructor="runner") | ||
def literal_str(my_str: Literal["foo", "bar"]) -> Literal[1, 2]: | ||
return {"foo": 1, "bar": 2}[my_str] | ||
|
||
|
||
with Workflow(name="my-workflow", entrypoint="steps") as w: | ||
with Steps(name="steps"): | ||
literal_str() |
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,24 @@ | ||
from typing import Literal | ||
|
||
from hera.shared import global_config | ||
from hera.workflows import Input, Output, Steps, Workflow, script | ||
|
||
global_config.experimental_features["script_pydantic_io"] = True | ||
|
||
|
||
class ExampleInput(Input): | ||
my_str: Literal["foo", "bar"] | ||
|
||
|
||
class ExampleOutput(Output): | ||
index: Literal[1, 2] | ||
|
||
|
||
@script(constructor="runner") | ||
def literal_str(input: ExampleInput) -> ExampleOutput: | ||
return ExampleOutput(index={"foo": 1, "bar": 2}[input.my_str]) | ||
|
||
|
||
with Workflow(name="my-workflow", entrypoint="steps") as w: | ||
with Steps(name="steps"): | ||
literal_str() |
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