From cff1815177de445c08a0bbdc8fb55c4b31a7c560 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Wed, 22 Jan 2020 02:45:46 +0800 Subject: [PATCH] idf_py: fix the ESPPORT environ variable type issue Python 2 expect the environ variables are all of type 'str', but sometimes wrong 'unicode' type is given. Here we force all variables that are not str to become str. --- tools/idf_py_actions/tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/idf_py_actions/tools.py b/tools/idf_py_actions/tools.py index cc35185aa..423aa558f 100644 --- a/tools/idf_py_actions/tools.py +++ b/tools/idf_py_actions/tools.py @@ -77,6 +77,13 @@ def run_tool(tool_name, args, cwd, env=dict()): env_copy = dict(os.environ) env_copy.update(env) + if sys.version_info[0] < 3: + # The subprocess lib cannot accept environment variables as "unicode". Convert to str. + # This encoding step is required only in Python 2. + for (key, val) in env_copy.items(): + if not isinstance(val, str): + env_copy[key] = val.encode(sys.getfilesystemencoding() or 'utf-8') + try: # Note: we explicitly pass in os.environ here, as we may have set IDF_PATH there during startup subprocess.check_call(args, env=env_copy, cwd=cwd)