Script
The hera.workflows.script module provides the Script class.
See https://argoproj.github.io/argo-workflows/workflow-concepts/#script for more on scripts in Argo Workflows.
Script
A Script in Argo Workflows acts as a wrapper around a Container, where you can specify Python code to run through source.
In Hera, you should aim to use the script decorator, rather than the Script class directly. You will need to refer to the Script class for the kwargs that the decorator can take, but your IDE should give you code completion and type hints.
Source code in src/hera/workflows/script.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
get_artifact
Finds and returns the artifact with the supplied name.
Note that this method will raise an error if the artifact is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input artifact to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
the artifact with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the artifact is not found. |
Source code in src/hera/workflows/_mixins.py
get_parameter
Finds and returns the parameter with the supplied name.
Note that this method will raise an error if the parameter is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the input parameter to find and return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Parameter |
Parameter
|
the parameter with the supplied name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the parameter is not found. |
Source code in src/hera/workflows/_mixins.py
ScriptConstructor
A ScriptConstructor is responsible for generating the source code for a Script given a python callable.
This allows users to customize the behaviour of the template that hera generates when a python callable is passed to the Script class.
In order to use your custom ScriptConstructor implementation, you can set it as the Script.constructor field.
Source code in src/hera/workflows/script.py
generate_source
A function that can inspect the Script instance and generate the source field.
transform_script_template_post_build
transform_script_template_post_build(
instance: Script, script: ScriptTemplate
) -> ScriptTemplate
A hook to transform the generated script template.
transform_template_post_build
transform_values
transform_values(script: Script) -> None
InlineScriptConstructor
InlineScriptConstructor is a script constructor that submits a script as a source to Argo.
This script constructor is focused on taking a Python script/function “as is” for remote execution. The
constructor processes the script to infer what parameters it needs to deserialize so the script can execute.
The submitted script will contain prefixes such as new imports, e.g. import os, import json, etc. and
will contain the necessary json.loads calls to deserialize the parameters so they are usable by the script just
like a normal Python script/function.
Source code in src/hera/workflows/script.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
generate_source
Assembles and returns a script representation of the given function.
This also assembles any extra script material prefixed to the string source.
The script is expected to be a callable function the client is interested in submitting
for execution on Argo and the script_extra material represents the parameter loading part obtained, likely,
through get_param_script_portion.
Returns:
str Final formatted script.
Source code in src/hera/workflows/script.py
transform_script_template_post_build
transform_script_template_post_build(
instance: Script, script: ScriptTemplate
) -> ScriptTemplate
A hook to transform the generated script template.
transform_template_post_build
transform_values
transform_values(script: Script) -> None
RunnerScriptConstructor
RunnerScriptConstructor is a script constructor that runs a script in a container.
The runner script, also known as “The Hera runner”, takes a script/Python function definition, infers the path
to the function (module import), assembles a path to invoke the function, and passes any specified parameters
to the function. This helps users “save” on the source space required for submitting a function for remote
execution on Argo. Execution within the container requires the executing container to include the file that
contains the submitted script. More specifically, the container must be created in some process (e.g. CI), so that
it conains the script to run remotely.
Source code in src/hera/workflows/script.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 | |
DEFAULT_HERA_OUTPUTS_DIRECTORY
DEFAULT_HERA_OUTPUTS_DIRECTORY: str = '/tmp/hera-outputs'
Used as the default value for when the outputs_directory is not set
outputs_directory
Used for saving outputs when defined using annotations.
pydantic_mode
Used for selecting the pydantic version used for BaseModels. Allows for using pydantic.v1 BaseModels with pydantic v2. Defaults to the installed version of Pydantic.
volume_for_outputs
volume_for_outputs: Optional[_BaseVolume] = None
Volume to use if saving outputs when defined using annotations.
generate_source
A function that can inspect the Script instance and generate the source field.
transform_script_template_post_build
transform_script_template_post_build(
instance: Script, script: ScriptTemplate
) -> ScriptTemplate
A hook to transform the generated script template.
Source code in src/hera/workflows/script.py
transform_template_post_build
transform_values
transform_values(script: Script) -> None
A function that can inspect the Script instance and generate the source field.
Source code in src/hera/workflows/script.py
script
script(**script_kwargs) -> Callable
A decorator that wraps a function into a Script object.
Using this decorator users can define a function that will be executed as a script in a container. Once the
Script is returned users can use it as they generally use a Script e.g. as a callable inside a DAG or Steps.
Note that invoking the function will result in the template associated with the script to be added to the
workflow context, so users do not have to worry about that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**script_kwargs
|
Keyword arguments to be passed to the Script object. |
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
Function that wraps a given function into a |