forked from harrischristiansen/generals-bot
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathparse_function_mappings.py
More file actions
64 lines (52 loc) · 2.3 KB
/
parse_function_mappings.py
File metadata and controls
64 lines (52 loc) · 2.3 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
#!/usr/bin/env python3
"""
Parse git diff to extract function mappings and create an optimized checker.
"""
import re
from pathlib import Path
def parse_function_mappings():
"""Parse the git diff to extract function -> module mappings."""
mappings = {}
with open('git_diff_detailed.txt', 'r', encoding='utf-8') as f:
lines = f.readlines()
i = 0
while i < len(lines):
line = lines[i].strip()
# Look for removed function definitions
if line.startswith('- def '):
func_name = line.replace('- def ', '').split('(')[0]
# Look at the next few lines for the return statement
j = i + 1
while j < len(lines) and j < i + 5: # Check next 5 lines max
next_line = lines[j].strip()
if 'return ' in next_line and '.' in next_line:
# Extract module and function from return statement
# Pattern: return ModuleName.function_name(self, ...)
match = re.search(r'return (\w+)\.(\w+)\(self', next_line)
if match:
module = match.group(1)
mappings[func_name] = {
'module': module,
'target_function': match.group(2),
'return_line': next_line.strip()
}
break
j += 1
i += 1
return mappings
def write_function_mappings():
"""Write the function mappings to files."""
mappings = parse_function_mappings()
# Write just function names (for backwards compatibility)
with open('removed_functions_clean.txt', 'w', encoding='utf-8') as f:
for func_name in sorted(mappings.keys()):
f.write(f"{func_name}\n")
# Write detailed mappings
with open('function_mappings.txt', 'w', encoding='utf-8') as f:
f.write("function_name,module_name,target_function,return_line\n")
for func_name, info in sorted(mappings.items()):
f.write(f"{func_name},{info['module']},{info['target_function']},\"{info['return_line']}\"\n")
print(f"Parsed {len(mappings)} function mappings")
return mappings
if __name__ == "__main__":
write_function_mappings()