Skip to content

Commit b2b9c54

Browse files
authored
Merge pull request #4911 from boegel/fail_on_error_hidden_post_run_shell_cmd_hook
also pass value of `fail_on_error` and `hidden` options of `run_shell_cmd` call down to pre/post `run_shell_cmd` hook
2 parents 8dd59f2 + 0ba881e commit b2b9c54

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

easybuild/tools/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ def to_cmd_str(cmd):
424424
kwargs = {
425425
'interactive': interactive,
426426
'work_dir': work_dir,
427+
'fail_on_error': fail_on_error,
428+
'hidden': hidden,
427429
}
428430
hook_res = run_hook(RUN_SHELL_CMD, hooks, pre_step_hook=True, args=[cmd], kwargs=kwargs)
429431
if hook_res:
@@ -597,6 +599,8 @@ def to_cmd_str(cmd):
597599
'stderr': res.stderr,
598600
'work_dir': res.work_dir,
599601
'shell_cmd_result': res,
602+
'fail_on_error': fail_on_error,
603+
'hidden': hidden,
600604
}
601605
run_hook(RUN_SHELL_CMD, hooks, post_step_hook=True, args=[cmd], kwargs=run_hook_kwargs)
602606

test/framework/run.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,8 @@ def pre_run_shell_cmd_hook(cmd, *args, **kwargs):
20682068
print("pre-run hook '%s' in %s" % (cmd, work_dir))
20692069
import sys
20702070
sys.stderr.write('pre-run hook done\\n')
2071+
print("command is allowed to fail: %s" % kwargs.get('fail_on_error', 'NOT AVAILABLE'))
2072+
print("command is hidden: %s" % kwargs.get('hidden', 'NOT AVAILABLE'))
20712073
if cmd != 'false' and not cmd.startswith('echo'):
20722074
cmds = cmd.split(';')
20732075
return '; '.join(cmds[:-1] + ["echo " + cmds[-1].lstrip()])
@@ -2081,6 +2083,8 @@ def post_run_shell_cmd_hook(cmd, *args, **kwargs):
20812083
else:
20822084
msg = "post-run hook '%s'" % cmd
20832085
msg += " (exit code: %s, output: '%s')" % (exit_code, output)
2086+
msg += "\\ncommand was allowed to fail: %s" % kwargs.get('fail_on_error', 'NOT AVAILABLE')
2087+
msg += "\\ncommand was hidden: %s" % kwargs.get('hidden', 'NOT AVAILABLE')
20842088
print(msg)
20852089
""")
20862090
write_file(hooks_file, hooks_file_txt)
@@ -2095,7 +2099,11 @@ def post_run_shell_cmd_hook(cmd, *args, **kwargs):
20952099

20962100
expected_stdout = '\n'.join([
20972101
f"pre-run hook 'make' in {cwd}",
2102+
"command is allowed to fail: True",
2103+
"command is hidden: False",
20982104
"post-run hook 'echo make' (exit code: 0, output: 'make\n')",
2105+
"command was allowed to fail: True",
2106+
"command was hidden: False",
20992107
'',
21002108
])
21012109
self.assertEqual(stdout, expected_stdout)
@@ -2109,6 +2117,8 @@ def post_run_shell_cmd_hook(cmd, *args, **kwargs):
21092117

21102118
expected_stdout = '\n'.join([
21112119
"pre-run hook 'make' in %s" % cwd,
2120+
"command is allowed to fail: True",
2121+
"command is hidden: False",
21122122
' running shell command "echo make"',
21132123
' (in %s)' % cwd,
21142124
'',
@@ -2135,8 +2145,14 @@ def post_run_shell_cmd_hook(cmd, *args, **kwargs):
21352145
pass
21362146
stdout = self.get_stdout()
21372147

2138-
expected_last_line = "\npost-run hook 'false' (exit code: 1, output: '')\n"
2139-
self.assertTrue(stdout.endswith(expected_last_line), f"Stdout should end with '{expected_last_line}': {stdout}")
2148+
expected_end = '\n'.join([
2149+
'',
2150+
"post-run hook 'false' (exit code: 1, output: '')",
2151+
"command was allowed to fail: True",
2152+
"command was hidden: False",
2153+
'',
2154+
])
2155+
self.assertTrue(stdout.endswith(expected_end), f"Stdout should end with '{expected_end}': {stdout}")
21402156

21412157
def test_run_shell_cmd_delete_cwd(self):
21422158
"""

0 commit comments

Comments
 (0)