@@ -293,27 +293,29 @@ def is_cached(self, rm_outdated=False):
293
293
"""
294
294
outdir = self .output_dir ()
295
295
296
- # Update hash
297
- hashed_inputs , hashvalue = self ._get_hashval ()
298
-
299
296
# The output folder does not exist: not cached
300
- if not op .exists (outdir ):
301
- logger .debug ('[Node] Directory not found "%s".' , outdir )
297
+ if not op .exists (outdir ) or \
298
+ not op .exists (op .join (outdir , 'result_%s.pklz' % self .name )):
299
+ logger .debug ('[Node] Not cached "%s".' , outdir )
302
300
return False , False
303
301
304
- hashfile = op .join (outdir , '_0x%s.json' % hashvalue )
305
- cached = op .exists (hashfile )
306
-
307
- # Check if updated
302
+ # Check if there are hashfiles
308
303
globhashes = glob (op .join (outdir , '_0x*.json' ))
309
304
unfinished = [
310
305
path for path in globhashes
311
306
if path .endswith ('_unfinished.json' )
312
307
]
313
308
hashfiles = list (set (globhashes ) - set (unfinished ))
309
+
310
+ # Update hash
311
+ hashed_inputs , hashvalue = self ._get_hashval ()
312
+
313
+ hashfile = op .join (outdir , '_0x%s.json' % hashvalue )
314
314
logger .debug ('[Node] Hashes: %s, %s, %s, %s' ,
315
315
hashed_inputs , hashvalue , hashfile , hashfiles )
316
316
317
+ cached = hashfile in hashfiles
318
+
317
319
# No previous hashfiles found, we're all set.
318
320
if cached and len (hashfiles ) == 1 :
319
321
assert (hashfile == hashfiles [0 ])
@@ -387,17 +389,17 @@ def hash_exists(self, updatehash=False):
387
389
return cached , self ._hashvalue , hashfile , self ._hashed_inputs
388
390
389
391
def run (self , updatehash = False ):
390
- """Execute the node in its directory.
392
+ """
393
+ Execute the node in its directory.
391
394
392
395
Parameters
393
396
----------
394
-
395
397
updatehash: boolean
396
398
When the hash stored in the output directory as a result of a previous run
397
399
does not match that calculated for this execution, updatehash=True only
398
400
updates the hash without re-running.
399
- """
400
401
402
+ """
401
403
if self .config is None :
402
404
self .config = {}
403
405
self .config = merge_dict (deepcopy (config ._sections ), self .config )
@@ -441,6 +443,11 @@ def run(self, updatehash=False):
441
443
for outdatedhash in glob (op .join (self .output_dir (), '_0x*.json' )):
442
444
os .remove (outdatedhash )
443
445
446
+ # _get_hashval needs to be called before running. When there is a valid (or seemingly
447
+ # valid cache), the is_cached() member updates the hashval via _get_hashval.
448
+ # However, if this node's folder doesn't exist or the result file is not found, then
449
+ # the hashval needs to be generated here. See #3026 for a larger context.
450
+ self ._get_hashval ()
444
451
# Hashfile while running
445
452
hashfile_unfinished = op .join (
446
453
outdir , '_0x%s_unfinished.json' % self ._hashvalue )
0 commit comments