Skip to content

Commit 4094617

Browse files
committed
pre-commit
1 parent f4ff2d0 commit 4094617

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

commit0/harness/execution_context.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
from commit0.harness.constants import Files
1919
from commit0.harness.spec import Spec
20-
from commit0.harness.utils import (
21-
EvaluationError,
22-
)
2320
from commit0.harness.docker_build import (
2421
close_logger,
2522
)
@@ -46,7 +43,7 @@ def __init__(
4643
num_cpus: int,
4744
log_dir: Path,
4845
files_to_copy: Optional[Files] = None,
49-
files_to_collect: Optional[Files] = None,
46+
files_to_collect: Optional[list[str]] = None,
5047
):
5148
"""Create the remote execution context
5249
@@ -87,9 +84,17 @@ def __init__(
8784
num_cpus: int,
8885
log_dir: Path,
8986
files_to_copy: Optional[Files] = None,
90-
files_to_collect: Optional[Files] = None,
87+
files_to_collect: Optional[list[str]] = None,
9188
):
92-
super().__init__(spec, logger, timeout, num_cpus, log_dir, files_to_copy=files_to_copy, files_to_collect=files_to_collect)
89+
super().__init__(
90+
spec,
91+
logger,
92+
timeout,
93+
num_cpus,
94+
log_dir,
95+
files_to_copy=files_to_copy,
96+
files_to_collect=files_to_collect,
97+
)
9398

9499
self.client = docker.from_env()
95100
self.container = create_container(
@@ -108,18 +113,16 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
108113
"""Exec"""
109114
output = exec_run_with_timeout(self.container, command, self.timeout)
110115

111-
for fname in self.files_to_collect:
112-
# copy back report.json if there is any
113-
file = Path(self.spec.repo_directory) / fname
114-
# Run the test command inside the container to check if the file exists
115-
exit_code, test_output = self.container.exec_run(
116-
f"test -e {file}", demux=True
117-
)
118-
# Check the exit code of the command
119-
if exit_code == 0:
120-
copy_from_container(
121-
self.container, file, self.log_dir / fname
116+
if self.files_to_collect:
117+
for fname in self.files_to_collect:
118+
file = Path(self.spec.repo_directory) / fname
119+
# Run the test command inside the container to check if the file exists
120+
exit_code, test_output = self.container.exec_run(
121+
f"test -e {file}", demux=True
122122
)
123+
# Check the exit code of the command
124+
if exit_code == 0:
125+
copy_from_container(self.container, file, self.log_dir / fname)
123126
return output
124127

125128
def __exit__(
@@ -141,9 +144,17 @@ def __init__(
141144
num_cpus: int,
142145
log_dir: Path,
143146
files_to_copy: Optional[Files] = None,
144-
files_to_collect: Optional[Files] = None,
147+
files_to_collect: Optional[list[str]] = None,
145148
):
146-
super().__init__(spec, logger, timeout, num_cpus, log_dir, files_to_copy=files_to_copy, files_to_collect=files_to_collect)
149+
super().__init__(
150+
spec,
151+
logger,
152+
timeout,
153+
num_cpus,
154+
log_dir,
155+
files_to_copy=files_to_copy,
156+
files_to_collect=files_to_collect,
157+
)
147158

148159
self.app = modal.App()
149160

@@ -161,10 +172,11 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
161172
start_time = time.time()
162173
with modal.Volume.ephemeral() as vol:
163174
cp_cmd = ""
164-
for fname in self.files_to_collect:
165-
remote_file = Path(self.spec.repo_directory) / fname
166-
curr_cp_cmd = f" && cp {str(remote_file)} /vol/{fname} 2>/dev/null"
167-
cp_cmd += curr_cp_cmd
175+
if self.files_to_collect:
176+
for fname in self.files_to_collect:
177+
remote_file = Path(self.spec.repo_directory) / fname
178+
curr_cp_cmd = f" && cp {str(remote_file)} /vol/{fname} 2>/dev/null"
179+
cp_cmd += curr_cp_cmd
168180

169181
command += cp_cmd
170182
self.sandbox = modal.Sandbox.create(
@@ -186,10 +198,11 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
186198
else:
187199
timed_out = False
188200

189-
for fname in self.files_to_collect:
190-
with (self.log_dir / fname).open("wb") as f:
191-
for data in vol.read_file(fname):
192-
f.write(data)
201+
if self.files_to_collect:
202+
for fname in self.files_to_collect:
203+
with (self.log_dir / fname).open("wb") as f:
204+
for data in vol.read_file(fname):
205+
f.write(data)
193206

194207
self.sandbox.terminate()
195208
end_time = time.time()

commit0/harness/run_pytest_ids.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from commit0.harness.spec import make_spec
1919
from commit0.harness.utils import (
2020
EvaluationError,
21-
extract_test_output,
2221
get_hash_string,
2322
generate_patch_between_commits,
2423
)
@@ -114,7 +113,12 @@ def main(
114113
eval_script={"src": eval_file, "dest": Path("/eval.sh")},
115114
patch={"src": patch_file, "dest": Path("/patch.diff")},
116115
)
117-
files_to_collect = ["report.json", "coverage.json", "pytest_exit_code.txt", "test_output.txt"]
116+
files_to_collect = [
117+
"report.json",
118+
"coverage.json",
119+
"pytest_exit_code.txt",
120+
"test_output.txt",
121+
]
118122

119123
try:
120124
with execution_context(
@@ -125,9 +129,9 @@ def main(
125129
)
126130
if timed_out:
127131
raise EvaluationError(
128-
self.spec.repo,
132+
repo_name,
129133
f"Test timed out after {timeout} seconds.",
130-
self.logger,
134+
logger,
131135
)
132136
pytest_exit_code = Path(log_dir / "pytest_exit_code.txt").read_text().strip()
133137
sys.exit(pytest_exit_code)

0 commit comments

Comments
 (0)