Skip to content

Commit 2e2740d

Browse files
committed
feat(tools): Imporve activate.py debug information
1 parent fe3bb07 commit 2e2740d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

tools/activate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def die(msg: str) -> None:
17-
sys.exit(f'error: {msg}')
17+
sys.exit(f'\nERROR: {msg}')
1818

1919

2020
idf_tools_path = os.path.realpath(os.path.dirname(__file__))
@@ -37,7 +37,11 @@ def die(msg: str) -> None:
3737
os.environ['IDF_PYTHON_ENV_PATH'] = idf_python_env_path
3838
os.environ['ESP_IDF_VERSION'] = idf_version
3939

40+
if not os.path.exists(virtualenv_python):
41+
die(f'ESP-IDF Python virtual environment not found. Please run the install script to set it up before proceeding.')
42+
4043
try:
4144
run([virtualenv_python, os.path.join(idf_path, 'tools', 'export_utils', 'activate_venv.py')] + sys.argv[1:], check=True)
4245
except (OSError, SubprocessError):
43-
die(f'Activation script failed')
46+
die('\n'.join(['Activation script failed',
47+
'To view detailed debug information, set ESP_IDF_EXPORT_DEBUG=1 and run the export script again.']))

tools/export_utils/activate_venv.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,16 @@ def get_idf_env() -> Dict[str,str]:
8787
'IDF_PYTHON_ENV_PATH': os.environ['IDF_PYTHON_ENV_PATH'],
8888
}
8989

90-
for line in stdout.splitlines():
91-
var, val = line.split('=')
92-
idf_env[var] = val
90+
try:
91+
for line in stdout.splitlines():
92+
var, val = line.split('=')
93+
idf_env[var] = val
94+
except ValueError as e:
95+
debug('\n'.join(['Output from `./tools/idf_tools.py export --format key-value`:',
96+
f'{stdout}']))
97+
raise ValueError('\n'.join(['Please ensure your ESP-IDF installation is clean, especially file `./tools/idf_tools.py`.',
98+
'The command `./tools/idf_tools.py export` appears to be returning unexpected values.',
99+
f'Details: {e}']))
93100

94101
if 'PATH' in idf_env:
95102
idf_env['PATH'] = os.pathsep.join([extra_paths, idf_env['PATH']])

0 commit comments

Comments
 (0)