Skip to content

[MAINT] Cleaning / simplify Node #2325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e420ceb
[REF] Clean-up class Node code
oesteban Nov 17, 2017
a5ba813
general cleanup
oesteban Nov 18, 2017
d21b321
Merge remote-tracking branch 'upstream/master' into ref/Node-cleanup
oesteban Dec 1, 2017
5cb476e
revert changes to plugin base - make in different PR
oesteban Dec 1, 2017
5f87526
revert changes to multiproc - to another PR
oesteban Dec 1, 2017
7e66b04
take switch and loggin outside try except
oesteban Dec 1, 2017
15b13ea
pep8 fixups
oesteban Dec 1, 2017
02dba98
tidy up imports, fix pep8 issues
oesteban Dec 1, 2017
5467376
add some comments [skip ci]
oesteban Dec 1, 2017
e049918
use new makedirs
oesteban Dec 3, 2017
2fcab30
Merge remote-tracking branch 'upstream/master' into ref/Node-cleanup
oesteban Dec 5, 2017
3070378
add docstring to emptydirs
oesteban Dec 5, 2017
de11e79
remove self._results from Node
oesteban Dec 5, 2017
a1c0fbd
hashfiles is True
oesteban Dec 5, 2017
43537aa
fix import of md5
oesteban Dec 5, 2017
b46704f
improved hashfiles checks
oesteban Dec 7, 2017
a984202
wip - refactoring
oesteban Dec 21, 2017
e975626
fix emptydirs
oesteban Dec 22, 2017
73ec692
fix write_report
oesteban Dec 22, 2017
ead00d7
refactor nodes
oesteban Dec 22, 2017
16eafc0
Update SPM interfaces to use the new PackageInfo
oesteban Dec 22, 2017
db479b1
fix spm.Info when spm is not installed
oesteban Dec 23, 2017
94a4604
improve logging of nodes with updated hash
oesteban Dec 31, 2017
37554d0
remove hashfiles on error situations, improve logging the diff of has…
oesteban Dec 31, 2017
a0b2b04
python2 compat, sty fixes
oesteban Jan 1, 2018
371a10b
Merge remote-tracking branch 'upstream/master' into ref/Node-cleanup
oesteban Jan 3, 2018
afa74b7
make sure the OSError when cwd is deleted by other process is handled…
oesteban Jan 3, 2018
77e5257
improve log trace when ``os.getcwd()`` failed
oesteban Jan 7, 2018
a1c780b
cache cwd in config object, handle os.getcwd errors
oesteban Jan 7, 2018
d0e1ec8
elevate trace to warning
oesteban Jan 7, 2018
ee7c70b
add test for cwd
oesteban Jan 7, 2018
459e0ac
cleaning pe.utils
oesteban Jan 7, 2018
1725515
finishing pe.nodes cleanup
oesteban Jan 7, 2018
4e0f6e1
finishing pe.nodes - unfinished hashfiles
oesteban Jan 7, 2018
396aa1e
fix Bunch does not have keys()
oesteban Jan 7, 2018
bb905b9
[skip ci] fix ordering as per @djarecka
oesteban Jan 8, 2018
4e4c670
[skip ci] Extend docstring as per @djarecka
oesteban Jan 8, 2018
a80c9b1
[skip ci] Update CHANGES
oesteban Jan 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Upcoming release (0.14.1)
================

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

0.14.0 (November 29, 2017)
==========================
Expand Down
4 changes: 3 additions & 1 deletion nipype/interfaces/freesurfer/tests/test_FSSurfaceCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def test_FSSurfaceCommand_inputs():


@pytest.mark.skipif(fs.no_freesurfer(), reason="freesurfer is not installed")
def test_associated_file():
def test_associated_file(tmpdir):
fssrc = FreeSurferSource(subjects_dir=fs.Info.subjectsdir(),
subject_id='fsaverage', hemi='lh')
fssrc.base_dir = tmpdir.strpath
fssrc.resource_monitor = False

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

Expand Down
87 changes: 64 additions & 23 deletions nipype/interfaces/spm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
# Local imports
from ... import logging
from ...utils import spm_docs as sd, NUMPY_MMAP
from ..base import (BaseInterface, traits, isdefined, InputMultiPath,
BaseInterfaceInputSpec, Directory, Undefined, ImageFile)
from ..base import (
BaseInterface, traits, isdefined, InputMultiPath,
BaseInterfaceInputSpec, Directory, Undefined,
ImageFile, PackageInfo
)
from ..matlab import MatlabCommand
from ...external.due import due, Doi, BibTeX

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


class Info(object):
class Info(PackageInfo):
"""Handles SPM version information
"""
@staticmethod
def version(matlab_cmd=None, paths=None, use_mcr=None):
"""Returns the path to the SPM directory in the Matlab path
_path = None
_name = None

@classmethod
def path(klass, matlab_cmd=None, paths=None, use_mcr=None):
if klass._path:
return klass._path
klass.getinfo(matlab_cmd, paths, use_mcr)
return klass._path

@classmethod
def version(klass, matlab_cmd=None, paths=None, use_mcr=None):
if klass._version:
return klass._version
klass.getinfo(matlab_cmd, paths, use_mcr)
return klass._version

@classmethod
def name(klass, matlab_cmd=None, paths=None, use_mcr=None):
if klass._name:
return klass._name
klass.getinfo(matlab_cmd, paths, use_mcr)
return klass._name

@classmethod
def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
"""
Returns the path to the SPM directory in the Matlab path
If path not found, returns None.

