Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename shell option in run_shell_cmd to use_bash #4378

Merged
merged 1 commit into from
Nov 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ def run_module(self, *args, **kwargs):
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, shell=False, split_stderr=True,
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)

# stdout will contain python code (to change environment etc)
Expand Down Expand Up @@ -1422,7 +1422,7 @@ def update(self):
cmd = ' '.join(cmd_list)
self.log.debug("Running command '%s'...", cmd)

res = run_shell_cmd(cmd_list, env=os.environ, fail_on_error=False, shell=False, split_stderr=True,
res = run_shell_cmd(cmd_list, env=os.environ, fail_on_error=False, use_bash=False, split_stderr=True,
hidden=True)
stdout, stderr = res.output, res.stderr

Expand Down
9 changes: 6 additions & 3 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def cache_aware_func(cmd, *args, **kwargs):

@run_shell_cmd_cache
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, shell=True,
hidden=False, in_dry_run=False, verbose_dry_run=False, work_dir=None, use_bash=True,
output_file=True, stream_output=False, asynchronous=False, with_hooks=True,
qa_patterns=None, qa_wait_patterns=None):
"""
Expand All @@ -194,7 +194,7 @@ def run_shell_cmd(cmd, fail_on_error=True, split_stderr=False, stdin=None, env=N
:param in_dry_run: also run command in dry run mode
:param verbose_dry_run: show that command is run in dry run mode (overrules 'hidden')
:param work_dir: working directory to run command in (current working directory if None)
:param shell: execute command through bash shell (enabled by default)
:param use_bash: execute command through bash shell (enabled by default)
:param output_file: collect command output in temporary output file
:param stream_output: stream command output to stdout
:param asynchronous: run command asynchronously
Expand Down Expand Up @@ -270,7 +270,10 @@ def to_cmd_str(cmd):
# use bash as shell instead of the default /bin/sh used by subprocess.run
# (which could be dash instead of bash, like on Ubuntu, see https://wiki.ubuntu.com/DashAsBinSh)
# stick to None (default value) when not running command via a shell
executable = '/bin/bash' if shell else None
if use_bash:
executable, shell = '/bin/bash', True
else:
executable, shell = None, False

stderr = subprocess.PIPE if split_stderr else subprocess.STDOUT

Expand Down
19 changes: 19 additions & 0 deletions test/framework/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,25 @@ def test_run_cmd_script(self):
self.assertEqual(ec, 0)
self.assertEqual(out, "hello\n")

def test_run_shell_cmd_no_bash(self):
"""Testing use of run_shell_cmd with use_bash=False to call external scripts"""
py_test_script = os.path.join(self.test_prefix, 'test.py')
write_file(py_test_script, '\n'.join([
'#!%s' % sys.executable,
'print("hello")',
]))
adjust_permissions(py_test_script, stat.S_IXUSR)

with self.mocked_stdout_stderr():
res = run_shell_cmd(py_test_script)
self.assertEqual(res.exit_code, 0)
self.assertEqual(res.output, "hello\n")

with self.mocked_stdout_stderr():
res = run_shell_cmd([py_test_script], use_bash=False)
self.assertEqual(res.exit_code, 0)
self.assertEqual(res.output, "hello\n")

def test_run_cmd_stream(self):
"""Test use of run_cmd with streaming output."""
self.mock_stdout(True)
Expand Down