Skip to content

Commit 3269897

Browse files
Explain code in flow.cylc files. (#651)
Explain code in flow.cylc files. --------- Co-authored-by: Oliver Sanders <[email protected]>
1 parent 68a4cd1 commit 3269897

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/dictionaries/words

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ premption
120120
prepackaged
121121
prepend
122122
prepended
123+
preprocessing
123124
preset
124125
proc
125126
programmatically

src/user-guide/writing-workflows/configuration.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,50 @@ documentation, configuration files, etc. When the workflow is :ref:`installed
6262
equivalent directories in the :ref:`workflow_share_directories`.
6363

6464

65+
.. _UnderstandingCodeInCylcConfigurations:
66+
67+
Understanding Code in Workflow Configurations
68+
---------------------------------------------
69+
70+
A workflow configuration is not executable code. It configures the scheduler
71+
program to run your workflow. A `flow.cylc` file may contain:
72+
73+
- Embedded Python-like Jinja2 or EmPy templating code, such as
74+
``{% set PLANET = "earth" %}``
75+
- Bash shell variable assignments and scripting, such as
76+
``script = "run-model.exe /path/to/data"``
77+
78+
Jinja2 (or EmPy) templating code gets executed as a preprocessing step, to
79+
programmatically generate the workflow configuration for the scheduler.
80+
To see the result after template processing:
81+
82+
.. code-block:: shell
83+
84+
# print the workflow configuration, processed but not parsed:
85+
$ cylc view --process <workflow-id>
86+
87+
# print the workflow configuration, processed and parsed:
88+
$ cylc config <workflow-id>
89+
90+
91+
The scheduler does not interpret shell syntax, but certain string-valued
92+
config items may contain shell code that gets written verbatim to job scripts,
93+
to be executed by the running job.
94+
95+
Some things to be aware of:
96+
97+
- Jinja2 code is evaluated once when the workflow is started.
98+
- Jinja2 code can only reference Jinja2 variables, not Cylc config items.
99+
- Jinja2 (like Python) has its own syntax for reading environment variables.
100+
- Jinja2 code that reads the environment or the filesystem will do so
101+
during config file parsing on the scheduler run host, not on job hosts.
102+
Beware of doing this in task definitions - do you want the scheduler
103+
environment to affect shell code that runs in the job environment?
104+
- Shell code destined for the job script can read the environment or
105+
access the filesystem as the job runs on the job host, not on the
106+
scheduler host.
107+
108+
65109
.. _SyntaxHighlighting:
66110

67111
Syntax Highlighting For Workflow Configuration

0 commit comments

Comments
 (0)