FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pre-commit-hooks/pre_commit_hooks/debug_statement_hook.py at main · pre-commit/pre-commit-hooks · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pre-commit
/
pre-commit-hooks
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
798
Star
6.7k
Code
Issues
6
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
pre-commit-hooks
/
pre_commit_hooks
/
debug_statement_hook.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (66 loc) · 2.17 KB
Breadcrumbs
pre-commit-hooks
/
pre_commit_hooks
/
debug_statement_hook.py
Copy path
File metadata and controls
86 lines (66 loc) · 2.17 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
from
__future__
import
annotations
import
argparse
import
ast
import
traceback
from
collections
.
abc
import
Sequence
from
typing
import
NamedTuple
DEBUG_STATEMENTS
=
{
'bpdb'
,
'ipdb'
,
'pdb'
,
'pdbr'
,
'pudb'
,
'pydevd_pycharm'
,
'q'
,
'rdb'
,
'rpdb'
,
'wdb'
,
}
class
Debug
(
NamedTuple
):
line
:
int
col
:
int
name
:
str
reason
:
str
class
DebugStatementParser
(
ast
.
NodeVisitor
):
def
__init__
(
self
)
->
None
:
self
.
breakpoints
:
list
[
Debug
]
=
[]
def
visit_Import
(
self
,
node
:
ast
.
Import
)
->
None
:
for
name
in
node
.
names
:
if
name
.
name
in
DEBUG_STATEMENTS
:
st
=
Debug
(
node
.
lineno
,
node
.
col_offset
,
name
.
name
,
'imported'
)
self
.
breakpoints
.
append
(
st
)
def
visit_ImportFrom
(
self
,
node
:
ast
.
ImportFrom
)
->
None
:
if
node
.
module
in
DEBUG_STATEMENTS
:
st
=
Debug
(
node
.
lineno
,
node
.
col_offset
,
node
.
module
,
'imported'
)
self
.
breakpoints
.
append
(
st
)
def
visit_Call
(
self
,
node
:
ast
.
Call
)
->
None
:
"""python3.7+ breakpoint()"""
if
isinstance
(
node
.
func
,
ast
.
Name
)
and
node
.
func
.
id
==
'breakpoint'
:
st
=
Debug
(
node
.
lineno
,
node
.
col_offset
,
node
.
func
.
id
,
'called'
)
self
.
breakpoints
.
append
(
st
)
self
.
generic_visit
(
node
)
def
check_file
(
filename
:
str
)
->
int
:
try
:
with
open
(
filename
,
'rb'
)
as
f
:
ast_obj
=
ast
.
parse
(
f
.
read
(),
filename
=
filename
)
except
SyntaxError
:
print
(
f'
{
filename
}
- Could not parse ast'
)
print
()
print
(
'
\t
'
+
traceback
.
format_exc
().
replace
(
'
\n
'
,
'
\n
\t
'
))
print
()
return
1
visitor
=
DebugStatementParser
()
visitor
.
visit
(
ast_obj
)
for
bp
in
visitor
.
breakpoints
:
print
(
f'
{
filename
}
:
{
bp
.
line
}
:
{
bp
.
col
}
:
{
bp
.
name
}
{
bp
.
reason
}
'
)
return
int
(
bool
(
visitor
.
breakpoints
))
def
main
(
argv
:
Sequence
[
str
]
|
None
=
None
)
->
int
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'filenames'
,
nargs
=
'*'
,
help
=
'Filenames to run'
)
args
=
parser
.
parse_args
(
argv
)
retv
=
0
for
filename
in
args
.
filenames
:
retv
|=
check_file
(
filename
)
return
retv
if
__name__
==
'__main__'
:
raise
SystemExit
(
main
())
Back
|
FazBrowse Home
|
New Git URL