Parameters
Expand All @@ -152,10 +180,17 @@ def version(matlab_cmd=None, paths=None, use_mcr=None):
returns None of path not found
"""

if klass._name and klass._path and klass._version:
return {
'name': klass._name,
'path': klass._path,
'release': klass._version
}

use_mcr = use_mcr or 'FORCE_SPMMCR' in os.environ
matlab_cmd = ((use_mcr and os.getenv('SPMMCRCMD')) or
os.getenv('MATLABCMD') or
'matlab -nodesktop -nosplash')
matlab_cmd = (
(use_mcr and os.getenv('SPMMCRCMD')) or
os.getenv('MATLABCMD', 'matlab -nodesktop -nosplash'))

mlab = MatlabCommand(matlab_cmd=matlab_cmd,
resource_monitor=False)
Expand Down Expand Up @@ -184,13 +219,17 @@ def version(matlab_cmd=None, paths=None, use_mcr=None):
# No Matlab -- no spm
logger.debug('%s', e)
return None
else:
out = sd._strip_header(out.runtime.stdout)
out_dict = {}
for part in out.split('|'):
key, val = part.split(':')
out_dict[key] = val
return out_dict

out = sd._strip_header(out.runtime.stdout)
out_dict = {}
for part in out.split('|'):
key, val = part.split(':')
out_dict[key] = val

klass._version = out_dict['release']
klass._path = out_dict['path']
klass._name = out_dict['name']
return out_dict


def no_spm():
Expand Down Expand Up @@ -288,13 +327,15 @@ def _matlab_cmd_update(self):

@property
def version(self):
version_dict = Info.version(matlab_cmd=self.inputs.matlab_cmd,
paths=self.inputs.paths,
use_mcr=self.inputs.use_mcr)
if version_dict:
return '.'.join((version_dict['name'].split('SPM')[-1],
version_dict['release']))
return version_dict
info_dict = Info.getinfo(
matlab_cmd=self.inputs.matlab_cmd,
paths=self.inputs.paths,
use_mcr=self.inputs.use_mcr
)
if info_dict:
return '%s.%s' % (
info_dict['name'].split('SPM')[-1],
info_dict['release'])

@property
def jobtype(self):
Expand Down
12 changes: 4 additions & 8 deletions nipype/interfaces/spm/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@
from nipype.interfaces.spm.base import SPMCommandInputSpec
from nipype.interfaces.base import traits

try:
matlab_cmd = os.environ['MATLABCMD']
except:
matlab_cmd = 'matlab'

mlab.MatlabCommand.set_default_matlab_cmd(matlab_cmd)
mlab.MatlabCommand.set_default_matlab_cmd(
os.getenv('MATLABCMD', 'matlab'))


def test_scan_for_fnames(create_files_in_directory):
Expand All @@ -35,10 +31,10 @@ def test_scan_for_fnames(create_files_in_directory):
if not save_time:
@pytest.mark.skipif(no_spm(), reason="spm is not installed")
def test_spm_path():
spm_path = spm.Info.version()['path']
spm_path = spm.Info.path()
if spm_path is not None:
assert isinstance(spm_path, (str, bytes))
assert 'spm' in spm_path
assert 'spm' in spm_path.lower()


def test_use_mfile():
Expand Down
8 changes: 2 additions & 6 deletions nipype/interfaces/spm/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
import nipype.interfaces.spm.model as spm
import nipype.interfaces.matlab as mlab

try:
matlab_cmd = os.environ['MATLABCMD']
except:
matlab_cmd = 'matlab'

mlab.MatlabCommand.set_default_matlab_cmd(matlab_cmd)
mlab.MatlabCommand.set_default_matlab_cmd(
os.getenv('MATLABCMD', 'matlab'))


def test_level1design():
Expand Down
12 changes: 4 additions & 8 deletions nipype/interfaces/spm/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
from nipype.interfaces.spm import no_spm
import nipype.interfaces.matlab as mlab

try:
matlab_cmd = os.environ['MATLABCMD']
except:
matlab_cmd = 'matlab'

mlab.MatlabCommand.set_default_matlab_cmd(matlab_cmd)
mlab.MatlabCommand.set_default_matlab_cmd(
os.getenv('MATLABCMD', 'matlab'))


def test_slicetiming():
Expand Down Expand Up @@ -88,7 +84,7 @@ def test_normalize12_list_outputs(create_files_in_directory):

@pytest.mark.skipif(no_spm(), reason="spm is not installed")
def test_segment():
if spm.Info.version()['name'] == "SPM12":
if spm.Info.name() == "SPM12":
assert spm.Segment()._jobtype == 'tools'
assert spm.Segment()._jobname == 'oldseg'
else:
Expand All @@ -98,7 +94,7 @@ def test_segment():

@pytest.mark.skipif(no_spm(), reason="spm is not installed")
def test_newsegment():
if spm.Info.version()['name'] == "SPM12":
if spm.Info.name() == "SPM12":
assert spm.NewSegment()._jobtype == 'spatial'
assert spm.NewSegment()._jobname == 'preproc'
else:
Expand Down
Loading