Skip to content

Commit 86ed634

Browse files
authored
Merge pull request #4378 from boegel/run_shell_cmd_use_bash
rename `shell` option in `run_shell_cmd` to `use_bash`
2 parents 6b09872 + 534b029 commit 86ed634

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

easybuild/tools/modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def run_module(self, *args, **kwargs):
820820
cmd_list = self.compose_cmd_list(args)
821821
cmd = ' '.join(cmd_list)
822822
# note: module commands are always run in dry mode, and are kept hidden in trace and dry run output
823-
res = run_shell_cmd(cmd_list, env=environ, fail_on_error=False, shell=False, split_stderr=True,
823+
res = run_shell_cmd(cmd_list, env=environ, fail_on_error=False, use_bash=False, split_stderr=True,
824824
hidden=True, in_dry_run=True, output_file=False)
825825

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

1425-
res = run_shell_cmd(cmd_list, env=os.environ, fail_on_error=False, shell=False, split_stderr=True,
1425+
res = run_shell_cmd(cmd_list, env=os.environ, fail_on_error=False, use_bash=False, split_stderr=True,
14261426
hidden=True)
14271427
stdout, stderr = res.output, res.stderr
14281428

easybuild/tools/run.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def cache_aware_func(cmd, *args, **kwargs):
180180

181181
@run_shell_cmd_cache
182182
def run_shell_cmd(cmd, fail_on_error=True, split_stderr=False, stdin=None, env=None,
183-
hidden=False, in_dry_run=False, verbose_dry_run=False, work_dir=None, shell=True,
183+
hidden=False, in_dry_run=False, verbose_dry_run=False, work_dir=None, use_bash=True,
184184
output_file=True, stream_output=False, asynchronous=False, with_hooks=True,
185185
qa_patterns=None, qa_wait_patterns=None):
186186
"""
@@ -194,7 +194,7 @@ def run_shell_cmd(cmd, fail_on_error=True, split_stderr=False, stdin=None, env=N
194194
:param in_dry_run: also run command in dry run mode
195195
:param verbose_dry_run: show that command is run in dry run mode (overrules 'hidden')
196196
:param work_dir: working directory to run command in (current working directory if None)
197-
:param shell: execute command through bash shell (enabled by default)
197+
:param use_bash: execute command through bash shell (enabled by default)
198198
:param output_file: collect command output in temporary output file
199199
:param stream_output: stream command output to stdout
200200
:param asynchronous: run command asynchronously
@@ -270,7 +270,10 @@ def to_cmd_str(cmd):
270270
# use bash as shell instead of the default /bin/sh used by subprocess.run
271271
# (which could be dash instead of bash, like on Ubuntu, see https://wiki.ubuntu.com/DashAsBinSh)
272272
# stick to None (default value) when not running command via a shell
273-
executable = '/bin/bash' if shell else None
273+
if use_bash:
274+
executable, shell = '/bin/bash', True
275+
else:
276+
executable, shell = None, False
274277

275278
stderr = subprocess.PIPE if split_stderr else subprocess.STDOUT
276279

test/framework/run.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,25 @@ def test_run_cmd_script(self):
10661066
self.assertEqual(ec, 0)
10671067
self.assertEqual(out, "hello\n")
10681068

1069+
def test_run_shell_cmd_no_bash(self):
1070+
"""Testing use of run_shell_cmd with use_bash=False to call external scripts"""
1071+
py_test_script = os.path.join(self.test_prefix, 'test.py')
1072+
write_file(py_test_script, '\n'.join([
1073+
'#!%s' % sys.executable,
1074+
'print("hello")',
1075+
]))
1076+
adjust_permissions(py_test_script, stat.S_IXUSR)
1077+
1078+
with self.mocked_stdout_stderr():
1079+
res = run_shell_cmd(py_test_script)
1080+
self.assertEqual(res.exit_code, 0)
1081+
self.assertEqual(res.output, "hello\n")
1082+
1083+
with self.mocked_stdout_stderr():
1084+
res = run_shell_cmd([py_test_script], use_bash=False)
1085+
self.assertEqual(res.exit_code, 0)
1086+
self.assertEqual(res.output, "hello\n")
1087+
10691088
def test_run_cmd_stream(self):
10701089
"""Test use of run_cmd with streaming output."""
10711090
self.mock_stdout(True)

0 commit comments

Comments
 (0)