Skip to content

Commit 9b0597a

Browse files
committed
fix: change how hash values are computed
1 parent 335c7a1 commit 9b0597a

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

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:
@@ -1340,7 +1347,7 @@ class must be instantiated with a command argument
13401347
'environ': {'DISPLAY': ':1'}, 'args': '-al'}
13411348
13421349
>>> cli.inputs.get_hashval()
1343-
({'args': '-al'}, 'a2f45e04a34630c5f33a75ea2a533cdd')
1350+
([('args', '-al')], '11c37f97649cd61627f4afe5136af8c0')
13441351
13451352
"""
13461353

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
@@ -1468,7 +1468,7 @@ def _get_hashval(self):
14681468
sorted_outputs = sorted(self.needed_outputs)
14691469
hashobject.update(str(sorted_outputs))
14701470
hashvalue = hashobject.hexdigest()
1471-
hashed_inputs['needed_outputs'] = sorted_outputs
1471+
hashed_inputs.append(('needed_outputs', sorted_outputs))
14721472
return hashed_inputs, hashvalue
14731473

14741474
def _save_hashfile(self, hashfile, hashed_inputs):
@@ -2133,7 +2133,7 @@ def _get_hashval(self):
21332133
sorted_outputs = sorted(self.needed_outputs)
21342134
hashobject.update(str(sorted_outputs))
21352135
hashvalue = hashobject.hexdigest()
2136-
hashed_inputs['needed_outputs'] = sorted_outputs
2136+
hashed_inputs.append(('needed_outputs', sorted_outputs))
21372137
return hashed_inputs, hashvalue
21382138

21392139
@property

0 commit comments

Comments
 (0)