From d5be8c0b646f3953a57d6b4921d322aecef725b3 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Mon, 2 Nov 2020 16:23:46 -0500 Subject: [PATCH 1/2] FIX: Canonicalize environment in deprecated version_from_command() --- nipype/interfaces/base/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/base/core.py b/nipype/interfaces/base/core.py index afafbebf84..755a33317c 100644 --- a/nipype/interfaces/base/core.py +++ b/nipype/interfaces/base/core.py @@ -26,7 +26,7 @@ from ... import config, logging, LooseVersion from ...utils.provenance import write_provenance from ...utils.misc import str2bool, rgetcwd -from ...utils.filemanip import split_filename, which, get_dependencies +from ...utils.filemanip import split_filename, which, get_dependencies, canonicalize_env from ...utils.subprocess import run_command from ...external.due import due @@ -778,7 +778,7 @@ def version_from_command(self, flag="-v", cmd=None): proc = sp.Popen( " ".join((cmd, flag)), shell=True, - env=env, + env=canonicalize_env(env), stdout=sp.PIPE, stderr=sp.PIPE, ) From 0dbcedda8c9e38f9c8ca90f8d9b6e0f5d0437fd8 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Mon, 2 Nov 2020 16:56:02 -0500 Subject: [PATCH 2/2] FIX: Windows actually wants strings --- nipype/utils/filemanip.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 656f4d23af..9b3741ae96 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -26,11 +26,7 @@ fmlogger = logging.getLogger("nipype.utils") -related_filetype_sets = [ - (".hdr", ".img", ".mat"), - (".nii", ".mat"), - (".BRIK", ".HEAD"), -] +related_filetype_sets = [(".hdr", ".img", ".mat"), (".nii", ".mat"), (".BRIK", ".HEAD")] def _resolve_with_filenotfound(path, **kwargs): @@ -876,7 +872,7 @@ def get_dependencies(name, environ): def canonicalize_env(env): - """Windows requires that environment be dicts with bytes as keys and values + """Windows requires that environment be dicts with str as keys and values This function converts any unicode entries for Windows only, returning the dictionary untouched in other environments. @@ -888,7 +884,7 @@ def canonicalize_env(env): Returns ------- env : dict - Windows: environment dictionary with bytes keys and values + Windows: environment dictionary with str keys and values Other: untouched input ``env`` """ if os.name != "nt": @@ -896,10 +892,10 @@ def canonicalize_env(env): out_env = {} for key, val in env.items(): - if not isinstance(key, bytes): - key = key.encode("utf-8") - if not isinstance(val, bytes): - val = val.encode("utf-8") + if not isinstance(key, str): + key = key.decode("utf-8") + if not isinstance(val, str): + val = val.decode("utf-8") out_env[key] = val return out_env