Skip to content

Commit efa42df

Browse files
committed
FIX: fMRIPrep crashes whenever FREESURFER_HOME is not set
Fixes #2013.
1 parent 2cf3e49 commit efa42df

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

fmriprep/cli/run.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,23 @@ def main():
316316
"cases).")
317317
validate_input_dir(exec_env, opts.bids_dir, opts.participant_label)
318318

319-
# FreeSurfer license
320-
default_license = str(Path(os.getenv('FREESURFER_HOME')) / 'license.txt')
321319
# Precedence: --fs-license-file, $FS_LICENSE, default_license
322-
license_file = opts.fs_license_file or Path(os.getenv('FS_LICENSE', default_license))
323-
if not license_file.exists():
320+
license_file = opts.fs_license_file
321+
322+
if license_file is None and os.getenv("FS_LICENSE"):
323+
license_file = Path(os.getenv("FS_LICENSE"))
324+
325+
if license_file is None and os.getenv("FREESURFER_HOME"):
326+
license_file = Path(os.getenv("FREESURFER_HOME")) / "license.txt"
327+
328+
# FreeSurfer license
329+
if license_file is None or not license_file.exists():
324330
raise RuntimeError("""\
325331
ERROR: a valid license file is required for FreeSurfer to run. fMRIPrep looked for an existing \
326332
license file at several paths, in this order: 1) command line argument ``--fs-license-file``; \
327333
2) ``$FS_LICENSE`` environment variable; and 3) the ``$FREESURFER_HOME/license.txt`` path. Get it \
328334
(for free) by registering at https://surfer.nmr.mgh.harvard.edu/registration.html""")
329-
os.environ['FS_LICENSE'] = str(license_file.resolve())
335+
os.environ["FS_LICENSE"] = str(license_file.absolute())
330336

331337
# Retrieve logging level
332338
log_level = int(max(25 - 5 * opts.verbose_count, logging.DEBUG))

0 commit comments

Comments
 (0)