-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_codebase.py
More file actions
40 lines (31 loc) · 1.23 KB
/
test_codebase.py
File metadata and controls
40 lines (31 loc) · 1.23 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
# test_codebase.py
from tools import file_operations
import json
def index_codebase(directory):
print(f"Indexing codebase in {directory}...")
# List all .py files
list_input = json.dumps({"action": "list", "file_path": directory})
list_result = file_operations.invoke(list_input)
if "Error" in list_result:
print(f"Failed to list files: {list_result}")
return
files = list_result.split(", ")
py_files = [f for f in files if f.endswith('.py')]
if not py_files:
print("No Python files found.")
return
print(f"Found Python files: {py_files}")
# Read and summarize each file
for py_file in py_files:
file_path = f"{directory}/{py_file}"
read_input = json.dumps({"action": "read", "file_path": file_path})
content = file_operations.invoke(read_input)
if "Error" in content:
print(f"Failed to read {py_file}: {content}")
continue
print(f"\nFile: {py_file}")
print(f"Content:\n{content}")
summary = f"Contains a {'function' if 'def' in content else 'script'}"
print(f"Summary: {summary}")
if __name__ == "__main__":
index_codebase("./my_project")