Skip to content

Commit 6009b57

Browse files
committed
clean up previous execution of examples
1 parent ce6a10b commit 6009b57

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

nipype/pipeline/engine/nodes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ def _load_resultfile(self, cwd):
528528
pkl_file = gzip.open(resultsoutputfile, 'rb')
529529
try:
530530
result = pickle.load(pkl_file)
531+
except UnicodeDecodeError:
532+
# Was this pickle created with Python 2.x?
533+
pickle.load(pkl_file, fix_imports=True, encoding='utf-8')
534+
logger.warn('Successfully loaded pickle in compatibility mode')
531535
except (traits.TraitError, AttributeError, ImportError) as err:
532536
if isinstance(err, (AttributeError, ImportError)):
533537
attribute_error = True

nipype/utils/filemanip.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,17 +470,21 @@ def loadpkl(infile):
470470
if infile.endswith('pklz'):
471471
pkl_file = gzip.open(infile, 'rb')
472472
else:
473-
pkl_file = open(infile)
474-
return pickle.load(pkl_file)
473+
pkl_file = open(infile, 'rb')
474+
475+
try:
476+
unpkl = pickle.load(pkl_file)
477+
except UnicodeDecodeError:
478+
unpkl = pickle.load(pkl_file, fix_imports=True, encoding='utf-8')
479+
return unpkl
475480

476481

477482
def savepkl(filename, record):
478-
content = pickle.dumps(record)
479483
if filename.endswith('pklz'):
480484
pkl_file = gzip.open(filename, 'wb')
481485
else:
482486
pkl_file = open(filename, 'wb')
483-
pkl_file.write(content.encode())
487+
pickle.dump(record, pkl_file)
484488
pkl_file.close()
485489

486490
rst_levels = ['=', '-', '~', '+']

tools/run_examples.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from multiprocessing import cpu_count
77

88

9-
def run_examples(example, pipelines, data_path, plugin=None):
9+
def run_examples(example, pipelines, data_path, plugin=None, rm_base_dir=True):
1010
from nipype import config
1111
from nipype.interfaces.base import CommandLine
1212

@@ -27,6 +27,10 @@ def run_examples(example, pipelines, data_path, plugin=None):
2727
wf = getattr(sys.modules[example], pipeline)
2828
wf.base_dir = os.path.join(os.getcwd(), 'output', example, plugin)
2929

30+
results_dir = os.path.join(wf.base_dir, wf.name)
31+
if rm_base_dir and os.path.exists(results_dir):
32+
rmtree(results_dir)
33+
3034
# Handle a logging directory
3135
log_dir = os.path.join(os.getcwd(), 'logs', example)
3236
if not os.path.exists(log_dir):

0 commit comments

Comments
 (0)