From 9ecd0436f54c9225d53e1072e6126bd472472c3e Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Thu, 4 Jul 2019 15:06:00 +0800 Subject: [PATCH 1/2] tools: fix idf_tools.py exception with python3 use `subprocess.Popen` when catch TypeError: ``` Traceback (most recent call last): File "tools/idf_tools.py", line 1249, in main(sys.argv[1:]) File "tools/idf_tools.py", line 1245, in main action_func(args) File "tools/idf_tools.py", line 1038, in action_install tool_obj.find_installed_versions() File "tools/idf_tools.py", line 468, in find_installed_versions ver_str = self.check_version() File "tools/idf_tools.py", line 426, in check_version version_cmd_result = run_cmd_check_output(cmd, None, extra_paths) File "tools/idf_tools.py", line 176, in run_cmd_check_output result = subprocess.run(cmd, capture_output=True, check=True, input=input_text) File "/opt/pyenv/pyenv-1.2.6/versions/3.5.5/lib/python3.5/subprocess.py", line 383, in run with Popen(*popenargs, **kwargs) as process: TypeError: __init__() got an unexpected keyword argument 'capture_output' ``` --- tools/idf_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index 30ed7b6389..c005ecd6f4 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -175,7 +175,7 @@ def run_cmd_check_output(cmd, input_text=None, extra_paths=None): input_text = input_text.encode() result = subprocess.run(cmd, capture_output=True, check=True, input=input_text) return result.stdout + result.stderr - except AttributeError: + except (AttributeError, TypeError): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate(input_text) if p.returncode != 0: From a626061f3c2468710c29634273071c7692e76c22 Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Thu, 4 Jul 2019 16:30:42 +0800 Subject: [PATCH 2/2] tools: fix exception in checkout ref script: decode bytes before searching with RegEx --- tools/ci/checkout_project_ref.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/ci/checkout_project_ref.py b/tools/ci/checkout_project_ref.py index 5b6b332c9c..e9c060a1b0 100755 --- a/tools/ci/checkout_project_ref.py +++ b/tools/ci/checkout_project_ref.py @@ -34,16 +34,20 @@ def target_branch_candidates(proj_name): except (KeyError, TypeError): pass # branch name read from IDF - git_describe = subprocess.check_output(["git", "describe", "--tags", "HEAD"]) - match = IDF_GIT_DESCRIBE_PATTERN.search(git_describe) - if match: - major_revision = match.group(1) - minor_revision = match.group(2) - # release branch - candidates.append("release/v{}.{}".format(major_revision, minor_revision)) - # branch to match all major branches, like v3.x or v3 - candidates.append("release/v{}.x".format(major_revision)) - candidates.append("release/v{}".format(major_revision)) + try: + git_describe = subprocess.check_output(["git", "describe", "--tags", "HEAD"]) + match = IDF_GIT_DESCRIBE_PATTERN.search(git_describe.decode()) + if match: + major_revision = match.group(1) + minor_revision = match.group(2) + # release branch + candidates.append("release/v{}.{}".format(major_revision, minor_revision)) + # branch to match all major branches, like v3.x or v3 + candidates.append("release/v{}.x".format(major_revision)) + candidates.append("release/v{}".format(major_revision)) + except subprocess.CalledProcessError: + # this should not happen as IDF should have describe message + pass return [c for c in candidates if c] # filter out null value