From cde207e996b9a5e2facd18018a521ba10f91db62 Mon Sep 17 00:00:00 2001 From: Jakub Kocka Date: Mon, 23 Oct 2023 10:51:26 +0200 Subject: [PATCH] feat(tools): Added IDF path order check for Windows platform This relates to old GH issue: https://github.com/espressif/esp-idf/issues/5994 --- tools/idf.py | 9 +++++++++ tools/idf_tools.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/tools/idf.py b/tools/idf.py index 9ab0d90f57c4..1ddf6b0c95b1 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -105,6 +105,15 @@ def check_environment() -> List: debug_print_idf_version() raise SystemExit(1) + # Check used Python interpreter + checks_output.append('Checking used Python interpreter...') + try: + python_venv_path = os.environ['IDF_PYTHON_ENV_PATH'] + if python_venv_path and not sys.executable.startswith(python_venv_path): + print_warning(f'WARNING: Python interpreter "{sys.executable}" used to start idf.py is not from installed venv "{python_venv_path}"') + except KeyError: + print_warning('WARNING: The IDF_PYTHON_ENV_PATH is missing in environmental variables!') + return checks_output diff --git a/tools/idf_tools.py b/tools/idf_tools.py index e4be2a98402b..f55a8811f1f8 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -1802,6 +1802,15 @@ def action_export(args): # type: ignore if paths_to_export: export_vars['PATH'] = path_sep.join(to_shell_specific_paths(paths_to_export) + [old_path]) + # Correct PATH order check for Windows platform + # idf-exe has to be before \tools in PATH + if sys.platform == 'win32': + paths_to_check = rf"{export_vars['PATH']}{os.environ['PATH']}" + try: + if paths_to_check.index(r'\tools;') < paths_to_check.index(r'\idf-exe'): + warn('The PATH is not in correct order (idf-exe should be before esp-idf\\tools)') + except ValueError: + fatal(f'Both of the directories (..\\idf-exe\\.. and ..\\tools) has to be in the PATH:\n\n{paths_to_check}\n') if export_vars: # if not copy of export_vars is given to function, it brekas the formatting string for 'export_statements'