diff --git a/nipype/interfaces/base.py b/nipype/interfaces/base.py index f7a2b5b655..1bd632f2ec 100644 --- a/nipype/interfaces/base.py +++ b/nipype/interfaces/base.py @@ -925,34 +925,36 @@ def _check_version_requirements(self, trait_object, raise_exception=True): """ Raises an exception on version mismatch """ unavailable_traits = [] - version = LooseVersion(str(self.version)) - if not version: - return # check minimum version check = dict(min_ver=lambda t: t is not None) names = trait_object.trait_names(**check) - for name in names: - min_ver = LooseVersion(str(trait_object.traits()[name].min_ver)) - if min_ver > version: - unavailable_traits.append(name) - if not isdefined(getattr(trait_object, name)): - continue - if raise_exception: - raise Exception('Trait %s (%s) (version %s < required %s)' % - (name, self.__class__.__name__, - version, min_ver)) - check = dict(max_ver=lambda t: t is not None) - names = trait_object.trait_names(**check) - for name in names: - max_ver = LooseVersion(str(trait_object.traits()[name].max_ver)) - if max_ver < version: - unavailable_traits.append(name) - if not isdefined(getattr(trait_object, name)): - continue - if raise_exception: - raise Exception('Trait %s (%s) (version %s > required %s)' % - (name, self.__class__.__name__, - version, max_ver)) + + if names: + version = LooseVersion(str(self.version)) + if not version: + return + for name in names: + min_ver = LooseVersion(str(trait_object.traits()[name].min_ver)) + if min_ver > version: + unavailable_traits.append(name) + if not isdefined(getattr(trait_object, name)): + continue + if raise_exception: + raise Exception('Trait %s (%s) (version %s < required %s)' % + (name, self.__class__.__name__, + version, min_ver)) + check = dict(max_ver=lambda t: t is not None) + names = trait_object.trait_names(**check) + for name in names: + max_ver = LooseVersion(str(trait_object.traits()[name].max_ver)) + if max_ver < version: + unavailable_traits.append(name) + if not isdefined(getattr(trait_object, name)): + continue + if raise_exception: + raise Exception('Trait %s (%s) (version %s > required %s)' % + (name, self.__class__.__name__, + version, max_ver)) return unavailable_traits def _run_wrapper(self, runtime): diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index 9f7949cf67..ddabcb29fa 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -766,16 +766,19 @@ class Segment(SPMCommand): """ - _local_version = SPMCommand().version - if _local_version and '12.' in _local_version: - _jobtype = 'tools' - _jobname = 'oldseg' - else: - _jobtype = 'spatial' - _jobname = 'preproc' - input_spec = SegmentInputSpec output_spec = SegmentOutputSpec + + def __init__(self, **inputs): + _local_version = SPMCommand().version + if _local_version and '12.' in _local_version: + self._jobtype = 'tools' + self._jobname = 'oldseg' + else: + self._jobtype = 'spatial' + self._jobname = 'preproc' + + SPMCommand.__init__(self, **inputs) def _format_arg(self, opt, spec, val): """Convert input to appropriate format for spm @@ -894,13 +897,17 @@ class NewSegment(SPMCommand): input_spec = NewSegmentInputSpec output_spec = NewSegmentOutputSpec - _local_version = SPMCommand().version - if _local_version and '12.' in _local_version: - _jobtype = 'spatial' - _jobname = 'preproc' - else: - _jobtype = 'tools' - _jobname = 'preproc8' + + def __init__(self, **inputs): + _local_version = SPMCommand().version + if _local_version and '12.' in _local_version: + self._jobtype = 'spatial' + self._jobname = 'preproc' + else: + self._jobtype = 'tools' + self._jobname = 'preproc8' + + SPMCommand.__init__(self, **inputs) def _format_arg(self, opt, spec, val): """Convert input to appropriate format for spm diff --git a/nipype/interfaces/spm/tests/test_preprocess.py b/nipype/interfaces/spm/tests/test_preprocess.py index 45caf3cd8b..47c2e16154 100644 --- a/nipype/interfaces/spm/tests/test_preprocess.py +++ b/nipype/interfaces/spm/tests/test_preprocess.py @@ -106,20 +106,20 @@ def test_normalize12_list_outputs(): @skipif(no_spm) def test_segment(): if spm.Info.version()['name'] == "SPM12": - yield assert_equal, spm.Segment._jobtype, 'tools' - yield assert_equal, spm.Segment._jobname, 'oldseg' + yield assert_equal, spm.Segment()._jobtype, 'tools' + yield assert_equal, spm.Segment()._jobname, 'oldseg' else: - yield assert_equal, spm.Segment._jobtype, 'spatial' - yield assert_equal, spm.Segment._jobname, 'preproc' + yield assert_equal, spm.Segment()._jobtype, 'spatial' + yield assert_equal, spm.Segment()._jobname, 'preproc' @skipif(no_spm) def test_newsegment(): if spm.Info.version()['name'] == "SPM12": - yield assert_equal, spm.NewSegment._jobtype, 'spatial' - yield assert_equal, spm.NewSegment._jobname, 'preproc' + yield assert_equal, spm.NewSegment()._jobtype, 'spatial' + yield assert_equal, spm.NewSegment()._jobname, 'preproc' else: - yield assert_equal, spm.NewSegment._jobtype, 'tools' - yield assert_equal, spm.NewSegment._jobname, 'preproc8' + yield assert_equal, spm.NewSegment()._jobtype, 'tools' + yield assert_equal, spm.NewSegment()._jobname, 'preproc8' def test_smooth(): diff --git a/nipype/testing/data/pyscript.m b/nipype/testing/data/pyscript.m index 1c8cee6b7f..8bf3ece9f1 100644 --- a/nipype/testing/data/pyscript.m +++ b/nipype/testing/data/pyscript.m @@ -1,6 +1,14 @@ fprintf(1,'Executing %s at %s:\n',mfilename,datestr(now)); ver, -try,a=1; +try, +if isempty(which('spm')), +throw(MException('SPMCheck:NotFound','SPM not in matlab path')); +end; +spm_path = spm('dir'); +[name, version] = spm('ver'); +fprintf(1, 'NIPYPE path:%s|name:%s|release:%s', spm_path, name, version); +exit; + ,catch ME, fprintf(2,'MATLAB code threw an exception:\n'); fprintf(2,'%s\n',ME.message);