1
1
import logging
2
2
import os
3
3
import subprocess
4
- from functools import partial
5
4
6
5
import hydra
7
6
from datasets import load_dataset
8
7
from omegaconf import OmegaConf
9
- from tqdm .contrib .concurrent import thread_map
10
8
import tarfile
11
9
from baselines .baseline_utils import (
12
10
get_message_to_aider ,
13
11
get_target_edit_files_cmd_args ,
14
12
)
15
13
from baselines .class_types import AiderConfig , BaselineConfig , Commit0Config
16
-
14
+ from commit0 . harness . constants import SPLIT
17
15
# from aider.run_aider import get_aider_cmd
18
16
19
17
logging .basicConfig (
@@ -27,11 +25,16 @@ def get_aider_cmd(
27
25
files : str ,
28
26
message_to_aider : str ,
29
27
test_cmd : str ,
28
+ lint_cmd : str ,
30
29
) -> str :
31
30
"""Get the Aider command based on the given context."""
32
- aider_cmd = f"aider --model { model } --file { files } --message \" { message_to_aider } \" --auto-test --test --test-cmd '{ test_cmd } ' --yes"
33
-
34
- return aider_cmd
31
+ base_cmd = f'aider --model { model } --file { files } --message "{ message_to_aider } "'
32
+ if lint_cmd :
33
+ base_cmd += f" --auto-lint --lint-cmd '{ lint_cmd } '"
34
+ if test_cmd :
35
+ base_cmd += f" --auto-test --test --test-cmd '{ test_cmd } '"
36
+ base_cmd += " --yes"
37
+ return base_cmd
35
38
36
39
37
40
def run_aider_for_repo (
@@ -61,29 +64,39 @@ def run_aider_for_repo(
61
64
62
65
repo_path = os .path .join (commit0_config .base_dir , repo_name )
63
66
67
+ os .chdir (repo_path )
68
+
64
69
target_edit_files_cmd_args = get_target_edit_files_cmd_args (repo_path )
65
70
66
71
message_to_aider = get_message_to_aider (
67
72
aider_config , target_edit_files_cmd_args , repo_path , ds
68
73
)
69
74
70
- test_files = test_files [:1 ]
75
+ if aider_config .use_lint_info :
76
+ lint_cmd = "pre-commit run --config ../../.pre-commit-config.yaml --files"
77
+ else :
78
+ lint_cmd = ""
79
+
71
80
for test_file in test_files :
72
- test_cmd = f"uv run commit0 test-reference { repo_name } { test_file } "
81
+ test_cmd = f"python -m commit0 test { repo_name } { test_file } "
73
82
74
83
aider_cmd = get_aider_cmd (
75
84
aider_config .llm_name ,
76
85
target_edit_files_cmd_args ,
77
86
message_to_aider ,
78
87
test_cmd ,
88
+ lint_cmd ,
79
89
)
80
90
81
- print (aider_cmd )
82
-
83
91
try :
84
- process = subprocess .Popen (aider_cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE , universal_newlines = True )
92
+ process = subprocess .Popen (
93
+ aider_cmd ,
94
+ shell = True ,
95
+ stdout = subprocess .PIPE ,
96
+ stderr = subprocess .PIPE ,
97
+ universal_newlines = True ,
98
+ )
85
99
stdout , stderr = process .communicate ()
86
- results = process .returncode
87
100
logger .info (f"STDOUT: { stdout } " )
88
101
logger .info (f"STDERR: { stderr } " )
89
102
except subprocess .CalledProcessError as e :
@@ -97,6 +110,7 @@ def run_aider_for_repo(
97
110
logger .error (f"Command: { '' .join (aider_cmd )} " )
98
111
else :
99
112
logger .error (f"OSError occurred: { e } " )
113
+ asdf
100
114
101
115
102
116
@hydra .main (version_base = None , config_path = "config" , config_name = "aider" )
@@ -114,13 +128,15 @@ def main(config: BaselineConfig) -> None:
114
128
115
129
dataset = load_dataset (commit0_config .dataset_name , split = "test" )
116
130
117
- dataset = [dataset [3 ]]
118
- thread_map (
119
- partial (run_aider_for_repo , commit0_config , aider_config ),
120
- dataset ,
121
- desc = "Running aider for repos" ,
122
- max_workers = 10 ,
123
- )
131
+ filtered_dataset = [
132
+ example
133
+ for example in dataset
134
+ if commit0_config .repo_split == "all"
135
+ or example ["repo" ].split ("/" )[- 1 ] in SPLIT .get (commit0_config .repo_split , [])
136
+ ]
137
+
138
+ for example in filtered_dataset :
139
+ run_aider_for_repo (commit0_config , aider_config , example )
124
140
125
141
126
142
if __name__ == "__main__" :
0 commit comments