forked from VimPlug/jedi
Debugging with more colors, yay.
This commit is contained in:
@@ -20,6 +20,7 @@ except ImportError:
|
|||||||
RED = ''
|
RED = ''
|
||||||
GREEN = ''
|
GREEN = ''
|
||||||
YELLOW = ''
|
YELLOW = ''
|
||||||
|
MAGENTA = ''
|
||||||
RESET = ''
|
RESET = ''
|
||||||
|
|
||||||
NOTICE = object()
|
NOTICE = object()
|
||||||
@@ -55,37 +56,45 @@ def increase_indent(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def dbg(message, *args):
|
def dbg(message, *args, **kwargs):
|
||||||
""" Looks at the stack, to see if a debug message should be printed. """
|
""" Looks at the stack, to see if a debug message should be printed. """
|
||||||
|
if kwargs:
|
||||||
|
# Python 2 compatibility, because it doesn't understand default args
|
||||||
|
# after *args.
|
||||||
|
color = kwargs.get('color')
|
||||||
|
if color is None:
|
||||||
|
raise TypeError("debug.dbg doesn't support more named arguments than color")
|
||||||
|
else:
|
||||||
|
color = 'GREEN'
|
||||||
|
|
||||||
if debug_function and enable_notice:
|
if debug_function and enable_notice:
|
||||||
frm = inspect.stack()[1]
|
frm = inspect.stack()[1]
|
||||||
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
|
||||||
debug_function(NOTICE, i + 'dbg: ' + message % tuple(u(repr(a)) for a in args))
|
debug_function(color, i + 'dbg: ' + message % tuple(u(repr(a)) for a in args))
|
||||||
|
|
||||||
|
|
||||||
def warning(message, *args):
|
def warning(message, *args):
|
||||||
if debug_function and enable_warning:
|
if debug_function and enable_warning:
|
||||||
i = ' ' * _debug_indent
|
i = ' ' * _debug_indent
|
||||||
debug_function(WARNING, i + 'warning: ' + message % tuple(u(repr(a)) for a in args))
|
debug_function('RED', i + 'warning: ' + message % tuple(u(repr(a)) for a in args))
|
||||||
|
|
||||||
|
|
||||||
def speed(name):
|
def speed(name):
|
||||||
if debug_function and enable_speed:
|
if debug_function and enable_speed:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
i = ' ' * _debug_indent
|
i = ' ' * _debug_indent
|
||||||
debug_function(SPEED, i + 'speed: ' + '%s %s' % (name, now - _start_time))
|
debug_function('YELLOW', i + 'speed: ' + '%s %s' % (name, now - _start_time))
|
||||||
|
|
||||||
|
|
||||||
def print_to_stdout(level, str_out):
|
def print_to_stdout(color, str_out):
|
||||||
""" The default debug function """
|
"""
|
||||||
if level == NOTICE:
|
The default debug function that prints to standard out.
|
||||||
col = Fore.GREEN
|
|
||||||
elif level == WARNING:
|
:param str color: A string that is an attribute of ``colorama.Fore``.
|
||||||
col = Fore.RED
|
"""
|
||||||
else:
|
col = getattr(Fore, color)
|
||||||
col = Fore.YELLOW
|
|
||||||
if not is_py3:
|
if not is_py3:
|
||||||
str_out = str_out.encode(encoding, 'replace')
|
str_out = str_out.encode(encoding, 'replace')
|
||||||
print(col + str_out + Fore.RESET)
|
print(col + str_out + Fore.RESET)
|
||||||
|
|||||||
@@ -55,13 +55,13 @@ def search_params(evaluator, param):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
func = param.get_parent_until(tree.Function)
|
func = param.get_parent_until(tree.Function)
|
||||||
debug.dbg('Dynamic param search for %s in %s.', param, str(func.name))
|
debug.dbg('Dynamic param search for %s in %s.', param, str(func.name), color='MAGENTA')
|
||||||
# Compare the param names.
|
# Compare the param names.
|
||||||
names = [n for n in search_function_call(evaluator, func)
|
names = [n for n in search_function_call(evaluator, func)
|
||||||
if n.value == param.name.value]
|
if n.value == param.name.value]
|
||||||
# Evaluate the ExecutedParams to types.
|
# Evaluate the ExecutedParams to types.
|
||||||
result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names))
|
result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names))
|
||||||
debug.dbg('Dynamic param result %s', result)
|
debug.dbg('Dynamic param result %s', result, color='MAGENTA')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -470,6 +470,7 @@ def check_array_additions(evaluator, array):
|
|||||||
|
|
||||||
|
|
||||||
@memoize_default([], evaluator_is_first_arg=True)
|
@memoize_default([], evaluator_is_first_arg=True)
|
||||||
|
@debug.increase_indent
|
||||||
def _check_array_additions(evaluator, compare_array, module, is_list):
|
def _check_array_additions(evaluator, compare_array, module, is_list):
|
||||||
"""
|
"""
|
||||||
Checks if a `Array` has "add" (append, insert, extend) statements:
|
Checks if a `Array` has "add" (append, insert, extend) statements:
|
||||||
@@ -477,7 +478,9 @@ def _check_array_additions(evaluator, compare_array, module, is_list):
|
|||||||
>>> a = [""]
|
>>> a = [""]
|
||||||
>>> a.append(1)
|
>>> a.append(1)
|
||||||
"""
|
"""
|
||||||
|
debug.dbg('Dynamic array search for %s' % compare_array, color='MAGENTA')
|
||||||
if not settings.dynamic_array_additions or isinstance(module, compiled.CompiledObject):
|
if not settings.dynamic_array_additions or isinstance(module, compiled.CompiledObject):
|
||||||
|
debug.dbg('Dynamic array search aborted.', color='MAGENTA')
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
def check_additions(arglist, add_name):
|
def check_additions(arglist, add_name):
|
||||||
@@ -564,6 +567,7 @@ def _check_array_additions(evaluator, compare_array, module, is_list):
|
|||||||
evaluator.recursion_detector.pop_stmt()
|
evaluator.recursion_detector.pop_stmt()
|
||||||
# reset settings
|
# reset settings
|
||||||
settings.dynamic_params_for_other_modules = temp_param_add
|
settings.dynamic_params_for_other_modules = temp_param_add
|
||||||
|
debug.dbg('Dynamic array result %s' % added_types, color='MAGENTA')
|
||||||
return added_types
|
return added_types
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user