]>
crepu.dev Git - config.git/blob - djavu-asus/emacs/elpy/rpc-venv/lib/python3.11/site-packages/jedi/debug.py
3 from contextlib
import contextmanager
4 from typing
import Callable
, Optional
9 def _lazy_colorama_init():
11 Lazily init colorama if necessary, not to screw up stdout if debugging is
14 This version of the function does nothing.
20 # Does not work on Windows, as pyreadline and colorama interfere
23 # Use colorama for nicer console output.
24 from colorama
import Fore
, init
# type: ignore[import]
25 from colorama
import initialise
27 def _lazy_colorama_init(): # noqa: F811
29 Lazily init colorama if necessary, not to screw up stdout is
32 This version of the function does init colorama.
36 # pytest resets the stream at the end - causes troubles. Since
37 # after every output the stream is reset automatically we don't
39 initialise
.atexit_done
= True
43 # Colorama fails with initializing under vim and is buggy in
49 class Fore
: # type: ignore[no-redef]
62 enable_warning
= False
65 # callback, interface: level, str
66 debug_function
: Optional
[Callable
[[str, str], None]] = None
68 _start_time
= time
.time()
72 global _start_time
, _debug_indent
73 _start_time
= time
.time()
77 def increase_indent(func
):
78 """Decorator for makin """
79 def wrapper(*args
, **kwargs
):
80 with
increase_indent_cm():
81 return func(*args
, **kwargs
)
86 def increase_indent_cm(title
=None, color
='MAGENTA'):
89 dbg('Start: ' + title
, color
=color
)
96 dbg('End: ' + title
, color
=color
)
99 def dbg(message
, *args
, color
='GREEN'):
100 """ Looks at the stack, to see if a debug message should be printed. """
103 if debug_function
and enable_notice
:
104 i
= ' ' * _debug_indent
105 _lazy_colorama_init()
106 debug_function(color
, i
+ 'dbg: ' + message
% tuple(repr(a
) for a
in args
))
109 def warning(message
, *args
, format
=True):
110 if debug_function
and enable_warning
:
111 i
= ' ' * _debug_indent
113 message
= message
% tuple(repr(a
) for a
in args
)
114 debug_function('RED', i
+ 'warning: ' + message
)
118 if debug_function
and enable_speed
:
120 i
= ' ' * _debug_indent
121 debug_function('YELLOW', i
+ 'speed: ' + '%s %s' % (name
, now
- _start_time
))
124 def print_to_stdout(color
, str_out
):
126 The default debug function that prints to standard out.
128 :param str color: A string that is an attribute of ``colorama.Fore``.
130 col
= getattr(Fore
, color
)
131 _lazy_colorama_init()
132 print(col
+ str_out
+ Fore
.RESET
)