Skip to content

Commit 8cde742

Browse files
committed
FIX: Changes the implementation for checking the environemntal variables so that it doesn't produce an error (just a warning) when testing without freesurfer.
1 parent b54c79f commit 8cde742

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

nipype/workflows/smri/freesurfer/recon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def checkarg(arg, default):
159159
return arg
160160
else:
161161
return default
162-
defaultconfig = getdefaultconfig()
162+
defaultconfig = getdefaultconfig(exitonfail=True)
163163
# set the default template and classifier files
164164
reg_template = checkarg(reg_template, defaultconfig['registration_template'])
165165
reg_template_withskull = checkarg(reg_template_withskull,

nipype/workflows/smri/freesurfer/utils.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ def mkdir_p(path):
420420
else:
421421
raise
422422

423-
def getdefaultconfig():
423+
def getdefaultconfig(exitonfail=False):
424424
config = { 'custom_atlas' : None,
425425
'cw256' : False,
426426
'field_strength' : '1.5T',
427-
'fs_home' : checkenv(),
427+
'fs_home' : checkenv(exitonfail),
428428
'longitudinal' : False,
429429
'long_base' : None,
430430
'openmp' : None,
@@ -463,31 +463,35 @@ def getdefaultconfig():
463463
return config
464464

465465

466-
def checkenv():
467-
import sys
466+
def checkenv(exitonfail=False):
468467
"""Check for the necessary FS environment variables"""
468+
import sys
469469
fs_home = os.environ.get('FREESURFER_HOME')
470470
path = os.environ.get('PATH')
471471
print("FREESURFER_HOME: {0}".format(fs_home))
472472
if fs_home == None:
473-
print("ERROR: please set FREESURFER_HOME before running the workflow")
473+
msg = "please set FREESURFER_HOME before running the workflow"
474474
elif not os.path.isdir(fs_home):
475-
print("ERROR: FREESURFER_HOME must be set to a valid directory before " +
476-
"running this workflow")
475+
msg = "FREESURFER_HOME must be set to a valid directory before running this workflow"
477476
elif os.path.join(fs_home, 'bin') not in path.replace('//','/'):
478477
print(path)
479-
print("ERROR: Could not find necessary executable in path")
478+
msg = "Could not find necessary executable in path"
480479
setupscript = os.path.join(fs_home, 'SetUpFreeSurfer.sh')
481480
if os.path.isfile(setupscript):
482481
print("Please source the setup script before running the workflow:" +
483-
"\nsource {0}".format(setupscript))
482+
"\nsource {0}".format(setupscript))
484483
else:
485484
print("Please ensure that FREESURFER_HOME is set to a valid fs " +
486485
"directory and source the necessary SetUpFreeSurfer.sh script before running " +
487486
"this workflow")
488487
else:
489488
return fs_home
490-
sys.exit(2)
489+
490+
if exitonfail:
491+
print("ERROR: " + msg)
492+
sys.exit(2)
493+
else:
494+
print("Warning: " + msg)
491495

492496
def center_volume(in_file):
493497
import SimpleITK as sitk

0 commit comments

Comments
 (0)