Skip to content

Commit 4329a4d

Browse files
authored
Merge pull request #44 from commit-0/rebuild
Rebuild
2 parents b3a7d96 + b326139 commit 4329a4d

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

.github/workflows/system.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ jobs:
2525
- name: Get tests
2626
run: uv run commit0 get-tests simpy
2727
- name: Test
28-
run: uv run commit0 test simpy tests/test_event.py::test_succeed --reference
28+
env:
29+
MODAL_TOKEN_ID: ${{secrets.MODAL_TOKEN_ID}}
30+
MODAL_TOKEN_SECRET: ${{secrets.MODAL_TOKEN_SECRET}}
31+
run: |
32+
uv run commit0 test simpy tests/test_event.py::test_succeed --reference --rebuild
33+
uv run commit0 test simpy tests/test_event.py::test_succeed --reference
2934
- name: Evaluate
30-
run: uv run commit0 evaluate --reference
35+
env:
36+
MODAL_TOKEN_ID: ${{secrets.MODAL_TOKEN_ID}}
37+
MODAL_TOKEN_SECRET: ${{secrets.MODAL_TOKEN_SECRET}}
38+
run: |
39+
uv run commit0 evaluate --reference --rebuild
40+
uv run commit0 evaluate --reference
3141
- name: Lint
3242
run: uv run commit0 lint commit0/harness/lint.py
3343
- name: Save

commit0/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ def test(
222222
reference: Annotated[
223223
bool, typer.Option("--reference", help="Test the reference commit.")
224224
] = False,
225+
rebuild: bool = typer.Option(
226+
False, "--rebuild", help="Whether to rebuild an image"
227+
),
225228
commit0_dot_file_path: str = typer.Option(
226229
".commit0.yaml",
227230
help="Path to the commit0 dot file, where the setup config is stored",
@@ -266,6 +269,7 @@ def test(
266269
backend,
267270
timeout,
268271
num_cpus,
272+
rebuild,
269273
verbose,
270274
)
271275

@@ -286,6 +290,7 @@ def evaluate(
286290
".commit0.yaml",
287291
help="Path to the commit0 dot file, where the setup config is stored",
288292
),
293+
rebuild: bool = typer.Option(False, "--rebuild", help="Whether to rebuild images"),
289294
) -> None:
290295
"""Evaluate Commit0 split you choose in Setup Stage."""
291296
check_commit0_path()
@@ -314,6 +319,7 @@ def evaluate(
314319
timeout,
315320
num_cpus,
316321
num_workers,
322+
rebuild,
317323
)
318324

319325

commit0/harness/evaluate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def main(
2828
timeout: int,
2929
num_cpus: int,
3030
num_workers: int,
31+
rebuild_image: bool,
3132
) -> None:
3233
dataset: Iterator[RepoInstance] = load_dataset(dataset_name, split=dataset_split) # type: ignore
3334
repos = SPLIT[repo_split]
@@ -57,6 +58,7 @@ def main(
5758
backend,
5859
timeout,
5960
num_cpus,
61+
rebuild_image=rebuild_image,
6062
verbose=0,
6163
): None
6264
for repo, test_dir in pairs

commit0/harness/execution_context.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(
4444
log_dir: Path,
4545
files_to_copy: Optional[Files] = None,
4646
files_to_collect: Optional[list[str]] = None,
47+
rebuild_image: bool = False,
4748
):
4849
"""Create the remote execution context
4950
@@ -85,6 +86,7 @@ def __init__(
8586
log_dir: Path,
8687
files_to_copy: Optional[Files] = None,
8788
files_to_collect: Optional[list[str]] = None,
89+
rebuild_image: bool = False,
8890
):
8991
super().__init__(
9092
spec,
@@ -145,6 +147,7 @@ def __init__(
145147
log_dir: Path,
146148
files_to_copy: Optional[Files] = None,
147149
files_to_collect: Optional[list[str]] = None,
150+
rebuild_image: bool = False,
148151
):
149152
super().__init__(
150153
spec,
@@ -161,7 +164,7 @@ def __init__(
161164
# the image must exist on dockerhub
162165
reponame = spec.repo.split("/")[-1]
163166
image_name = f"wentingzhao/{reponame}:latest".lower()
164-
image = modal.Image.from_registry(image_name)
167+
image = modal.Image.from_registry(image_name, force_build=rebuild_image)
165168
if files_to_copy:
166169
for _, f in files_to_copy.items():
167170
image = image.copy_local_file(f["src"], f["dest"]) # type: ignore
@@ -175,9 +178,8 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
175178
command += " && "
176179
for fname in self.files_to_collect:
177180
remote_file = Path(self.spec.repo_directory) / fname
178-
cp_cmd = f"cp {str(remote_file)} /vol/{fname} 2>/dev/null; "
181+
cp_cmd = f"test -e {str(remote_file)} && cp {str(remote_file)} /vol/{fname}; "
179182
command += cp_cmd
180-
181183
self.sandbox = modal.Sandbox.create(
182184
"bash",
183185
"-c",
@@ -198,7 +200,9 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
198200
timed_out = False
199201

200202
if self.files_to_collect:
201-
for fname in self.files_to_collect:
203+
fnames = vol.listdir("")
204+
for fname in fnames:
205+
fname = fname.path
202206
with (self.log_dir / fname).open("wb") as f:
203207
for data in vol.read_file(fname):
204208
f.write(data)

commit0/harness/run_pytest_ids.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def main(
3737
backend: str,
3838
timeout: int,
3939
num_cpus: int,
40+
rebuild_image: bool,
4041
verbose: int,
4142
) -> None:
4243
"""Runs the pytests for repos in a dataset.
@@ -125,7 +126,14 @@ def main(
125126

126127
try:
127128
with execution_context(
128-
spec, logger, timeout, num_cpus, log_dir, files_to_copy, files_to_collect
129+
spec,
130+
logger,
131+
timeout,
132+
num_cpus,
133+
log_dir,
134+
files_to_copy,
135+
files_to_collect,
136+
rebuild_image,
129137
) as context:
130138
output, timed_out, total_runtime = context.exec_run_with_timeout(
131139
"/bin/bash /eval.sh"

0 commit comments

Comments
 (0)