From 1700086f1a8e76ea5a12489f4358879f48e86b0d Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 1 Jan 2023 06:13:44 -0500 Subject: [PATCH] Enable colour logging for docker even if tty is not set --- discord/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index d60626ae2..772d57530 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1207,6 +1207,11 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) return f'' +def is_docker() -> bool: + path = '/proc/self/cgroup' + return os.path.exists('/.dockerenv') or (os.path.isfile(path) and any('docker' in line for line in open(path))) + + def stream_supports_colour(stream: Any) -> bool: # Pycharm and Vscode support colour in their inbuilt editors if 'PYCHARM_HOSTED' in os.environ or os.environ.get('TERM_PROGRAM') == 'vscode': @@ -1214,7 +1219,8 @@ def stream_supports_colour(stream: Any) -> bool: is_a_tty = hasattr(stream, 'isatty') and stream.isatty() if sys.platform != 'win32': - return is_a_tty + # Docker does not consistently have a tty attached to it + return is_a_tty or is_docker() # ANSICON checks for things like ConEmu # WT_SESSION checks if this is Windows Terminal