Skip to content

Commit 5467376

Browse files
committed
add some comments [skip ci]
1 parent 02dba98 commit 5467376

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

nipype/pipeline/engine/nodes.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def run(self, updatehash=False):
307307
updatehash: boolean
308308
Update the hash stored in the output directory
309309
"""
310-
cwd = os.getcwd()
310+
cwd = os.getcwd() # First thing, keep track of where we are
311311

312312
if self.config is None:
313313
self.config = {}
@@ -327,6 +327,7 @@ def run(self, updatehash=False):
327327
makedirs(outdir, exist_ok=True)
328328
os.chdir(outdir)
329329

330+
# Check hash, check whether run should be enforced
330331
logger.info('[Node] Setting-up "%s" in "%s".', self.fullname, outdir)
331332
hash_info = self.hash_exists(updatehash=updatehash)
332333
hash_exists, hashvalue, hashfile, hashed_inputs = hash_info
@@ -359,7 +360,7 @@ def run(self, updatehash=False):
359360
if need_rerun:
360361
log_debug = config.get('logging', 'workflow_level') == 'DEBUG'
361362
logger.debug('[Node] Rerunning "%s"', self.fullname)
362-
if log_debug and not hash_exists:
363+
if log_debug and not hash_exists: # Lazy logging - only debug
363364
exp_hash_paths = glob(json_pat)
364365
if len(exp_hash_paths) == 1:
365366
split_out = split_filename(exp_hash_paths[0])
@@ -375,9 +376,10 @@ def run(self, updatehash=False):
375376
hashed_inputs)
376377
if not force_run and str2bool(self.config['execution']['stop_on_first_rerun']):
377378
raise Exception('Cannot rerun when "stop_on_first_rerun" is set to True')
378-
hashfile_unfinished = op.join(outdir,
379-
'_0x%s_unfinished.json' %
380-
hashvalue)
379+
380+
# Hashfile while running, remove if exists already
381+
hashfile_unfinished = op.join(
382+
outdir, '_0x%s_unfinished.json' % hashvalue)
381383
if op.exists(hashfile):
382384
os.remove(hashfile)
383385

@@ -396,6 +398,7 @@ def run(self, updatehash=False):
396398
for filename in glob(op.join(outdir, '_0x*.json')):
397399
os.remove(filename)
398400

401+
# Store runtime-hashfile, pre-execution report, the node and the inputs set.
399402
self._save_hashfile(hashfile_unfinished, hashed_inputs)
400403
self.write_report(report_type='preexec', cwd=outdir)
401404
savepkl(op.join(outdir, '_node.pklz'), self)
@@ -405,11 +408,12 @@ def run(self, updatehash=False):
405408
self._run_interface(execute=True)
406409
except:
407410
logger.warning('[Node] Exception "%s" (%s)', self.fullname, outdir)
411+
# Tear-up after error
408412
os.remove(hashfile_unfinished)
409413
os.chdir(cwd)
410414
raise
411415

412-
# Tear-up
416+
# Tear-up after success
413417
shutil.move(hashfile_unfinished, hashfile)
414418
self.write_report(report_type='postexec', cwd=outdir)
415419
logger.info('[Node] Finished "%s".', self.fullname)

0 commit comments

Comments
 (0)