From 5375f36c0dd120e8a872f29eee4dd541591a54f8 Mon Sep 17 00:00:00 2001 From: oesteban Date: Tue, 21 Nov 2017 13:19:54 -0800 Subject: [PATCH 1/4] [ENH] Memoize FSL version check Same as in #2274, but for FSL --- nipype/interfaces/fsl/base.py | 42 ++++++++++++++--------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/nipype/interfaces/fsl/base.py b/nipype/interfaces/fsl/base.py index 6d16817e09..21ac707495 100644 --- a/nipype/interfaces/fsl/base.py +++ b/nipype/interfaces/fsl/base.py @@ -33,20 +33,27 @@ from ... import logging from ...utils.filemanip import fname_presuffix -from ..base import traits, isdefined, CommandLine, CommandLineInputSpec +from ..base import traits, isdefined, CommandLine, CommandLineInputSpec, PackageInfo from ...external.due import BibTeX IFLOGGER = logging.getLogger('interface') -class Info(object): - """Handle fsl output type and version information. - - version refers to the version of fsl on the system +class Info(PackageInfo): + """ + Handle FSL ``output_type`` and version information. output type refers to the type of file fsl defaults to writing eg, NIFTI, NIFTI_GZ + Examples + -------- + + >>> from nipype.interfaces.fsl import Info + >>> Info.version() # doctest: +SKIP + >>> Info.output_type() # doctest: +SKIP + + """ ftypes = {'NIFTI': '.nii', @@ -54,28 +61,13 @@ class Info(object): 'NIFTI_GZ': '.nii.gz', 'NIFTI_PAIR_GZ': '.img.gz'} - @staticmethod - def version(): - """Check for fsl version on system - - Parameters - ---------- - None + if os.getenv('FSLDIR'): + version_file = os.path.join( + os.getenv('FSLDIR'), 'etc', 'fslversion') - Returns - ------- - version : str - Version number as string or None if FSL not found + def parse_version(raw_info): + return raw_info.splitlines()[0] - """ - # find which fsl being used....and get version from - # /path/to/fsl/etc/fslversion - try: - basedir = os.environ['FSLDIR'] - except KeyError: - return None - out = open('%s/etc/fslversion' % (basedir)).read() - return out.strip('\n') @classmethod def output_type_to_ext(cls, output_type): From bd086f9dbc873dff776b8079647e805083ac65ff Mon Sep 17 00:00:00 2001 From: oesteban Date: Tue, 21 Nov 2017 13:24:21 -0800 Subject: [PATCH 2/4] remove unused packages --- nipype/interfaces/fsl/base.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/nipype/interfaces/fsl/base.py b/nipype/interfaces/fsl/base.py index 21ac707495..513612fb50 100644 --- a/nipype/interfaces/fsl/base.py +++ b/nipype/interfaces/fsl/base.py @@ -26,7 +26,6 @@ """ from __future__ import print_function, division, unicode_literals, absolute_import -from builtins import open, object from glob import glob import os @@ -68,7 +67,6 @@ class Info(PackageInfo): def parse_version(raw_info): return raw_info.splitlines()[0] - @classmethod def output_type_to_ext(cls, output_type): """Get the file extension for the given output type. From 3d132465c988cd4740f4cf3255c1256bbbafb36a Mon Sep 17 00:00:00 2001 From: oesteban Date: Tue, 21 Nov 2017 13:27:32 -0800 Subject: [PATCH 3/4] Update CHANGES --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index f7761f7b91..88238aa8c8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ Upcoming release (0.14.0) ================ +* ENH: Memoize version checks (https://github.com/nipy/nipype/pull/2274, https://github.com/nipy/nipype/pull/2295) * FIX: Testing maintainance and improvements (https://github.com/nipy/nipype/pull/2252) * ENH: Add elapsed_time and final metric_value to ants.Registration (https://github.com/nipy/nipype/pull/1985) * ENH: Improve terminal_output feature (https://github.com/nipy/nipype/pull/2209) From 48117bccdacdab9ff45737e5ce016444710e8acf Mon Sep 17 00:00:00 2001 From: oesteban Date: Tue, 21 Nov 2017 17:21:36 -0800 Subject: [PATCH 4/4] parse_version should be static --- nipype/interfaces/fsl/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nipype/interfaces/fsl/base.py b/nipype/interfaces/fsl/base.py index 513612fb50..2bb120e097 100644 --- a/nipype/interfaces/fsl/base.py +++ b/nipype/interfaces/fsl/base.py @@ -64,6 +64,7 @@ class Info(PackageInfo): version_file = os.path.join( os.getenv('FSLDIR'), 'etc', 'fslversion') + @staticmethod def parse_version(raw_info): return raw_info.splitlines()[0]