`colorama` disables colors in GitHub Actions
GitHub Actions provide no TTY, so colorama import wraps stdout and strips all colors https://github.com/tartley/colorama/issues/209#issuecomment-465119302 so even forcing colors doesn't work.
2022-06-30T17:00:45.4633499Z Successfully installed build-0.8.0 pep517-0.12.0 tomli-2.0.1
2022-06-30T17:00:46.1506025Z ##[group]Run python -m build
2022-06-30T17:00:46.1506287Z [36;1mpython -m build[0m
2022-06-30T17:00:46.1506499Z [36;1mgit status --ignored[0m
2022-06-30T17:00:46.1559508Z shell: /usr/bin/bash -e {0}
2022-06-30T17:00:46.1559700Z env:
2022-06-30T17:00:46.1559871Z FORCE_COLOR: 1
2022-06-30T17:00:46.1560056Z ##[endgroup]
2022-06-30T17:00:46.6361795Z * Creating venv isolated environment...
2022-06-30T17:00:49.6232262Z * Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
2022-06-30T17:00:52.0028343Z * Getting dependencies for sdist...
Took me a while to debug this. Added some debug statements.
--- a/src/build/__main__.py
+++ b/src/build/__main__.py
@@ -49,6 +49,7 @@ def _init_colors() -> Dict[str, str]:
_STYLES = _init_colors()
print(_STYLES)
+print('{red}ERROR{reset} {}'.format("msg", **_STYLES))
def _showwarning(
message: Union[Warning, str],
@@ -65,6 +64,7 @@ def _showwarning(
def _setup_cli() -> None:
+ print('{red}ERROR{reset} {}'.format("precolorama", **_STYLES))
warnings.showwarning = _showwarning
try:
@@ -73,6 +73,7 @@ def _setup_cli() -> None:
pass
else:
colorama.init() # fix colors on windows
+ print('{red}ERROR{reset} {}'.format("postcolorama", **_STYLES))
def _error(msg: str, code: int = 1) -> NoReturn: # pragma: no cover
And got this.

The solution is to enable colorama only on Windows.
That seems pretty reasonable to do, but just curious, why is colorama even present? It should not be installed on linux/macOS generally.
colorama is needed on Windows, because its terminal is unable to render ANSI sequences by itself. Why it was installed in Linux needs further investigation.
colorama is present by default on ubuntu-latest GHA runners.
https://github.com/yakshaveinc/python/runs/7144602632?check_suite_focus=true

But I haven't found why it is here. Software list doesn't include it https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2204-Readme.md and I couldn't find build logs for runner images to trace down who installs it. pip also doesn't seem to include the feature to track who needed a dependency.
Asked why the deps here https://github.com/actions/virtual-environments/issues/5851