From 575e924d61fbbfe48fbfd40895db1ddc35c98589 Mon Sep 17 00:00:00 2001 From: Peter Dragun Date: Wed, 14 Feb 2024 12:52:52 +0100 Subject: [PATCH] fix(tools): catch more general errors in python dependency checker --- .gitlab/ci/rules.yml | 2 ++ tools/check_python_dependencies.py | 19 +++++++++++-------- tools/ci/exclude_check_tools_files.txt | 1 - 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index b206407018..a756c316bb 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -138,6 +138,8 @@ - "tools/split_paths_by_spaces.py" + - "tools/check_python_dependencies.py" + .patterns-windows: &patterns-windows - "tools/windows/**/*" diff --git a/tools/check_python_dependencies.py b/tools/check_python_dependencies.py index ea0e45e640..945d8e7a0d 100755 --- a/tools/check_python_dependencies.py +++ b/tools/check_python_dependencies.py @@ -1,8 +1,7 @@ #!/usr/bin/env python # -# SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 - import argparse import os import re @@ -18,11 +17,11 @@ except ImportError: sys.exit(1) try: - from importlib.metadata import PackageNotFoundError, requires + from importlib.metadata import requires from importlib.metadata import version as get_version except ImportError: # compatibility for python <=3.7 - from importlib_metadata import PackageNotFoundError, requires # type: ignore + from importlib_metadata import requires # type: ignore from importlib_metadata import version as get_version # type: ignore try: @@ -92,8 +91,10 @@ if __name__ == '__main__': if not req.marker or req.marker.evaluate(): try: version_check(req) - except PackageNotFoundError as e: - not_satisfied.append(f"'{e}' - was not found and is required by the application") + except Exception as e: + # Catch general exception, because get_version may return None (https://github.com/python/cpython/issues/91216) + # log package name alongside the error message for easier debugging + not_satisfied.append(f"Error while checking requirement '{req}'. Package was not found and is required by the application: {e}") new_req_list.remove(req) else: new_req_list.remove(req) @@ -120,8 +121,10 @@ if __name__ == '__main__': # version is taken into account as well because packages can have different requirements for a given # Python package. The dependencies need to be checked for all of them because they can be different. new_req_list.extend(dependency_requirements - already_checked) - except PackageNotFoundError as e: - not_satisfied.append(f"'{e}' - was not found and is required by the application") + except Exception as e: + # Catch general exception, because get_version may return None (https://github.com/python/cpython/issues/91216) + # log package name alongside the error message for easier debugging + not_satisfied.append(f"Error while checking requirement '{req}'. Package was not found and is required by the application: {e}") if len(not_satisfied) > 0: print('The following Python requirements are not satisfied:') diff --git a/tools/ci/exclude_check_tools_files.txt b/tools/ci/exclude_check_tools_files.txt index a218ba6da7..f28943b7e5 100644 --- a/tools/ci/exclude_check_tools_files.txt +++ b/tools/ci/exclude_check_tools_files.txt @@ -8,7 +8,6 @@ tools/ci/check_copyright_config.yaml tools/ci/get_all_test_results.py tools/gdb_panic_server.py tools/check_term.py -tools/check_python_dependencies.py tools/python_version_checker.py tools/generate_debug_prefix_map.py tools/ci/checkout_project_ref.py