Skip to content

Commit db15507

Browse files
authored
Update script item style reccommendations (#392)
Update script item style reccommendations
1 parent 254faf6 commit db15507

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

src/workflow-design-guide/style-guide.rst

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,45 +92,47 @@ to, and trailing comments should be preceded by two spaces, as shown above.
9292
Script String Lines
9393
^^^^^^^^^^^^^^^^^^^
9494

95-
Script strings are written verbatim to task job scripts so they should really
96-
be indented from the left margin:
95+
Script strings are written verbatim to task job scripts.
96+
97+
.. code-block:: cylc
98+
99+
[runtime]
100+
[[foo]]
101+
script = echo "Hello, Mr. Thompson"
102+
103+
If using a triple-quoted string, any common leading whitespace is trimmed
104+
using the logic of :py:func:`textwrap.dedent`. As such, it is recommended to
105+
indent like any other triple-quoted string setting in Cylc:
97106

98107
.. code-block:: cylc
99108
100109
[runtime]
101110
[[foo]]
102111
# Recommended.
103-
post-script = """
104-
if [[ $RESULT == "bad" ]]; then
105-
echo Goodbye World!
112+
script = """
113+
if [[ "$RESULT" == "bad" ]]; then
114+
echo "Goodbye World!"
106115
exit 1
107116
fi
108117
"""
109118
110-
Indentation is *mostly* ignored by the bash interpreter, but is useful for
111-
readability. It is *mostly* harmless to indent internal script lines as if
112-
part of the Cylc syntax, or even out to the triple quotes:
119+
The example above would result in the following being written to the job
120+
script:
113121

114-
.. code-block:: cylc
122+
.. code-block:: bash
115123
116-
[runtime]
117-
[[foo]]
118-
# OK, but...
119-
post-script = """if [[ $RESULT == "bad" ]]; then
120-
echo Goodbye World!
121-
exit 1
122-
fi"""
124+
if [[ "$RESULT" == "bad" ]]; then
125+
echo "Goodbye World!"
126+
exit 1
127+
fi
123128
124-
On parsing the triple quoted value, Cylc will remove any common leading
125-
whitespace from each line using the logic of
126-
`Python's textwrap.dedent <https://docs.python.org/2/library/textwrap.html#textwrap.dedent>`_
127-
so the script block would end up being the same as the previous example.
128-
However, you should watch your line length (see :ref:`Line Length`) when you
129-
have many levels of indentations.
129+
.. tip::
130130

131-
.. note::
131+
Take care when indenting here documents (aka heredocs) to match the
132+
common leading whitespace.
132133

133-
Take care when indenting here documents:
134+
For the following example, each line in ``log.txt`` would end up with
135+
4 leading white spaces:
134136

135137
.. code-block:: cylc
136138
@@ -143,8 +145,7 @@ have many levels of indentations.
143145
_EOF_
144146
"""
145147
146-
Each line in ``log.txt`` would end up with 4 leading white spaces. The
147-
following will give you lines with no white spaces.
148+
The following will give you lines with no white spaces:
148149

149150
.. code-block:: cylc
150151

0 commit comments

Comments
 (0)