@@ -128,6 +128,14 @@ def check_deprecated(data):
128
128
129
129
130
130
class CacheKeyFactoryBase (object ):
131
+
132
+ py_version = sys .version_info
133
+
134
+ class CacheKeyBase (object ):
135
+ def __init__ (self ):
136
+ self ._hasher = hashlib .sha256 ()
137
+ self ._hasher .update (CacheKeyFactoryBase .py_version )
138
+
131
139
def __init__ (self , keycls ):
132
140
self .keycls = keycls
133
141
self .created = dict ()
@@ -154,14 +162,15 @@ class CacheKeyFactory(CacheKeyFactoryBase):
154
162
Only the content of the module is taken into account
155
163
'''
156
164
157
- class CacheKey (object ):
165
+ class CacheKey (CacheKeyFactoryBase . CacheKeyBase ):
158
166
159
167
def __init__ (self , module_path , _ ):
168
+ super (CacheKey , self ).__init__ ()
160
169
161
170
with open (module_path , 'rb' ) as fd :
162
171
module_content = fd .read ()
163
- module_hash = hashlib . sha256 ( module_content ). hexdigest ( )
164
- self .module_hash = module_hash
172
+ self . _hasher . update ( module_content )
173
+ self .module_hash = m . hexdigest ()
165
174
166
175
@property
167
176
def path (self ):
@@ -179,7 +188,7 @@ class RecursiveCacheKeyFactory(CacheKeyFactoryBase):
179
188
key.
180
189
'''
181
190
182
- class CacheKey (object ):
191
+ class CacheKey (CacheKeyFactoryBase . CacheKeyBase ):
183
192
184
193
def __init__ (self , module_path , factory ):
185
194
assert module_path not in factory .created or factory .created [module_path ] is None
@@ -196,9 +205,7 @@ def __init__(self, module_path, factory):
196
205
if factory .get (dep , 1 ) is not None :
197
206
new_deps .append (dep )
198
207
199
- module_hash = hashlib .sha256 (module_content ).hexdigest ()
200
-
201
- hashes = [module_hash ]
208
+ self ._hasher .update (module_content )
202
209
203
210
for new_dep in sorted (new_deps ):
204
211
try :
@@ -207,9 +214,9 @@ def __init__(self, module_path, factory):
207
214
# better?
208
215
except UnicodeDecodeError :
209
216
continue
210
- hashes . append (new_dep_key .module_hash )
217
+ self . _hasher . update (new_dep_key .module_hash )
211
218
212
- self .module_hash = hashlib . sha256 ( "" . join ( hashes ). encode ( "ascii" )) .hexdigest ()
219
+ self .module_hash = self . _hasher .hexdigest ()
213
220
214
221
@property
215
222
def path (self ):
0 commit comments