Bläddra i källkod

Merge branch 'fix/tools_py_environ_str' into 'master'

idf_py: fix the ESPPORT environ variable type issue

See merge request espressif/esp-idf!7433
Angus Gratton 6 år sedan
förälder
incheckning
64654c0444
1 ändrade filer med 7 tillägg och 0 borttagningar
  1. 7 0
      tools/idf_py_actions/tools.py

+ 7 - 0
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)