feat(tools): adopt esp-pylib for idf.py logging and errors

Migrate idf.py and its actions to the shared esp-pylib library:
- add esp-pylib (and esp-pylib[ide]) to the core/ide requirements
- base FatalError on esp_pylib.errors.FatalError, keeping the idf.py ctx cleanup
- replace the local raw-ANSI helpers (red_print/yellow_print/print_warning/
  color_print) with esp_pylib.logger.log (warn/err/note/hint) across the
  idf.py actions
- install esp_pylib exception reporting at the idf.py entry point and silence
  the logger during shell completion
- update affected tests for the new prefixes/line wrapping
- add normalize_output() helper and unify terminal env in conftest to handle
  Rich line-wrapping in CI assertions

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Marek Fiala
2026-07-13 11:28:49 +02:00
committed by BOT
parent 055ba9d3f9
commit 8c08c75f48
25 changed files with 381 additions and 318 deletions

View File

@@ -322,6 +322,29 @@ def idf_copy(func_work_dir: Path, request: FixtureRequest) -> typing.Generator[P
shutil.rmtree(path_to, ignore_errors=True)
@pytest.fixture(autouse=True, scope='session')
def idf_py_terminal_env() -> typing.Generator[None, None, None]:
"""Set terminal env so idf.py subprocesses produce consistent output.
COLUMNS=200 raises Rich's non-TTY default of 80, preventing most line wrapping.
Messages with long file paths can still exceed 200 characters; use
normalize_output() for assertions on those.
"""
keys = ('COLUMNS', 'LINES', 'NO_COLOR', 'FORCE_COLOR', 'PY_COLORS', 'TERM')
saved = {k: os.environ.get(k) for k in keys}
os.environ['COLUMNS'] = '200'
os.environ['LINES'] = '40'
os.environ['NO_COLOR'] = '1'
for k in ('FORCE_COLOR', 'PY_COLORS'):
os.environ.pop(k, None)
yield
for k, v in saved.items():
if v is None:
os.environ.pop(k, None)
else:
os.environ[k] = v
@pytest.fixture(name='default_idf_env')
def fixture_default_idf_env() -> EnvDict:
return get_idf_build_env(os.environ['IDF_PATH']) # type: ignore