Skip to content

Commit 9be816e

Browse files
authored
Merge pull request #2325 from oesteban/ref/Node-cleanup
[MAINT] Cleaning / simplify Node
2 parents cfcd8f6 + a80c9b1 commit 9be816e

File tree

18 files changed

+1193
-950
lines changed

18 files changed

+1193
-950
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Upcoming release (0.14.1)
22
================
33

4+
* MAINT: Cleaning / simplify ``Node`` (https://github.com/nipy/nipype/pull/#2325)
45

56
0.14.0 (November 29, 2017)
67
==========================

nipype/interfaces/freesurfer/tests/test_FSSurfaceCommand.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ def test_FSSurfaceCommand_inputs():
2929

3030

3131
@pytest.mark.skipif(fs.no_freesurfer(), reason="freesurfer is not installed")
32-
def test_associated_file():
32+
def test_associated_file(tmpdir):
3333
fssrc = FreeSurferSource(subjects_dir=fs.Info.subjectsdir(),
3434
subject_id='fsaverage', hemi='lh')
35+
fssrc.base_dir = tmpdir.strpath
36+
fssrc.resource_monitor = False
3537

3638
fsavginfo = fssrc.run().outputs.get()
3739

nipype/interfaces/spm/base.py

+64-23
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
# Local imports
3030
from ... import logging
3131
from ...utils import spm_docs as sd, NUMPY_MMAP
32-
from ..base import (BaseInterface, traits, isdefined, InputMultiPath,
33-
BaseInterfaceInputSpec, Directory, Undefined, ImageFile)
32+
from ..base import (
33+
BaseInterface, traits, isdefined, InputMultiPath,
34+
BaseInterfaceInputSpec, Directory, Undefined,
35+
ImageFile, PackageInfo
36+
)
3437
from ..matlab import MatlabCommand
3538
from ...external.due import due, Doi, BibTeX
3639

@@ -123,12 +126,37 @@ def scans_for_fnames(fnames, keep4d=False, separate_sessions=False):
123126
return flist
124127

125128

126-
class Info(object):
129+
class Info(PackageInfo):
127130
"""Handles SPM version information
128131
"""
129-
@staticmethod
130-
def version(matlab_cmd=None, paths=None, use_mcr=None):
131-
"""Returns the path to the SPM directory in the Matlab path
132+
_path = None
133+
_name = None
134+
135+
@classmethod
136+
def path(klass, matlab_cmd=None, paths=None, use_mcr=None):
137+
if klass._path:
138+
return klass._path
139+
klass.getinfo(matlab_cmd, paths, use_mcr)
140+
return klass._path
141+
142+
@classmethod
143+
def version(klass, matlab_cmd=None, paths=None, use_mcr=None):
144+
if klass._version:
145+
return klass._version
146+
klass.getinfo(matlab_cmd, paths, use_mcr)
147+
return klass._version
148+
149+
@classmethod
150+
def name(klass, matlab_cmd=None, paths=None, use_mcr=None):
151+
if klass._name:
152+
return klass._name
153+
klass.getinfo(matlab_cmd, paths, use_mcr)
154+
return klass._name
155+
156+
@classmethod
157+
def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
158+
"""
159+
Returns the path to the SPM directory in the Matlab path
132160
If path not found, returns None.
133161
134162
Parameters
@@ -152,10 +180,17 @@ def version(matlab_cmd=None, paths=None, use_mcr=None):
152180
returns None of path not found
153181
"""
154182

183+
if klass._name and klass._path and klass._version:
184+
return {
185+
'name': klass._name,
186+
'path': klass._path,
187+
'release': klass._version
188+
}
189+
155190
use_mcr = use_mcr or 'FORCE_SPMMCR' in os.environ
156-
matlab_cmd = ((use_mcr and os.getenv('SPMMCRCMD')) or
157-
os.getenv('MATLABCMD') or
158-
'matlab -nodesktop -nosplash')
191+
matlab_cmd = (
192+
(use_mcr and os.getenv('SPMMCRCMD')) or
193+
os.getenv('MATLABCMD', 'matlab -nodesktop -nosplash'))
159194

160195
mlab = MatlabCommand(matlab_cmd=matlab_cmd,
161196
resource_monitor=False)
@@ -184,13 +219,17 @@ def version(matlab_cmd=None, paths=None, use_mcr=None):
184219
# No Matlab -- no spm
185220
logger.debug('%s', e)
186221
return None
187-
else:
188-
out = sd._strip_header(out.runtime.stdout)
189-
out_dict = {}
190-
for part in out.split('|'):
191-
key, val = part.split(':')
192-
out_dict[key] = val
193-
return out_dict
222+
223+
out = sd._strip_header(out.runtime.stdout)
224+
out_dict = {}
225+
for part in out.split('|'):
226+
key, val = part.split(':')
227+
out_dict[key] = val
228+
229+
klass._version = out_dict['release']
230+
klass._path = out_dict['path']
231+
klass._name = out_dict['name']
232+
return out_dict
194233

195234

196235
def no_spm():
@@ -288,13 +327,15 @@ def _matlab_cmd_update(self):
288327

289328
@property
290329
def version(self):
291-
version_dict = Info.version(matlab_cmd=self.inputs.matlab_cmd,
292-
paths=self.inputs.paths,
293-
use_mcr=self.inputs.use_mcr)
294-
if version_dict:
295-
return '.'.join((version_dict['name'].split('SPM')[-1],
296-
version_dict['release']))
297-
return version_dict
330+
info_dict = Info.getinfo(
331+
matlab_cmd=self.inputs.matlab_cmd,
332+
paths=self.inputs.paths,
333+
use_mcr=self.inputs.use_mcr
334+
)
335+
if info_dict:
336+
return '%s.%s' % (
337+
info_dict['name'].split('SPM')[-1],
338+
info_dict['release'])
298339

299340
@property
300341
def jobtype(self):

nipype/interfaces/spm/tests/test_base.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616
from nipype.interfaces.spm.base import SPMCommandInputSpec
1717
from nipype.interfaces.base import traits
1818

19-
try:
20-
matlab_cmd = os.environ['MATLABCMD']
21-
except:
22-
matlab_cmd = 'matlab'
23-
24-
mlab.MatlabCommand.set_default_matlab_cmd(matlab_cmd)
19+
mlab.MatlabCommand.set_default_matlab_cmd(
20+
os.getenv('MATLABCMD', 'matlab'))
2521

2622

2723
def test_scan_for_fnames(create_files_in_directory):
@@ -35,10 +31,10 @@ def test_scan_for_fnames(create_files_in_directory):
3531
if not save_time:
3632
@pytest.mark.skipif(no_spm(), reason="spm is not installed")
3733
def test_spm_path():
38-
spm_path = spm.Info.version()['path']
34+
spm_path = spm.Info.path()
3935
if spm_path is not None:
4036
assert isinstance(spm_path, (str, bytes))
41-
assert 'spm' in spm_path
37+
assert 'spm' in spm_path.lower()
4238

4339

4440
def test_use_mfile():

nipype/interfaces/spm/tests/test_model.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
import nipype.interfaces.spm.model as spm
77
import nipype.interfaces.matlab as mlab
88

9-
try:
10-
matlab_cmd = os.environ['MATLABCMD']
11-
except:
12-
matlab_cmd = 'matlab'
13-
14-
mlab.MatlabCommand.set_default_matlab_cmd(matlab_cmd)
9+
mlab.MatlabCommand.set_default_matlab_cmd(
10+
os.getenv('MATLABCMD', 'matlab'))
1511

1612

1713
def test_level1design():

nipype/interfaces/spm/tests/test_preprocess.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
from nipype.interfaces.spm import no_spm
1111
import nipype.interfaces.matlab as mlab
1212

13-
try:
14-
matlab_cmd = os.environ['MATLABCMD']
15-
except:
16-
matlab_cmd = 'matlab'
17-
18-
mlab.MatlabCommand.set_default_matlab_cmd(matlab_cmd)
13+
mlab.MatlabCommand.set_default_matlab_cmd(
14+
os.getenv('MATLABCMD', 'matlab'))
1915

2016

2117
def test_slicetiming():
@@ -88,7 +84,7 @@ def test_normalize12_list_outputs(create_files_in_directory):
8884

8985
@pytest.mark.skipif(no_spm(), reason="spm is not installed")
9086
def test_segment():
91-
if spm.Info.version()['name'] == "SPM12":
87+
if spm.Info.name() == "SPM12":
9288
assert spm.Segment()._jobtype == 'tools'
9389
assert spm.Segment()._jobname == 'oldseg'
9490
else:
@@ -98,7 +94,7 @@ def test_segment():
9894

9995
@pytest.mark.skipif(no_spm(), reason="spm is not installed")
10096
def test_newsegment():
101-
if spm.Info.version()['name'] == "SPM12":
97+
if spm.Info.name() == "SPM12":
10298
assert spm.NewSegment()._jobtype == 'spatial'
10399
assert spm.NewSegment()._jobname == 'preproc'
104100
else:

0 commit comments

Comments
 (0)