Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ def clean_up_fake_module(self, fake_mod_data):
# self.short_mod_name might not be set (e.g. during unit tests)
if fake_mod_path and self.short_mod_name is not None:
try:
self.modules_tool.unload([self.short_mod_name], silent=True)
self.modules_tool.unload([self.short_mod_name], log_changes=False)
self.modules_tool.remove_module_path(os.path.join(fake_mod_path, self.mod_subdir))
remove_dir(os.path.dirname(fake_mod_path))
except OSError as err:
Expand Down
12 changes: 6 additions & 6 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,12 +1121,12 @@ def load(self, modules, mod_paths=None, purge=False, init_env=None, allow_reload
if allow_reload or mod not in loaded_modules:
self.run_module('load', mod)

def unload(self, modules, silent=False):
def unload(self, modules, log_changes=True):
"""
Unload all requested modules.
"""
for mod in modules:
self.run_module('unload', mod, silent=silent)
self.run_module('unload', mod, log_changes=log_changes)

def purge(self):
"""
Expand Down Expand Up @@ -1189,9 +1189,9 @@ def modulefile_path(self, mod_name, strip_ext=False):

return modpath

def set_path_env_var(self, key, paths, silent=False):
def set_path_env_var(self, key, paths, log_changes=True):
"""Set path environment variable to the given list of paths."""
setvar(key, os.pathsep.join(paths), verbose=False, log_changes=not silent)
setvar(key, os.pathsep.join(paths), verbose=False, log_changes=log_changes)

def check_module_output(self, cmd, stdout, stderr):
"""Check output of 'module' command, see if if is potentially invalid."""
Expand Down Expand Up @@ -1250,13 +1250,13 @@ def run_module(self, *args, **kwargs):
self.log.debug("Changing %s from '%s' to '%s' in environment for module command",
key, old_value, new_value)

silent = kwargs.get('silent', False)
log_changes = kwargs.get('log_changes', True)
cmd_list = self.compose_cmd_list(args)
cmd = ' '.join(cmd_list)
# note: module commands are always run in dry mode, and are kept hidden in trace and dry run output
res = run_shell_cmd(cmd_list, env=environ, fail_on_error=False, use_bash=False, split_stderr=True,
hidden=True, in_dry_run=True, output_file=False,
hide_output_on_success=silent)
log_output_on_success=log_changes)

# stdout will contain python code (to change environment etc)
# stderr will contain text (just like the normal module command)
Expand Down
9 changes: 5 additions & 4 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def _answer_question(stdout, proc, qa_patterns, qa_wait_patterns):
def run_shell_cmd(cmd, fail_on_error=True, split_stderr=False, stdin=None, env=None,
hidden=False, in_dry_run=False, verbose_dry_run=False, work_dir=None, use_bash=True,
output_file=True, stream_output=None, asynchronous=False, task_id=None, with_hooks=True,
qa_patterns=None, qa_wait_patterns=None, qa_timeout=100, hide_output_on_success=False):
qa_patterns=None, qa_wait_patterns=None, qa_timeout=100, log_output_on_success=True):
"""
Run specified (interactive) shell command, and capture output + exit code.

Expand All @@ -381,6 +381,7 @@ def run_shell_cmd(cmd, fail_on_error=True, split_stderr=False, stdin=None, env=N
:param qa_patterns: list of 2-tuples with patterns for questions + corresponding answers
:param qa_wait_patterns: list of strings with patterns for non-questions
:param qa_timeout: amount of seconds to wait until more output is produced when there is no matching question
:param log_output_on_success: log output of command if it was successful

:return: Named tuple with:
- output: command output, stdout+stderr combined if split_stderr is disabled, only stdout otherwise
Expand Down Expand Up @@ -604,17 +605,17 @@ def to_cmd_str(cmd):
}
run_hook(RUN_SHELL_CMD, hooks, post_step_hook=True, args=[cmd], kwargs=run_hook_kwargs)

# always log command output
# log command output (unless command was successful and log_output_on_success is disabled)
cmd_name = cmd_str.split(' ')[0]
if split_stderr:
log_msg = f"Output of '{cmd_name} ...' shell command (stdout only):\n{res.output}\n"
log_msg = f"Output of '{cmd_name} ...' shell command (stdout only):\n{res.output}\n\n"
log_msg += f"Warnings and errors of '{cmd_name} ...' shell command (stderr only):\n{res.stderr}"
else:
log_msg = f"Output of '{cmd_name} ...' shell command (stdout + stderr):\n{res.output}"

if res.exit_code == EasyBuildExit.SUCCESS:
_log.info(f"Shell command completed successfully: {cmd_str}")
if not hide_output_on_success:
if log_output_on_success:
_log.info(log_msg)
else:
_log.warning(f"Shell command FAILED (exit code {res.exit_code}): {cmd_str}")
Expand Down
4 changes: 2 additions & 2 deletions test/framework/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def test_run_shell_cmd_log(self):
# command output can be suppressed
init_logging(logfile, silent=True)
with self.mocked_stdout_stderr():
res = run_shell_cmd("echo hello", hide_output_on_success=True)
res = run_shell_cmd("echo hello", log_output_on_success=False)
stop_logging(logfile)
self.assertEqual(res.exit_code, 0)
self.assertEqual(res.output, 'hello\n')
Expand All @@ -479,7 +479,7 @@ def test_run_shell_cmd_log(self):
# But is shown on error
init_logging(logfile, silent=True)
with self.mocked_stdout_stderr():
res = run_shell_cmd("echo hello && false", hide_output_on_success=True, fail_on_error=False)
res = run_shell_cmd("echo hello && false", log_output_on_success=False, fail_on_error=False)
stop_logging(logfile)
self.assertEqual(res.exit_code, 1)
self.assertEqual(res.output, 'hello\n')
Expand Down