Skip to content

Commit

Permalink
Move new syntax behind decorator_syntax feature
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Purcell <[email protected]>
  • Loading branch information
alicederyn committed Sep 5, 2024
1 parent ce12edf commit 0a7fb95
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hera.workflows import DAG, Parameter, WorkflowTemplate, script
from hera.workflows.io.v1 import Input, Output

global_config.experimental_features["script_pydantic_io"] = True
global_config.experimental_features["decorator_syntax"] = True


class CutInput(Input):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hera.workflows import Parameter, Steps, WorkflowTemplate, script
from hera.workflows.io.v1 import Input, Output

global_config.experimental_features["script_pydantic_io"] = True
global_config.experimental_features["decorator_syntax"] = True


class CutInput(Input):
Expand Down
22 changes: 16 additions & 6 deletions src/hera/workflows/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from hera.expr import g
from hera.shared import BaseMixin, global_config
from hera.shared._global_config import (
_DECORATOR_SYNTAX_FLAG,
_SCRIPT_ANNOTATIONS_FLAG,
_SCRIPT_PYDANTIC_IO_FLAG,
_flag_enabled,
Expand Down Expand Up @@ -378,15 +379,19 @@ def _get_parameters_from_callable(source: Callable) -> List[Parameter]:
return parameters


def please_enable_experimental_feature(flag: str) -> str:
return (
"Please turn on experimental features by setting "
f'`hera.shared.global_config.experimental_features["{flag}"] = True`.'
" Note that experimental features are unstable and subject to breaking changes."
)


def _assert_pydantic_io_enabled(annotation: str) -> None:
if not _flag_enabled(_SCRIPT_PYDANTIC_IO_FLAG):
raise ValueError(
(
"Unable to instantiate {} since it is an experimental feature."
" Please turn on experimental features by setting "
'`hera.shared.global_config.experimental_features["{}"] = True`.'
" Note that experimental features are unstable and subject to breaking changes."
).format(annotation, _SCRIPT_PYDANTIC_IO_FLAG)
f"Unable to instantiate {annotation} since it is an experimental feature. "
+ please_enable_experimental_feature(_SCRIPT_PYDANTIC_IO_FLAG)
)


Expand Down Expand Up @@ -767,6 +772,11 @@ def task_wrapper(*args, **kwargs) -> Union[FuncR, Step, Task, None]:
"""Invokes a `Script` object's `__call__` method using the given SubNode (Step or Task) args/kwargs."""
if _context.active:
if len(args) == 1 and isinstance(args[0], (InputV1, InputV2)):
if not _flag_enabled(_DECORATOR_SYNTAX_FLAG):
raise SyntaxError(
"Cannot pass a Pydantic type inside a context. "
+ please_enable_experimental_feature(_DECORATOR_SYNTAX_FLAG)
)
arguments = args[0]._get_as_arguments()
arguments_list = [
*(arguments.artifacts or []),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from hera.shared._global_config import _SCRIPT_PYDANTIC_IO_FLAG
from hera.shared._global_config import _DECORATOR_SYNTAX_FLAG
from hera.workflows import Input, Output, Steps, Workflow, script


Expand All @@ -14,7 +14,7 @@ class IntOutput(Output):

@pytest.fixture(autouse=True)
def enable_pydantic_io(global_config_fixture):
global_config_fixture.experimental_features[_SCRIPT_PYDANTIC_IO_FLAG] = True
global_config_fixture.experimental_features[_DECORATOR_SYNTAX_FLAG] = True


def test_output_field_contains_argo_template(global_config_fixture):
Expand Down

0 comments on commit 0a7fb95

Please sign in to comment.