sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.61k stars 2.13k forks source link

Color output not shown in CI #13065

Open asmeurer opened 4 weeks ago

asmeurer commented 4 weeks ago

Describe the bug

This is a spinoff of https://github.com/sphinx-doc/sphinx/issues/13056

I have to add FORCE_COLOR=1 to my Makefile to force color output on CircleCI and GitHub Actions.

Here is an example of a build with the default options and no color output: https://github.com/Quansight-Labs/ndindex/actions/runs/11253438088/job/31288699625

Here is an example where I've set FORCE_COLOR=1 (from a different project): https://github.com/sympy/sympy/actions/runs/11484600101/job/31963800399

The color output makes things much easier to read, especially if there is a warning or error printed in red.

How to Reproduce

Run a Sphinx build on GitHub Actions

Environment Information

See the build log above. Seems to be installing Sphinx 8.0.2

Sphinx extensions

No response

Additional context

We should investigate why this happens. It isn't clear to me if this is just a limitation of CI systems or if there is something else at play here. What do other tools that output color on CI do? Are they manually enabling color when they detect they are on GitHub Actions? Is the fact that Sphinx is run through make relevant?

Obviously we don't want to unconditionally enable color output in Sphinx, especially when the output is a pipe.

AA-Turner commented 4 weeks ago

The relevant code is

https://github.com/sphinx-doc/sphinx/blob/8042eb633a51e5cf88c7dfa704d13895c1375da8/sphinx/util/console.py#L94-L109

My assumption is that it fails because CI is not a TTY. But as you say, perhaps we can improve this logic.

A

asmeurer commented 3 weeks ago

Here is the logic from a Rust package https://github.com/zkat/is_ci/blob/main/src/lib.rs

This is used in the Rust supports-color package https://github.com/zkat/supports-color/blob/main/src/lib.rs