-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzer.py
More file actions
65 lines (45 loc) · 1.32 KB
/
Copy pathanalyzer.py
File metadata and controls
65 lines (45 loc) · 1.32 KB
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
from pathlib import Path
from cli.arguments import create_parser
from analysis.file_analysis import analyze_file
from analysis.duplicate_detection import detect_duplicates
from reporting.terminal import (
generate_codebase_summary,
generate_report,
)
from reporting.json_report import generate_json_report
def main():
parser = create_parser()
args = parser.parse_args()
p = Path(args.path)
if p.is_dir():
py_files = list(p.rglob("*.py"))
print(f"\nPython files: {len(py_files)}\n")
analyze_codebase(
py_files,
generate_json=args.json,
output_file=args.output,
)
else:
print("This is not a valid directory")
def analyze_codebase(
py_files,
generate_json=False,
output_file="codebase_report.json",
):
results = []
duplicates = detect_duplicates(py_files)
for file in py_files:
metrics = analyze_file(file)
# skipping files with syntax errors
if metrics is None:
continue
results.append(metrics)
print()
generate_report(metrics)
print()
generate_codebase_summary(results, duplicates)
print()
if generate_json:
generate_json_report(results, output_file, duplicates)
if __name__ == "__main__":
main()