From 94ec45b8fe6753e07777c44954acb38838e60b0a Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Tue, 24 Sep 2019 11:38:51 -0400 Subject: [PATCH] fix: remove switching directory to load results --- nipype/utils/filemanip.py | 47 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 1cdd1e9676..fe1bdac5b1 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -707,34 +707,33 @@ def loadpkl(infile): pkl_metadata = None unpkl = None - with indirectory(infile.parent): - with SoftFileLock('%s.lock' % infile.name): - with pklopen(infile.name, 'rb') as pkl_file: - try: # Look if pkl file contains version file - pkl_metadata_line = pkl_file.readline() - pkl_metadata = json.loads(pkl_metadata_line) - except (UnicodeDecodeError, json.JSONDecodeError): - # Could not get version info - pkl_file.seek(0) - try: - unpkl = pickle.load(pkl_file) - except UnicodeDecodeError: - # Was this pickle created with Python 2.x? - unpkl = pickle.load(pkl_file, fix_imports=True, encoding='utf-8') - fmlogger.info('Successfully loaded pkl in compatibility mode.') - # Unpickling problems - except Exception as e: - if pkl_metadata and 'version' in pkl_metadata: - from nipype import __version__ as version - if pkl_metadata['version'] != version: - fmlogger.error("""\ + with SoftFileLock('%s.lock' % infile): + with pklopen(str(infile), 'rb') as pkl_file: + try: # Look if pkl file contains version file + pkl_metadata_line = pkl_file.readline() + pkl_metadata = json.loads(pkl_metadata_line) + except (UnicodeDecodeError, json.JSONDecodeError): + # Could not get version info + pkl_file.seek(0) + try: + unpkl = pickle.load(pkl_file) + except UnicodeDecodeError: + # Was this pickle created with Python 2.x? + unpkl = pickle.load(pkl_file, fix_imports=True, encoding='utf-8') + fmlogger.info('Successfully loaded pkl in compatibility mode.') + # Unpickling problems + except Exception as e: + if pkl_metadata and 'version' in pkl_metadata: + from nipype import __version__ as version + if pkl_metadata['version'] != version: + fmlogger.error("""\ Attempted to open a results file generated by Nipype version %s, \ with an incompatible Nipype version (%s)""", pkl_metadata['version'], version) - raise e - fmlogger.warning("""\ + raise e + fmlogger.warning("""\ No metadata was found in the pkl file. Make sure you are currently using \ the same Nipype version from the generated pkl.""") - raise e + raise e if unpkl is None: raise ValueError('Loading %s resulted in None.' % infile)