Skip to content

Commit 0c5b68b

Browse files
committed
CLI: Check CommandLine dependencies before running
1 parent 5562313 commit 0c5b68b

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 niworkflows.nipype.filemanip import which
35+
return sorted(
36+
(node.interface.__class__.__name__, node.interface._cmd)
37+
for node in workflow.get_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__
@@ -268,6 +277,14 @@ def main():
268277
if opts.reports_only:
269278
sys.exit(int(retcode > 0))
270279

280+
# Check workflow for missing commands
281+
missing = check_deps(fmriprep_wf)
282+
if missing:
283+
print("Cannot run fMRIPrep. Missing dependencies:")
284+
for iface, cmd in missing:
285+
print("\t{} (Interface: {})".format(cmd, iface))
286+
sys.exit(2)
287+
271288
# Clean up master process before running workflow, which may create forks
272289
gc.collect()
273290
try:

0 commit comments

Comments
 (0)