Commit 6f9b1bfd authored by Jesse McKenna's avatar Jesse McKenna Committed by LUCI CQ

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/+/2485882Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
parent f28949d6
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment