1
0
forked from VimPlug/jedi

Initialize colorama lazily

Will prevent colorama from wrapping stderr/out if not in debug mode,
which leads to some errors.
This commit is contained in:
Matthias Bussonnier
2016-05-17 16:46:45 -07:00
parent 6266678064
commit 4ba6000f92

View File

@@ -3,6 +3,11 @@ import inspect
import os import os
import time import time
def _lazy_colorama_init():
pass
_inited=False
try: try:
if os.name == 'nt': if os.name == 'nt':
# does not work on Windows, as pyreadline and colorama interfere # does not work on Windows, as pyreadline and colorama interfere
@@ -13,8 +18,13 @@ try:
from colorama import initialise from colorama import initialise
# pytest resets the stream at the end - causes troubles. Since after # pytest resets the stream at the end - causes troubles. Since after
# every output the stream is reset automatically we don't need this. # every output the stream is reset automatically we don't need this.
initialise.atexit_done = True def _lazy_colorama_init():
init() global _inited
if not _inited:
initialise.atexit_done = True
init()
_inited = True
except ImportError: except ImportError:
class Fore(object): class Fore(object):
RED = '' RED = ''
@@ -63,6 +73,7 @@ def dbg(message, *args):
mod = inspect.getmodule(frm[0]) mod = inspect.getmodule(frm[0])
if not (mod.__name__ in ignored_modules): if not (mod.__name__ in ignored_modules):
i = ' ' * _debug_indent i = ' ' * _debug_indent
_lazy_colorama_init()
debug_function(NOTICE, i + 'dbg: ' + message % tuple(u(repr(a)) for a in args)) debug_function(NOTICE, i + 'dbg: ' + message % tuple(u(repr(a)) for a in args))
@@ -81,6 +92,7 @@ def speed(name):
def print_to_stdout(level, str_out): def print_to_stdout(level, str_out):
""" The default debug function """ """ The default debug function """
_lazy_colorama_init()
if level == NOTICE: if level == NOTICE:
col = Fore.GREEN col = Fore.GREEN
elif level == WARNING: elif level == WARNING: