From a71a74cd9dcac1b424878731495801a9be6b038c Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Wed, 23 Jun 2021 11:46:00 +0200 Subject: [PATCH] tools: Catch OSError which is raised when the tool is not available Closes https://github.com/espressif/esp-idf/issues/7140 --- tools/idf_tools.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index c1bc09b680..8aa013fcdf 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -967,12 +967,15 @@ def get_python_env_path(): # type: () -> Tuple[str, str, str] with open(version_file_path, 'r') as version_file: idf_version_str = version_file.read() else: + idf_version_str = '' try: idf_version_str = subprocess.check_output(['git', 'describe'], cwd=global_idf_path, env=os.environ).decode() + except OSError: + # OSError should cover FileNotFoundError and WindowsError + warn('Git was not found') except subprocess.CalledProcessError as e: - warn('Git describe was unsuccessul: {}'.format(e)) - idf_version_str = '' + warn('Git describe was unsuccessul: {}'.format(e.output)) match = re.match(r'^v([0-9]+\.[0-9]+).*', idf_version_str) if match: idf_version = match.group(1) # type: Optional[str] @@ -1351,7 +1354,7 @@ def action_install_python_env(args): # type: ignore if os.path.exists(virtualenv_python): try: subprocess.check_call([virtualenv_python, '--version'], stdout=sys.stdout, stderr=sys.stderr) - except subprocess.CalledProcessError: + except (OSError, subprocess.CalledProcessError): # At this point we can reinstall the virtual environment if it is non-functional. This can happen at least # when the Python interpreter was removed which was used to create the virtual environment. reinstall = True