Skip to content

Commit f882fd2

Browse files
committed
Merge pull request #1174 from satra/fix/frompy3
fix: change how hash values are computed
2 parents e25da04 + b05da12 commit f882fd2

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Next release
22
============
33

4+
* API: Change how hash values are computed (https://github.com/nipy/nipype/pull/1174)
45
* ENH: New interfaces for MRTrix3 (https://github.com/nipy/nipype/pull/1126)
56
* ENH: New option in afni.3dRefit - zdel, ydel, zdel etc. (https://github.com/nipy/nipype/pull/1079)
67
* FIX: ants.Registration composite transform outputs are no longer returned as lists (https://github.com/nipy/nipype/pull/1183)

nipype/interfaces/base.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,14 @@ def __repr__(self):
175175
for k, v in sorted(self.items()):
176176
if not first:
177177
outstr.append(', ')
178-
outstr.append('%s=%r' % (k, v))
178+
if isinstance(v, dict):
179+
pairs = []
180+
for key, value in sorted(v.items()):
181+
pairs.append("'%s': %s" % (key, value))
182+
v = '{' + ', '.join(pairs) + '}'
183+
outstr.append('%s=%s' % (k, v))
184+
else:
185+
outstr.append('%s=%r' % (k, v))
179186
first = False
180187
outstr.append(')')
181188
return ''.join(outstr)
@@ -537,8 +544,8 @@ def get_hashval(self, hash_method=None):
537544
538545
"""
539546

540-
dict_withhash = {}
541-
dict_nofilename = {}
547+
dict_withhash = []
548+
dict_nofilename = []
542549
for name, val in sorted(self.get().items()):
543550
if isdefined(val):
544551
trait = self.trait(name)
@@ -548,24 +555,24 @@ def get_hashval(self, hash_method=None):
548555
False)
549556
and not has_metadata(trait.trait_type,
550557
"name_source"))
551-
dict_nofilename[name] = \
558+
dict_nofilename.append((name,
552559
self._get_sorteddict(val, hash_method=hash_method,
553-
hash_files=hash_files)
554-
dict_withhash[name] = \
560+
hash_files=hash_files)))
561+
dict_withhash.append((name,
555562
self._get_sorteddict(val, True, hash_method=hash_method,
556-
hash_files=hash_files)
557-
return (dict_withhash, md5(str(dict_nofilename)).hexdigest())
563+
hash_files=hash_files)))
564+
return dict_withhash, md5(str(dict_nofilename)).hexdigest()
558565

559566
def _get_sorteddict(self, object, dictwithhash=False, hash_method=None,
560567
hash_files=True):
561568
if isinstance(object, dict):
562-
out = {}
569+
out = []
563570
for key, val in sorted(object.items()):
564571
if isdefined(val):
565-
out[key] = \
572+
out.append((key,
566573
self._get_sorteddict(val, dictwithhash,
567574
hash_method=hash_method,
568-
hash_files=hash_files)
575+
hash_files=hash_files)))
569576
elif isinstance(object, (list, tuple)):
570577
out = []
571578
for val in object:
@@ -1342,7 +1349,7 @@ class must be instantiated with a command argument
13421349
'environ': {'DISPLAY': ':1'}, 'args': '-al'}
13431350
13441351
>>> cli.inputs.get_hashval()
1345-
({'args': '-al'}, 'a2f45e04a34630c5f33a75ea2a533cdd')
1352+
([('args', '-al')], '11c37f97649cd61627f4afe5136af8c0')
13461353
13471354
"""
13481355

nipype/interfaces/tests/test_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class spec(nib.TraitedSpec):
8888
specfunc = lambda x : spec(hoo=x)
8989
yield assert_raises, nib.traits.TraitError, specfunc, 1
9090
infields = spec(foo=1)
91-
hashval = ({'foo': 1, 'goo': '0.0000000000'}, 'cb03be1c3182ff941eecea6440c910f0')
91+
hashval = ([('foo', 1), ('goo', '0.0000000000')], 'e89433b8c9141aa0fda2f8f4d662c047')
9292
yield assert_equal, infields.get_hashval(), hashval
9393
#yield assert_equal, infields.hashval[1], hashval[1]
9494
yield assert_equal, infields.__repr__(), '\nfoo = 1\ngoo = 0.0\n'
@@ -314,7 +314,7 @@ class spec2(nib.TraitedSpec):
314314
doo = nib.traits.List(nib.File(exists=True))
315315
infields = spec2(moo=tmp_infile, doo=[tmp_infile])
316316
hashval = infields.get_hashval(hash_method='content')
317-
yield assert_equal, hashval[1], '8c227fb727c32e00cd816c31d8fea9b9'
317+
yield assert_equal, hashval[1], 'a00e9ee24f5bfa9545a515b7a759886b'
318318
teardown_file(tmpd)
319319

320320
@skipif(checknose)
@@ -329,7 +329,7 @@ class spec2(nib.TraitedSpec):
329329
doo = nib.traits.List(nib.File(exists=True))
330330
infields = spec2(moo=nme, doo=[tmp_infile])
331331
hashval = infields.get_hashval(hash_method='content')
332-
yield assert_equal, hashval[1], '642c326a05add933e9cdc333ce2d0ac2'
332+
yield assert_equal, hashval[1], '8da4669ff5d72f670a46ea3e7a203215'
333333

334334
class spec3(nib.TraitedSpec):
335335
moo = nib.File(exists=True, name_source="doo")

nipype/pipeline/engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ def _get_hashval(self):
14711471
sorted_outputs = sorted(self.needed_outputs)
14721472
hashobject.update(str(sorted_outputs))
14731473
hashvalue = hashobject.hexdigest()
1474-
hashed_inputs['needed_outputs'] = sorted_outputs
1474+
hashed_inputs.append(('needed_outputs', sorted_outputs))
14751475
return hashed_inputs, hashvalue
14761476

14771477
def _save_hashfile(self, hashfile, hashed_inputs):
@@ -2136,7 +2136,7 @@ def _get_hashval(self):
21362136
sorted_outputs = sorted(self.needed_outputs)
21372137
hashobject.update(str(sorted_outputs))
21382138
hashvalue = hashobject.hexdigest()
2139-
hashed_inputs['needed_outputs'] = sorted_outputs
2139+
hashed_inputs.append(('needed_outputs', sorted_outputs))
21402140
return hashed_inputs, hashvalue
21412141

21422142
@property

0 commit comments

Comments
 (0)