Skip to content

Commit 1b47e55

Browse files
authored
Merge pull request #1044 from effigies/cli/check_deps
[ENH] Check CommandLine dependencies before running
2 parents d73ba9d + eb42339 commit 1b47e55

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

fmriprep/cli/run.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ def _warn_redirect(message, category, filename, lineno, file=None, line=None):
3030
logger.warning('Captured warning (%s): %s', category, message)
3131

3232

33+
def check_deps(workflow):
34+
from nipype.utils.filemanip import which
35+
return sorted(
36+
(node.interface.__class__.__name__, node.interface._cmd)
37+
for node in workflow._get_all_nodes()
38+
if (hasattr(node.interface, '_cmd') and
39+
which(node.interface._cmd) is None))
40+
41+
3342
def get_parser():
3443
"""Build parser object"""
3544
from ..info import __version__
@@ -310,6 +319,14 @@ def main():
310319
except Exception:
311320
pass
312321

322+
# Check workflow for missing commands
323+
missing = check_deps(fmriprep_wf)
324+
if missing:
325+
print("Cannot run fMRIPrep. Missing dependencies:")
326+
for iface, cmd in missing:
327+
print("\t{} (Interface: {})".format(cmd, iface))
328+
sys.exit(2)
329+
313330
# Clean up master process before running workflow, which may create forks
314331
gc.collect()
315332
try:

0 commit comments

Comments
 (0)