diff --git a/.mypy.ini b/.mypy.ini index 2d7c2ac8e53..0fdab43fa46 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -28,3 +28,7 @@ follow_imports = skip [mypy-esp_pylib.*] # esp-pylib ships py.typed; follow it so NoReturn on log.die() is visible for type narrowing follow_imports = normal + +[mypy-rich.markup.*] +# rich.markup ships py.typed; follow it so escape() is visible for type narrowing +follow_imports = normal diff --git a/tools/export_utils/activate_venv.py b/tools/export_utils/activate_venv.py index a8490729259..95b8b6427c3 100644 --- a/tools/export_utils/activate_venv.py +++ b/tools/export_utils/activate_venv.py @@ -11,6 +11,7 @@ from console_output import status_message from esp_pylib.excepthook import install_exception_reporting from esp_pylib.logger import log from rich.markup import escape +from rich.text import Text from shell_types import SHELL_CLASSES from shell_types import SUPPORTED_SHELLS from utils import conf @@ -108,18 +109,18 @@ def detect_shell(args: Any) -> str: @status_message('Detecting outdated tools in system', rv_on_ok=True) -def print_uninstall_msg() -> Any: +def print_uninstall_msg() -> Text: stdout = run_cmd([sys.executable, conf.IDF_TOOLS_PY, 'uninstall', '--dry-run']) if stdout: python_cmd = 'python.exe' if sys.platform == 'win32' else 'python' - msg = ( - f'Found tools that are not used by active ESP-IDF version.\n' - f'[bright_cyan]{stdout}\n' - f'To free up even more space, remove installation packages of those tools.\n' - f'Use option {python_cmd} {conf.IDF_TOOLS_PY} uninstall --remove-archives.' + msg = Text('Found tools that are not used by active ESP-IDF version.\n', style='green') + msg.append( + f'{stdout}\nTo free up even more space, remove installation packages of those tools.\n' + f'Use option {python_cmd} {conf.IDF_TOOLS_PY} uninstall --remove-archives.', + style='bright_cyan', ) else: - msg = 'OK - no outdated tools found' + msg = Text('OK - no outdated tools found', style='green') return msg diff --git a/tools/export_utils/console_output.py b/tools/export_utils/console_output.py index dd9b2c6fd76..77af6c357ef 100644 --- a/tools/export_utils/console_output.py +++ b/tools/export_utils/console_output.py @@ -6,6 +6,7 @@ from typing import Any from typing import cast from rich.markup import escape +from rich.text import Text from utils import conf try: @@ -36,7 +37,7 @@ def configure_output(*, no_color: bool = False, quiet: bool = False, debug: bool def status_message(msg: str, msg_result: str = '', rv_on_ok: bool = False, die_on_err: bool = True) -> Callable: def inner(func: Callable) -> Callable: def wrapper(*args: Any, **kwargs: Any) -> Any: - log.print(f'[dark_orange]*[/dark_orange] {escape(msg)} ... ', file=sys.stderr, end='') + log.print(f'[dark_orange]*[/dark_orange] {msg} ... ', file=sys.stderr, end='') try: rv = func(*args, **kwargs) @@ -49,9 +50,10 @@ def status_message(msg: str, msg_result: str = '', rv_on_ok: bool = False, die_o log.die(escape(str(e))) if rv_on_ok: - log.print(f'[green]{escape(str(rv))}[/green]', file=sys.stderr) + result = rv if isinstance(rv, Text) else Text(str(rv), style='green') + log.print(result, file=sys.stderr) elif msg_result: - log.print(f'[green]{escape(msg_result)}[/green]', file=sys.stderr) + log.print(f'[green]{msg_result}[/green]', file=sys.stderr) else: log.print('[green]OK[/green]', file=sys.stderr)