Skip to content

Commit 7674b04

Browse files
committed
enh: test fs-license is a file on wrapper CLI
1 parent 312da4a commit 7674b04

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

wrapper/fmriprep_docker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def is_in_directory(filepath, directory):
225225
def get_parser():
226226
"""Defines the command line interface of the wrapper"""
227227
import argparse
228+
from functools import partial
228229

229230
class ToDict(argparse.Action):
230231
def __call__(self, parser, namespace, values, option_string=None):
@@ -234,11 +235,21 @@ def __call__(self, parser, namespace, values, option_string=None):
234235
d[k] = os.path.abspath(v)
235236
setattr(namespace, self.dest, d)
236237

238+
def _is_file(path, parser):
239+
"""Ensure a given path exists and it is a file."""
240+
if not os.path.isfile(path):
241+
raise parser.error(
242+
"Path should point to a file (or symlink of file): <%s>." % path
243+
)
244+
return path
245+
237246
parser = argparse.ArgumentParser(
238247
description=__doc__,
239248
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
240249
add_help=False)
241250

251+
IsFile = partial(_is_file, parser=parser)
252+
242253
# Standard FMRIPREP arguments
243254
parser.add_argument('bids_dir', nargs='?', type=os.path.abspath,
244255
default='')
@@ -279,7 +290,7 @@ def __call__(self, parser, namespace, values, option_string=None):
279290
', '.join(NONSTANDARD_REFERENCES)))
280291

281292
g_wrap.add_argument(
282-
'--fs-license-file', metavar='PATH', type=os.path.abspath,
293+
'--fs-license-file', metavar='PATH', type=IsFile,
283294
default=os.getenv('FS_LICENSE', None),
284295
help='Path to FreeSurfer license key file. Get it (for free) by registering'
285296
' at https://surfer.nmr.mgh.harvard.edu/registration.html')

0 commit comments

Comments
 (0)