From 26002e13fcc34db845a215c5c330d8fd86d689a5 Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Wed, 30 Oct 2024 15:53:16 +0100 Subject: [PATCH] feat(tools): Imporve activate.py debug information --- tools/activate.py | 8 ++++++-- tools/export_utils/activate_venv.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/activate.py b/tools/activate.py index 8c0c021a5da..d1f88e34adf 100755 --- a/tools/activate.py +++ b/tools/activate.py @@ -14,7 +14,7 @@ def die(msg: str) -> None: - sys.exit(f'error: {msg}') + sys.exit(f'\nERROR: {msg}') idf_tools_path = os.path.realpath(os.path.dirname(__file__)) @@ -37,7 +37,11 @@ def die(msg: str) -> None: os.environ['IDF_PYTHON_ENV_PATH'] = idf_python_env_path os.environ['ESP_IDF_VERSION'] = idf_version +if not os.path.exists(virtualenv_python): + die(f'ESP-IDF Python virtual environment not found. Please run the install script to set it up before proceeding.') + try: run([virtualenv_python, os.path.join(idf_path, 'tools', 'export_utils', 'activate_venv.py')] + sys.argv[1:], check=True) except (OSError, SubprocessError): - die(f'Activation script failed') + die('\n'.join(['Activation script failed', + 'To view detailed debug information, set ESP_IDF_EXPORT_DEBUG=1 and run the export script again.'])) diff --git a/tools/export_utils/activate_venv.py b/tools/export_utils/activate_venv.py index fa3ed051453..d409d50eadf 100644 --- a/tools/export_utils/activate_venv.py +++ b/tools/export_utils/activate_venv.py @@ -87,9 +87,16 @@ def get_idf_env() -> Dict[str,str]: 'IDF_PYTHON_ENV_PATH': os.environ['IDF_PYTHON_ENV_PATH'], } - for line in stdout.splitlines(): - var, val = line.split('=') - idf_env[var] = val + try: + for line in stdout.splitlines(): + var, val = line.split('=') + idf_env[var] = val + except ValueError as e: + debug('\n'.join(['Output from `./tools/idf_tools.py export --format key-value`:', + f'{stdout}'])) + raise ValueError('\n'.join(['Please ensure your ESP-IDF installation is clean, especially file `./tools/idf_tools.py`.', + 'The command `./tools/idf_tools.py export` appears to be returning unexpected values.', + f'Details: {e}'])) if 'PATH' in idf_env: idf_env['PATH'] = os.pathsep.join([extra_paths, idf_env['PATH']])