FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/pythonFiles/jedi/debug.py at master · rjshaver/pythonVSCode · GitHub
rjshaver
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
pythonFiles
/
jedi
/
debug.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
115 lines (92 loc) · 3.03 KB
Breadcrumbs
pythonVSCode
/
pythonFiles
/
jedi
/
debug.py
Copy path
File metadata and controls
115 lines (92 loc) · 3.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from
jedi
.
_compatibility
import
encoding
,
is_py3
,
u
import
inspect
import
os
import
time
def
_lazy_colorama_init
():
"""lazily init colorama if necessary, not to screw up stdout is debug not enabled.
This version of the function does nothing.
"""
pass
_inited
=
False
try
:
if
os
.
name
==
'nt'
:
# does not work on Windows, as pyreadline and colorama interfere
raise
ImportError
else
:
# Use colorama for nicer console output.
from
colorama
import
Fore
,
init
from
colorama
import
initialise
def
_lazy_colorama_init
():
"""lazily init colorama if necessary, not to screw up stdout is debug not enabled.
This version of the function does init colorama.
"""
global
_inited
if
not
_inited
:
# pytest resets the stream at the end - causes troubles. Since after
# every output the stream is reset automatically we don't need this.
initialise
.
atexit_done
=
True
init
()
_inited
=
True
except
ImportError
:
class
Fore
(
object
):
RED
=
''
GREEN
=
''
YELLOW
=
''
RESET
=
''
NOTICE
=
object
()
WARNING
=
object
()
SPEED
=
object
()
enable_speed
=
False
enable_warning
=
False
enable_notice
=
False
# callback, interface: level, str
debug_function
=
None
ignored_modules
=
[
'jedi.evaluate.builtin'
,
'jedi.parser'
]
_debug_indent
=
-
1
_start_time
=
time
.
time
()
def
reset_time
():
global
_start_time
,
_debug_indent
_start_time
=
time
.
time
()
_debug_indent
=
-
1
def
increase_indent
(
func
):
"""Decorator for makin """
def
wrapper
(
*
args
,
**
kwargs
):
global
_debug_indent
_debug_indent
+=
1
try
:
result
=
func
(
*
args
,
**
kwargs
)
finally
:
_debug_indent
-=
1
return
result
return
wrapper
def
dbg
(
message
,
*
args
):
""" Looks at the stack, to see if a debug message should be printed. """
if
debug_function
and
enable_notice
:
frm
=
inspect
.
stack
()[
1
]
mod
=
inspect
.
getmodule
(
frm
[
0
])
if
not
(
mod
.
__name__
in
ignored_modules
):
i
=
' '
*
_debug_indent
_lazy_colorama_init
()
debug_function
(
NOTICE
,
i
+
'dbg: '
+
message
%
tuple
(
u
(
repr
(
a
))
for
a
in
args
))
def
warning
(
message
,
*
args
):
if
debug_function
and
enable_warning
:
i
=
' '
*
_debug_indent
debug_function
(
WARNING
,
i
+
'warning: '
+
message
%
tuple
(
u
(
repr
(
a
))
for
a
in
args
))
def
speed
(
name
):
if
debug_function
and
enable_speed
:
now
=
time
.
time
()
i
=
' '
*
_debug_indent
debug_function
(
SPEED
,
i
+
'speed: '
+
'%s %s'
%
(
name
,
now
-
_start_time
))
def
print_to_stdout
(
level
,
str_out
):
""" The default debug function """
_lazy_colorama_init
()
if
level
==
NOTICE
:
col
=
Fore
.
GREEN
elif
level
==
WARNING
:
col
=
Fore
.
RED
else
:
col
=
Fore
.
YELLOW
if
not
is_py3
:
str_out
=
str_out
.
encode
(
encoding
,
'replace'
)
print
(
col
+
str_out
+
Fore
.
RESET
)
# debug_function = print_to_stdout
Back
|
FazBrowse Home
|
New Git URL