Did you know you Cylc extends Jinja2’s import mechanism to allow direct use of arbitrary Python modules?
Here’s an example that creates tasks at start-up, to process each file in a directory:
$ ls /path/to/data/
cat dog fish
#!Jinja2
{# import Python's os module: #}
{% from "os" import listdir %}
{% set DATADIR = "/path/to/data" %}
[task parameters] {# use os.listdir() #}
id = {{ listdir(DATADIR) | join(", ") }}
[scheduling]
[[graph]]
R1 = "prep => proc<id> => results"
[runtime]
[[prep]]
# ...
[[proc<id>]]
script = """
do-something.py {{DATADIR}}/${CYLC_TASK_PARAM_id}
"""
[[results]]
# ...
Result after Jinja2 processing (use cylc view -j
):
[task parameters]
id = fish, cat, dog
[scheduling]
[[graph]]
R1 = "prep => proc<id> => results"
[runtime]
[[prep]]
# ...
[[proc<id>]]
script = """
do-something.py /path/to/data/${CYLC_TASK_PARAM_id}
"""
[[results]]
# ...
And (use cylc graph
):
Documented here in the User Guide: Jinja2 — Cylc 8.1.4 documentation