Skip to content

Commit f054c29

Browse files
authored
Merge pull request #3267 from effigies/fix/canonicalize_env
FIX: Canonicalize environment dicts to strings in Windows
2 parents 35b7927 + 0dbcedd commit f054c29

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

nipype/interfaces/base/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from ... import config, logging, LooseVersion
2727
from ...utils.provenance import write_provenance
2828
from ...utils.misc import str2bool, rgetcwd
29-
from ...utils.filemanip import split_filename, which, get_dependencies
29+
from ...utils.filemanip import split_filename, which, get_dependencies, canonicalize_env
3030
from ...utils.subprocess import run_command
3131

3232
from ...external.due import due
@@ -778,7 +778,7 @@ def version_from_command(self, flag="-v", cmd=None):
778778
proc = sp.Popen(
779779
" ".join((cmd, flag)),
780780
shell=True,
781-
env=env,
781+
env=canonicalize_env(env),
782782
stdout=sp.PIPE,
783783
stderr=sp.PIPE,
784784
)

nipype/utils/filemanip.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626

2727
fmlogger = logging.getLogger("nipype.utils")
2828

29-
related_filetype_sets = [
30-
(".hdr", ".img", ".mat"),
31-
(".nii", ".mat"),
32-
(".BRIK", ".HEAD"),
33-
]
29+
related_filetype_sets = [(".hdr", ".img", ".mat"), (".nii", ".mat"), (".BRIK", ".HEAD")]
3430

3531

3632
def _resolve_with_filenotfound(path, **kwargs):
@@ -876,7 +872,7 @@ def get_dependencies(name, environ):
876872

877873

878874
def canonicalize_env(env):
879-
"""Windows requires that environment be dicts with bytes as keys and values
875+
"""Windows requires that environment be dicts with str as keys and values
880876
This function converts any unicode entries for Windows only, returning the
881877
dictionary untouched in other environments.
882878
@@ -888,18 +884,18 @@ def canonicalize_env(env):
888884
Returns
889885
-------
890886
env : dict
891-
Windows: environment dictionary with bytes keys and values
887+
Windows: environment dictionary with str keys and values
892888
Other: untouched input ``env``
893889
"""
894890
if os.name != "nt":
895891
return env
896892

897893
out_env = {}
898894
for key, val in env.items():
899-
if not isinstance(key, bytes):
900-
key = key.encode("utf-8")
901-
if not isinstance(val, bytes):
902-
val = val.encode("utf-8")
895+
if not isinstance(key, str):
896+
key = key.decode("utf-8")
897+
if not isinstance(val, str):
898+
val = val.decode("utf-8")
903899
out_env[key] = val
904900
return out_env
905901

0 commit comments

Comments
 (0)