22import attr
33from pathlib import Path
44import typing as ty
5- from .helpers_file import hash_file , is_existed_file
65
76
87def attr_fields (x ):
@@ -40,15 +39,15 @@ def collect_additional_outputs(self, input_spec, inputs, output_dir):
4039 @property
4140 def hash (self ):
4241 """Compute a basic hash for any given set of fields."""
43- from .helpers import hash_function
42+ from .helpers import hash_value , hash_function
4443
4544 inp_dict = {}
4645 for field in attr_fields (self ):
4746 if field .name in ["_graph_checksums" , "bindings" ] or field .metadata .get (
4847 "output_file_template"
4948 ):
5049 continue
51- inp_dict [field .name ] = self . hash_value (
50+ inp_dict [field .name ] = hash_value (
5251 value = getattr (self , field .name ), tp = field .type , metadata = field .metadata
5352 )
5453 inp_hash = hash_function (inp_dict )
@@ -57,28 +56,6 @@ def hash(self):
5756 else :
5857 return inp_hash
5958
60- def hash_value (self , value , tp = None , metadata = None ):
61- """calculating hash or returning values recursively"""
62- if isinstance (value , (tuple , list )):
63- return [self .hash_value (el , tp , metadata ) for el in value ]
64- elif isinstance (value , dict ):
65- dict_hash = {
66- k : self .hash_value (v , tp , metadata ) for (k , v ) in value .items ()
67- }
68- # returning a sorted object
69- return sorted (dict_hash .items (), key = lambda x : x [0 ])
70- else : # not a container
71- if (
72- (tp is File or "pydra.engine.specs.File" in str (tp ))
73- and is_existed_file (value )
74- and "container_path" not in metadata
75- ):
76- return hash_file (value )
77- elif isinstance (value , tuple ):
78- return list (value )
79- else :
80- return value
81-
8259 def retrieve_values (self , wf , state_index = None ):
8360 """Get values contained by this spec."""
8461 temp_values = {}
0 commit comments