-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
74 lines (58 loc) · 3.87 KB
/
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
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
66
67
68
69
70
71
72
73
74
import argparse
from src.capr import Capr
from src.cigar import CigaR
from src.chatgpt import ChatGPT
from src.framework import Framework
from src.analysis import Analysis
from prog_params import ProgParams as prog_params
from user_params import UserParams as user_params
def main(framework=None, project=None, bug_ids=None, repair_tool=None):
defects4j = Framework(name="defects4j", list_of_bugs = prog_params.d4j_list_of_bugs,
d4j_path=user_params.D4J_PATH, java_home=user_params.JAVA_HOME, tmp_dir=user_params.TMP_DIR,
validate_patch_cache_folder=prog_params.validate_patch_cache_folder,
n_shot_cache_folder=prog_params.n_shot_cache_folder,
bug_details_cache_folder=prog_params.bug_details_cache_folder)
#humanevaljava = Framework(name="humanevaljava", # TODO add human eval java framework
# list_of_bugs=prog_params.humaneval_list_of_bugs,
# d4j_path=user_params.HUMANEVAL_PATH,
# java_home=user_params.JAVA_HOME,
# tmp_dir=user_params.TMP_DIR,
# validate_patch_cache_folder=prog_params.validate_patch_cache_folder,
# n_shot_cache_folder=prog_params.n_shot_cache_folder,
# bug_details_cache_folder=prog_params.bug_details_cache_folder)
chatgpt = ChatGPT(model=prog_params.gpt35_model, api_key=user_params.API_KEY,
cache_folder=prog_params.gpt35_cache_folder,
load_from_cache=True, save_to_cache=True)
frameworks = [defects4j]
if framework is not None:
frameworks = [f for f in frameworks if f.name == framework]
for test_framework in frameworks:
capr = Capr(chatgpt=chatgpt, framework=test_framework)
cigar = CigaR(chatgpt=chatgpt, framework=test_framework)
aprs = [capr, cigar]
if repair_tool is not None:
aprs = [apr for apr in aprs if apr.name.lower() == repair_tool]
for apr in aprs:
if project is not None and bug_ids is not None:
list_of_bugs_to_fix = [(project, bug_ids)]
elif project is not None:
if test_framework.name == "defects4j":
list_of_bugs_to_fix = [(project, [ids for proj, ids in prog_params.d4j_list_of_bugs if proj == project][0])]
elif test_framework.name == "humanevaljava":
list_of_bugs_to_fix = [(project, [ids for proj, ids in prog_params.humaneval_list_of_bugs if proj == project][0])]
else:
if test_framework.name == "defects4j":
list_of_bugs_to_fix = prog_params.d4j_list_of_bugs
elif test_framework.name == "humanevaljava":
list_of_bugs_to_fix = prog_params.humaneval_list_of_bugs
analysis = Analysis(apr=apr, framework=test_framework)
analysis.run(list_of_bugs_to_fix)
if __name__ == '__main__':
project_choices = [p for p, _ in prog_params.d4j_list_of_bugs] + ["humaneval"]
parser = argparse.ArgumentParser(description='Run CAPR on D4J Bugs')
parser.add_argument('-fr', '--framework', metavar='path', required=False, help='Framework to use', choices=['defects4j'])
parser.add_argument('-p', '--proj', metavar='path', required=False, help='Project name', choices=project_choices)
parser.add_argument('-bs', '--bug_ids', metavar='path', required=False, help='List of bug_ids to repair', nargs='+')
parser.add_argument('-apr', '--repair_tool', metavar='path', required=False, help='APR algorithms to use', choices=['capr', 'cigar'])
args = parser.parse_args()
main(framework=args.framework, project=args.proj, bug_ids=args.bug_ids, repair_tool=args.repair_tool)