From 6f9b1bfd4849a72c2f858dcfafd4472152938cd0 Mon Sep 17 00:00:00 2001 From: Jesse McKenna Date: Fri, 23 Oct 2020 20:47:46 +0000 Subject: [PATCH] setup_color: Disable colorama on pre-Windows-10 This change disables colorama wrapping on versions of Windows prior to 10. Currently, this wrapping causes "TypeError: cannot use a string pattern on a bytes-like object" on Windows 7 and 8.1 when running `gclient sync`, `gclient fetch`, and other utilities that use colorama. Bug: 1114548 Change-Id: Id6b4a6f9a8ae0721765da34b5625b4524b9d36b1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2485882 Reviewed-by: Josip Sokcevic Commit-Queue: Jesse McKenna --- setup_color.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/setup_color.py b/setup_color.py index e866a6f48..03297f825 100644 --- a/setup_color.py +++ b/setup_color.py @@ -43,19 +43,20 @@ def enable_native_ansi(): def init(): - # should_wrap instructs colorama to wrap stdout/stderr with an ASNI colorcode + # should_wrap instructs colorama to wrap stdout/stderr with an ANSI colorcode # interpreter that converts them to SetConsoleTextAttribute calls. This only # should be True in cases where we're connected to cmd.exe's console. Setting # this to True on non-windows systems has no effect. should_wrap = False global IS_TTY, OUT_TYPE IS_TTY = sys.stdout.isatty() + is_windows = sys.platform.startswith('win') if IS_TTY: # Yay! We detected a console in the normal way. It doesn't really matter # if it's windows or not, we win. OUT_TYPE = 'console' should_wrap = True - elif sys.platform.startswith('win'): + elif is_windows: # assume this is some sort of file OUT_TYPE = 'file (win)' @@ -117,9 +118,9 @@ def init(): # This is non-windows, so we trust isatty. OUT_TYPE = 'pipe or file' - # Enable native ANSI color codes on Windows 10. - if IS_TTY and platform.release() == '10': - if enable_native_ansi(): + if IS_TTY and is_windows: + # Wrapping may cause errors on some Windows versions (crbug.com/1114548). + if platform.release() != '10' or enable_native_ansi(): should_wrap = False colorama.init(wrap=should_wrap)