Skip to content

Commit d0defe3

Browse files
committed
TEST/RF: Check modified command + helper command
1 parent c1a71f3 commit d0defe3

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

nipype/interfaces/base/core.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -988,14 +988,26 @@ def _run_interface(self, runtime, correct_return_codes=(0, )):
988988

989989
# which $cmd
990990
executable_name = self.cmd.split()[0]
991-
cmd_path = which(executable_name, env=runtime.environ)
991+
992+
prefix_parts = self._cmd_prefix.split()
993+
r_pre = prefix_parts.pop() if prefix_parts else ''
994+
995+
cmd_path = which(r_pre + executable_name, env=runtime.environ)
992996

993997
if cmd_path is None:
994998
raise IOError(
995999
'No command "%s" found on host %s. Please check that the '
9961000
'corresponding package is installed.' % (executable_name,
9971001
runtime.hostname))
9981002

1003+
if prefix_parts:
1004+
helper_command = which(prefix_parts[0], env=runtime.environ)
1005+
if helper_command is None:
1006+
raise IOError(
1007+
'No command "%s" found on host %s. Please check that the '
1008+
'corresponding package is installed.' % (helper_command,
1009+
runtime.hostname))
1010+
9991011
runtime.command_path = cmd_path
10001012
runtime.dependencies = (get_dependencies(executable_name,
10011013
runtime.environ)

nipype/interfaces/base/tests/test_core.py

+35
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,38 @@ def test_global_CommandLine_output(tmpdir):
480480
# Check default affects derived interfaces
481481
ci = BET()
482482
assert ci.terminal_output == 'file'
483+
484+
485+
def test_CommandLine_prefix(tmpdir):
486+
tmpdir.chdir()
487+
oop = 'out/of/path'
488+
os.makedirs(oop)
489+
490+
script_name = 'test_script.sh'
491+
script_path = os.path.join(oop, script_name)
492+
with open(script_path, 'w') as script_f:
493+
script_f.write('#!/usr/bin/env bash\necho Success!')
494+
os.chmod(script_path, mode=0o755)
495+
496+
ci = nib.CommandLine(command=script_name)
497+
with pytest.raises(OSError):
498+
ci.run()
499+
500+
class OOPCLI(nib.CommandLine):
501+
_cmd_prefix = oop + '/'
502+
503+
ci = OOPCLI(command=script_name)
504+
ci.run()
505+
506+
class OOPShell(nib.CommandLine):
507+
_cmd_prefix = 'bash {}/'.format(oop)
508+
509+
ci = OOPShell(command=script_name)
510+
ci.run()
511+
512+
class OOPBadShell(nib.CommandLine):
513+
_cmd_prefix = 'shell_dne {}/'.format(oop)
514+
515+
ci = OOPBadShell(command=script_name)
516+
with pytest.raises(OSError):
517+
ci.run()

0 commit comments

Comments
 (0)