mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Enable colour by default in when running on CI (#13240)
This commit is contained in:
parent
501b8258fc
commit
2431c665d6
@ -44,6 +44,8 @@ Features added
|
||||
Patch by Chris Barrick.
|
||||
* #13227: Implement the :rst:role:`kbd` role as a ``SphinxRole``.
|
||||
Patch by Adam Turner.
|
||||
* #13065: Enable colour by default in when running on CI.
|
||||
Patch by Adam Turner.
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
@ -21,6 +21,8 @@ def terminal_supports_colour() -> bool:
|
||||
colorama.just_fix_windows_console()
|
||||
if 'FORCE_COLOUR' in os.environ or 'FORCE_COLOR' in os.environ:
|
||||
return True
|
||||
if os.environ.get('CI', '') in {'true', '1'}:
|
||||
return True
|
||||
|
||||
try:
|
||||
if not sys.stdout.isatty():
|
||||
|
@ -13,11 +13,12 @@ from typing import TYPE_CHECKING
|
||||
import sphinx._cli.util.errors
|
||||
import sphinx.locale
|
||||
from sphinx import __display_version__
|
||||
from sphinx._cli.util.colour import terminal_supports_colour
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.locale import __
|
||||
from sphinx.util._io import TeeStripANSI
|
||||
from sphinx.util._pathlib import _StrPath
|
||||
from sphinx.util.console import color_terminal, nocolor
|
||||
from sphinx.util.console import nocolor
|
||||
from sphinx.util.docutils import docutils_namespace, patch_docutils
|
||||
from sphinx.util.osutil import ensuredir
|
||||
|
||||
@ -326,7 +327,7 @@ def _validate_filenames(
|
||||
|
||||
|
||||
def _validate_colour_support(colour: str) -> None:
|
||||
if colour == 'no' or (colour == 'auto' and not color_terminal()):
|
||||
if colour == 'no' or (colour == 'auto' and not terminal_supports_colour()):
|
||||
nocolor()
|
||||
|
||||
|
||||
|
@ -16,9 +16,10 @@ from contextlib import chdir
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import sphinx
|
||||
from sphinx._cli.util.colour import terminal_supports_colour
|
||||
from sphinx.cmd.build import build_main
|
||||
from sphinx.util._pathlib import _StrPath
|
||||
from sphinx.util.console import blue, bold, color_terminal, nocolor
|
||||
from sphinx.util.console import blue, bold, nocolor
|
||||
from sphinx.util.osutil import rmtree
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -91,7 +92,7 @@ class Make:
|
||||
return 0
|
||||
|
||||
def build_help(self) -> None:
|
||||
if not color_terminal():
|
||||
if not terminal_supports_colour():
|
||||
nocolor()
|
||||
|
||||
print(bold('Sphinx v%s' % sphinx.__display_version__))
|
||||
|
@ -31,8 +31,9 @@ from docutils.utils import column_width
|
||||
|
||||
import sphinx.locale
|
||||
from sphinx import __display_version__, package_dir
|
||||
from sphinx._cli.util.colour import terminal_supports_colour
|
||||
from sphinx.locale import __
|
||||
from sphinx.util.console import bold, color_terminal, colorize, nocolor, red
|
||||
from sphinx.util.console import bold, colorize, nocolor, red
|
||||
from sphinx.util.osutil import ensuredir
|
||||
from sphinx.util.template import SphinxRenderer
|
||||
|
||||
@ -724,7 +725,7 @@ def main(argv: Sequence[str] = (), /) -> int:
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
sphinx.locale.init_console()
|
||||
|
||||
if not color_terminal():
|
||||
if not terminal_supports_colour():
|
||||
nocolor()
|
||||
|
||||
# parse options
|
||||
|
@ -2,12 +2,15 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sphinx._cli.util.colour import (
|
||||
terminal_supports_colour as color_terminal, # NoQA: F401
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Final
|
||||
|
||||
@ -91,24 +94,6 @@ def term_width_line(text: str) -> str:
|
||||
return text.ljust(_tw + len(text) - len(strip_escape_sequences(text))) + '\r'
|
||||
|
||||
|
||||
def color_terminal() -> bool:
|
||||
if 'NO_COLOR' in os.environ:
|
||||
return False
|
||||
if sys.platform == 'win32' and COLORAMA_AVAILABLE:
|
||||
colorama.just_fix_windows_console()
|
||||
return True
|
||||
if 'FORCE_COLOR' in os.environ:
|
||||
return True
|
||||
if not hasattr(sys.stdout, 'isatty'):
|
||||
return False
|
||||
if not sys.stdout.isatty():
|
||||
return False
|
||||
if 'COLORTERM' in os.environ:
|
||||
return True
|
||||
term = os.environ.get('TERM', 'dumb').lower()
|
||||
return term in {'xterm', 'linux'} or 'color' in term
|
||||
|
||||
|
||||
def nocolor() -> None:
|
||||
if sys.platform == 'win32' and COLORAMA_AVAILABLE:
|
||||
colorama.deinit()
|
||||
|
@ -2,9 +2,10 @@ from __future__ import annotations
|
||||
|
||||
import functools
|
||||
|
||||
from sphinx._cli.util.colour import terminal_supports_colour
|
||||
from sphinx.locale import __
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.console import bold, color_terminal
|
||||
from sphinx.util.console import bold
|
||||
|
||||
if False:
|
||||
from collections.abc import Callable, Iterable, Iterator
|
||||
@ -35,7 +36,7 @@ def status_iterator(
|
||||
stringify_func: Callable[[Any], str] = display_chunk,
|
||||
) -> Iterator[T]:
|
||||
# printing on a single line requires ANSI control sequences
|
||||
single_line = verbosity < 1 and color_terminal()
|
||||
single_line = verbosity < 1 and terminal_supports_colour()
|
||||
bold_summary = bold(summary)
|
||||
if length == 0:
|
||||
logger.info(bold_summary, nonl=True)
|
||||
|
Loading…
Reference in New Issue
Block a user