-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscalpel_wrapper.py
43 lines (33 loc) · 1.27 KB
/
scalpel_wrapper.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
34
35
36
37
38
39
40
41
42
43
import json
import os
from scalpel.typeinfer.typeinfer import TypeInference
def list_python_files(folder_path):
python_files = []
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith(".py"):
python_files.append(os.path.join(root, file))
return python_files
folder_path = "../micro-benchmark/analysis_sensitivities/object_sensitivity"
python_files = list_python_files(folder_path)
for file in python_files:
print(file)
try:
json_file_path = file.replace(".py", "_gt.json")
if os.path.exists(json_file_path):
print(f"JSON file already exists: {json_file_path}")
continue
inferer = TypeInference(name=file, entry_point=file)
inferer.infer_types()
inferred = inferer.get_types()
print(inferred)
with open(json_file_path, "w") as json_file:
# json.dump(inferred, json_file)
inferred_serializable = [
{k: list(v) if isinstance(v, set) else v for k, v in d.items()}
for d in inferred
]
inferred_serializable.sort(key=lambda x: x["line_number"])
json.dump(inferred_serializable, json_file, indent=4)
except Exception as e:
print(e)