Skip to content

Commit 5375f36

Browse files
committed
[ENH] Memoize FSL version check
Same as in #2274, but for FSL
1 parent 1b05497 commit 5375f36

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

nipype/interfaces/fsl/base.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,41 @@
3333

3434
from ... import logging
3535
from ...utils.filemanip import fname_presuffix
36-
from ..base import traits, isdefined, CommandLine, CommandLineInputSpec
36+
from ..base import traits, isdefined, CommandLine, CommandLineInputSpec, PackageInfo
3737
from ...external.due import BibTeX
3838

3939
IFLOGGER = logging.getLogger('interface')
4040

4141

42-
class Info(object):
43-
"""Handle fsl output type and version information.
44-
45-
version refers to the version of fsl on the system
42+
class Info(PackageInfo):
43+
"""
44+
Handle FSL ``output_type`` and version information.
4645
4746
output type refers to the type of file fsl defaults to writing
4847
eg, NIFTI, NIFTI_GZ
4948
49+
Examples
50+
--------
51+
52+
>>> from nipype.interfaces.fsl import Info
53+
>>> Info.version() # doctest: +SKIP
54+
>>> Info.output_type() # doctest: +SKIP
55+
56+
5057
"""
5158

5259
ftypes = {'NIFTI': '.nii',
5360
'NIFTI_PAIR': '.img',
5461
'NIFTI_GZ': '.nii.gz',
5562
'NIFTI_PAIR_GZ': '.img.gz'}
5663

57-
@staticmethod
58-
def version():
59-
"""Check for fsl version on system
60-
61-
Parameters
62-
----------
63-
None
64+
if os.getenv('FSLDIR'):
65+
version_file = os.path.join(
66+
os.getenv('FSLDIR'), 'etc', 'fslversion')
6467

65-
Returns
66-
-------
67-
version : str
68-
Version number as string or None if FSL not found
68+
def parse_version(raw_info):
69+
return raw_info.splitlines()[0]
6970

70-
"""
71-
# find which fsl being used....and get version from
72-
# /path/to/fsl/etc/fslversion
73-
try:
74-
basedir = os.environ['FSLDIR']
75-
except KeyError:
76-
return None
77-
out = open('%s/etc/fslversion' % (basedir)).read()
78-
return out.strip('\n')
7971

8072
@classmethod
8173
def output_type_to_ext(cls, output_type):

0 commit comments

Comments
 (0)