Skip to content

Commit 03b2dde

Browse files
authored
Merge pull request #6848 from MetRonnie/platform-subshell
Allow platform setting to have prefix/suffix around subshell
1 parent e770f48 commit 03b2dde

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

changes.d/6848.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow `flow.cylc[runtime][<task>]platform` setting to have a prefix/suffix around a subshell expression.

cylc/flow/cfgspec/workflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ def get_script_common_text(this: str, example: Optional[str] = None):
12111211
12121212
# run a command to select the platform (or platform group):
12131213
platform = $(select-platform)
1214+
platform = prefix-$(select-platform)-suffix
12141215
12151216
.. versionadded:: 8.0.0
12161217
''')

cylc/flow/platforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
# Regex to check whether a string is a command
5959
HOST_REC_COMMAND = re.compile(r'(`|\$\()\s*(.*)\s*([`)])$')
60-
PLATFORM_REC_COMMAND = re.compile(r'(\$\()\s*(.*)\s*([)])$')
60+
PLATFORM_REC_COMMAND = re.compile(r'(\$\()\s*(.*)\s*(\))')
6161

6262
HOST_SELECTION_METHODS = {
6363
'definition order': lambda goodhosts: goodhosts[0],

cylc/flow/task_remote_mgr.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,18 @@ def _subshell_eval(
143143
return 'localhost'
144144

145145
# Host selection command: $(command) or `command`
146-
match = command_pattern.match(eval_str)
146+
match = command_pattern.search(eval_str)
147147
if match:
148-
cmd_str = match.groups()[1]
148+
cmd_str = match.group(2)
149149
if cmd_str in self.remote_command_map:
150150
# Command recently launched
151151
value = self.remote_command_map[cmd_str]
152152
if isinstance(value, PlatformError):
153153
raise value # command failed
154154
if value is None:
155155
return None # command not yet ready
156-
eval_str = value # command succeeded
156+
# command succeeded
157+
eval_str = eval_str.replace(match.group(0), value)
157158
else:
158159
# Command not launched (or already reset)
159160
self.proc_pool.put_command(

tests/functional/job-submission/19-platform_select.t

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#-------------------------------------------------------------------------------
1818
# Test recovery of a failed host select command for a group of tasks.
1919
. "$(dirname "$0")/test_header"
20-
set_test_number 6
20+
set_test_number 7
2121

2222
install_workflow "${TEST_NAME_BASE}"
2323

@@ -29,20 +29,24 @@ logfile="${WORKFLOW_RUN_DIR}/log/scheduler/log"
2929

3030
# Check that host = $(cmd) is correctly evaluated
3131
grep_ok \
32-
"1/host_subshell.* evaluated as improbable host name$" \
32+
"1/host_subshell/01:.* evaluated as improbable host name$" \
3333
"${logfile}"
3434
grep_ok \
35-
"1/localhost_subshell.* evaluated as localhost$" \
35+
"1/localhost_subshell/01:.* evaluated as localhost$" \
3636
"${logfile}"
3737

3838
# Check that host = `cmd` is correctly evaluated
3939
grep_ok \
40-
"1/host_subshell_backticks.* evaluated as improbable host name$" \
40+
"1/host_subshell_backticks/01:.* evaluated as improbable host name$" \
4141
"${logfile}"
4242

4343
# Check that platform = $(cmd) correctly evaluated
4444
grep_ok \
45-
"1/platform_subshell.* evaluated as improbable platform name$" \
45+
"1/platform_subshell:.* evaluated as improbable platform name$" \
46+
"${logfile}"
47+
48+
grep_ok \
49+
"1/platform_subshell_suffix:.* evaluated as prefix-middle-suffix$" \
4650
"${logfile}"
4751

4852
purge

tests/functional/job-submission/19-platform_select/flow.cylc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ purpose = """
1515
R1 = """
1616
host_no_subshell
1717
localhost_subshell
18-
platform_subshell:submit-fail? => fin_platform
19-
platform_no_subshell:submit-fail? => fin_platform
20-
host_subshell:submit-fail? => fin_host
21-
host_subshell_backticks:submit-fail? => fin_host
18+
platform_subshell:submit-fail?
19+
platform_no_subshell:submit-fail?
20+
platform_subshell_suffix:submit-fail?
21+
host_subshell:submit-fail?
22+
host_subshell_backticks:submit-fail?
2223
"""
2324

2425
[runtime]
@@ -35,6 +36,9 @@ purpose = """
3536
[[platform_subshell]]
3637
platform = $(echo "improbable platform name")
3738

39+
[[platform_subshell_suffix]]
40+
platform = prefix-$( echo middle )-suffix
41+
3842
[[host_subshell]]
3943
[[[remote]]]
4044
host = $(echo "improbable host name")
@@ -46,9 +50,3 @@ purpose = """
4650
[[localhost_subshell]]
4751
[[[remote]]]
4852
host = $(echo "localhost4.localdomain4")
49-
50-
[[fin_platform]]
51-
script = cylc remove "${CYLC_WORKFLOW_ID}//1/platform_*"
52-
53-
[[fin_host]]
54-
script = cylc remove "${CYLC_WORKFLOW_ID}//1/host_subshell*"

tests/functional/job-submission/19-platform_select/reference.log

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
1/host_subshell -triggered off [] in flow 1
55
1/host_subshell_backticks -triggered off [] in flow 1
66
1/localhost_subshell -triggered off [] in flow 1
7-
1/fin_platform -triggered off ['1/platform_no_subshell', '1/platform_subshell'] in flow 1
8-
1/fin_host -triggered off ['1/host_subshell', '1/host_subshell_backticks'] in flow 1
7+
1/platform_subshell_suffix -triggered off [] in flow 1

tests/unit/test_platforms_get_platform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def test_get_platform_groups_basic(mock_glbl_cfg):
272272
'task_conf, expected_err_msg',
273273
[
274274
({'platform': '$(host)'}, None),
275+
({'platform': '$(host)-suffix'}, None),
275276
({'platform': '`echo ${chamber}`'}, "backticks are not supported")
276277
]
277278
)

0 commit comments

Comments
 (0)