Custom Actions¶
A step in StepUp consists of an action (which is a string representing something executable) and a set of additional arguments that control the execution: required inputs, outputs, working directory, …
Many steps use the runsh action, which executes a shell command in a subprocess.
However, there are situations where this is not the best option:
- When the overhead of starting a new process is too high.
- If the step should execute Python code for which you do not want to create a new command line entry point.
For these situations, you can create a custom action, which consists of two parts:
-
Write a Python function that implements the action:
Of course, you should use a more descriptive name than
custom_action.The following conventions are assumed:
- The action function takes two arguments and returns an integer, which is treated as the exit code of the action. (Zero means success, non-zero means failure.)
- The most important argument is
argstr, which contains the part of the string after the action. For example, if the step isrunsh echo hello,argstrwill beecho hello. - The second argument is a
WorkThreadobject, which is only used for launching new subprocesses with thework_thread.runsh()method.
-
Create an action entry point in
pyproject.tomlpointing to this function:where you replace
your.packagewith the name of the module that containscustom_action.