generated from srijan-deepsource/custom-analyzer-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (25 loc) · 875 Bytes
/
main.py
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
import ast
import analyze
from helper import CODEPATH, ISSUES, get_files, prepare_result, publish_results, set_current_filepath
def run_analysis(filepath: str) -> None:
with open(filepath) as file:
source = file.read()
if hasattr(analyze, "analyze") and callable(analyze.analyze):
try:
tree = ast.parse(source)
analyze.analyze(tree)
except Exception:
pass
if hasattr(analyze, "analyze_source") and callable(analyze.analyze_source):
try:
analyze.analyze_source(source)
except Exception:
pass
if __name__ == "__main__":
for filepath in get_files(CODEPATH):
if not filepath.endswith(".py"):
continue
set_current_filepath(filepath)
run_analysis(filepath)
result = prepare_result(ISSUES)
publish_results(result)