Skip to content

Commit e5bb856

Browse files
committed
Merge branch 'ref/interface-base' of github.com:oesteban/nipype into ref/interface-base
2 parents 67491af + 290eb77 commit e5bb856

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

nipype/interfaces/base/support.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
"""
55
6-
Miscelanous tools to support Interface functionality
7-
....................................................
6+
Miscellaneous tools to support Interface functionality
7+
......................................................
88
99
"""
1010
from __future__ import print_function, division, unicode_literals, absolute_import
11-
from builtins import range, object, open, str
11+
from builtins import range, object, str
1212

1313
import os
1414
from copy import deepcopy
@@ -18,7 +18,7 @@
1818

1919
from ... import logging
2020
from ...utils.misc import is_container
21-
from ...utils.filemanip import md5, to_str
21+
from ...utils.filemanip import md5, to_str, hash_infile
2222
iflogger = logging.getLogger('interface')
2323

2424

@@ -116,27 +116,6 @@ def __repr__(self):
116116
outstr.append(')')
117117
return ''.join(outstr)
118118

119-
def _hash_infile(self, adict, key):
120-
# Inject file hashes into adict[key]
121-
stuff = adict[key]
122-
if not is_container(stuff):
123-
stuff = [stuff]
124-
file_list = []
125-
for afile in stuff:
126-
if os.path.isfile(afile):
127-
md5obj = md5()
128-
with open(afile, 'rb') as fp:
129-
while True:
130-
data = fp.read(8192)
131-
if not data:
132-
break
133-
md5obj.update(data)
134-
md5hex = md5obj.hexdigest()
135-
else:
136-
md5hex = None
137-
file_list.append((afile, md5hex))
138-
return file_list
139-
140119
def _get_bunch_hash(self):
141120
"""Return a dictionary of our items with hashes for each file.
142121
@@ -181,7 +160,7 @@ def _get_bunch_hash(self):
181160
dict_withhash = self.dictcopy()
182161
dict_nofilename = self.dictcopy()
183162
for item in infile_list:
184-
dict_withhash[item] = self._hash_infile(dict_withhash, item)
163+
dict_withhash[item] = _hash_bunch_dict(dict_withhash, item)
185164
dict_nofilename[item] = [val[1] for val in dict_withhash[item]]
186165
# Sort the items of the dictionary, before hashing the string
187166
# representation so we get a predictable order of the
@@ -208,6 +187,15 @@ def __pretty__(self, p, cycle):
208187
p.end_group(6, ')')
209188

210189

190+
def _hash_bunch_dict(adict, key):
191+
"""Inject file hashes into adict[key]"""
192+
stuff = adict[key]
193+
if not is_container(stuff):
194+
stuff = [stuff]
195+
return [(afile, hash_infile(afile))
196+
for afile in stuff]
197+
198+
211199
class InterfaceResult(object):
212200
"""Object that contains the results of running a particular Interface.
213201
@@ -307,7 +295,7 @@ def load_template(name):
307295
please use nipype.interfaces.fsl.model.load_template
308296
309297
"""
310-
from .fsl.model import load_template
298+
from ..fsl.model import load_template
311299
iflogger.warning(
312300
'Deprecated in 1.0.0, and will be removed in 1.1.0, '
313301
'please use nipype.interfaces.fsl.model.load_template instead.'

nipype/interfaces/base/traits_extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
"""
5-
Traits extention
5+
Traits extension
66
................
77
88
This module contains Trait classes that we've pulled from the

0 commit comments

Comments
 (0)