File tree 4 files changed +40
-10
lines changed
4 files changed +40
-10
lines changed Original file line number Diff line number Diff line change 1
1
from enum import Enum
2
2
from pathlib import Path
3
- from typing import Dict , ItemsView
3
+ from typing import Dict , ItemsView , KeysView
4
4
from pydantic import BaseModel
5
5
6
6
@@ -16,17 +16,24 @@ class RepoInstance(BaseModel):
16
16
def __getitem__ (self , item : str ):
17
17
return getattr (self , item )
18
18
19
+ def keys (self ) -> KeysView [str ]:
20
+ """Return the field names of the model as dictionary keys."""
21
+ return self .__annotations__ .keys ()
22
+
19
23
20
24
class SimpleInstance (BaseModel ):
21
25
instance_id : str
22
26
prompt : str
23
27
canonical_solution : str
24
28
test : str
25
- entry_point : str
26
29
27
30
def __getitem__ (self , item : str ):
28
31
return getattr (self , item )
29
32
33
+ def keys (self ) -> KeysView [str ]:
34
+ """Return the field names of the model as dictionary keys."""
35
+ return self .__annotations__ .keys ()
36
+
30
37
31
38
class Files (BaseModel ):
32
39
eval_script : Dict [str , Path ]
Original file line number Diff line number Diff line change 1
1
import git
2
2
import os
3
- import re
4
3
import sys
5
4
import traceback
6
5
from datasets import load_dataset
21
20
generate_patch_between_commits ,
22
21
setup_logger ,
23
22
close_logger ,
23
+ extract_code_blocks ,
24
24
)
25
25
from commit0 .harness .execution_context import (
26
26
ExecutionBackend ,
@@ -165,15 +165,13 @@ def main(
165
165
)
166
166
else :
167
167
solution = open (test_ids ).read ()
168
- pattern = r"```python\n(.*?)```"
169
- matches = re .finditer (pattern , solution , re .DOTALL )
170
- matches = [match .group (1 ).strip () for match in matches ]
168
+ prompt = example ["prompt" ] if "prompt" in example .keys () else ""
169
+ matches = extract_code_blocks (solution )
171
170
if len (matches ) > 0 :
172
171
solution = "\n \n " .join (matches )
173
172
else :
174
- solution = example [ " prompt" ] + "\n \n " + solution
173
+ solution = prompt + "\n \n " + solution
175
174
patch = solution + "\n \n " + example ["test" ]
176
- patch = patch + "\n \n " + f"check({ example ['entry_point' ]} )"
177
175
eval_script = spec .eval_script
178
176
179
177
patch_file = Path (log_dir / "patch.diff" )
Original file line number Diff line number Diff line change @@ -185,6 +185,7 @@ def make_repo_script_list(self) -> list[str]:
185
185
f"mkdir { self .repo_directory } && cd { self .repo_directory } " ,
186
186
"uv venv --python 3.12" ,
187
187
"source .venv/bin/activate" ,
188
+ "uv pip install -U pytest pytest-cov coverage pytest-json-report" ,
188
189
"which python" ,
189
190
]
190
191
return setup_commands
@@ -195,7 +196,7 @@ def make_eval_script_list(self) -> list[str]:
195
196
f"cd { self .repo_directory } " ,
196
197
"source .venv/bin/activate" ,
197
198
"cat /patch.diff > test.py" ,
198
- "uv run test.py > test_output.txt 2>&1" ,
199
+ "pytest test.py > test_output.txt 2>&1" ,
199
200
"echo $? > pytest_exit_code.txt" ,
200
201
]
201
202
return eval_script_list
Original file line number Diff line number Diff line change 4
4
import logging
5
5
import os
6
6
import time
7
+ import re
7
8
import sys
8
9
from pathlib import Path
9
- from typing import Optional , Union
10
+ from typing import List , Optional , Union
10
11
11
12
from fastcore .net import HTTP404NotFoundError , HTTP403ForbiddenError # type: ignore
12
13
from ghapi .core import GhApi
@@ -220,4 +221,27 @@ def get_active_branch(repo_path: Union[str, Path]) -> str:
220
221
return branch
221
222
222
223
224
+ def extract_code_blocks (text : str ) -> List [str ]:
225
+ """Extract Python code blocks from a given text wrapped in markdown markers.
226
+
227
+ This function identifies and extracts all Python code blocks within a provided
228
+ text. The code blocks should be surrounded by markdown-style markers, such as
229
+ ```python ... ```.
230
+
231
+ Args:
232
+ ----
233
+ text (str): The input text containing Python code blocks marked with
234
+ ```python ... ```.
235
+
236
+ Returns:
237
+ -------
238
+ List[str]: A list of strings, each containing a Python code block extracted
239
+ from the text.
240
+
241
+ """
242
+ pattern = r"```python\n(.*?)```"
243
+ matches = re .finditer (pattern , text , re .DOTALL )
244
+ return [match .group (1 ).strip () for match in matches ]
245
+
246
+
223
247
__all__ = []
You can’t perform that action at this time.
0 commit comments