Skip to content

Commit

Permalink
feat(tools): Imporve activate.py debug information
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Fiala committed Nov 5, 2024
1 parent 405327d commit 26002e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions tools/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand All @@ -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.']))
13 changes: 10 additions & 3 deletions tools/export_utils/activate_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']])
Expand Down

0 comments on commit 26002e1

Please sign in to comment.