script tasks#

Script tasks consist of a reference to a python callable to import and execute, and optionally values or expressions to pass as arguments, for example:

fetch-assets.script = "my_pkg.assets:fetch"
fetch-images.script = "my_pkg.assets:fetch(only='images', log=environ['LOG_PATH'])"

As in the second example, is it possible to hard code literal arguments to the target callable. In fact a subset of python syntax, operators, and globals can be used inline to define the arguments to the function using normal python syntax, including environ (from the os package) to access environment variables that are available to the task.

If extra arguments are passed to task on the command line (and no CLI args are declared), then they will be available within the called python function via sys.argv. If args are configured for the task then they will be available as python variables.

If the target python function is an async function then it will be exectued with

Available task options#

script tasks support all of the standard task options.

The following options are also accepted:

print_resultbool 📖

If true then the return value of the python callable will be output to stdout, unless it is None.

Output the return value#

Script tasks can be configured to output the return value of the python callable using the print_result option.

script = ""
print_result = true

Given the above configuration running the following command would output just the generated key.

poe -q create-secret

Note that if the return value is None then the print_result option has no effect.

Calling standard library functions#

Any python callable accessible via the python path can be referenced, including the standard library. This can be useful for ensuring that tasks work across platforms.

For example, the following task will not always work on windows:

cmd = "mkdir -p build/assets"

whereas the same behaviour can can be reliably achieved like so:

script = "os:makedirs('build/assets', exist_ok=True)"