Skip to content

Commit 0b998b7

Browse files
pre-commit
1 parent 48b3768 commit 0b998b7

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

commit0/harness/modal_utils.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
""" Modal utility functions
1+
"""Modal utility functions
22
33
A mirror of the docker utility functions.
44
"""
55

66
import modal
77
import os
8+
from pathlib import Path
89

9-
from commit0.harness.docker_utils import HEREDOC_DELIMITER
1010

11-
12-
def create_sandbox(image: modal.Image, nfs: model.NetworkFileSystem) -> modal.Sandbox:
11+
def create_sandbox(image: modal.Image, nfs: modal.NetworkFileSystem) -> modal.Sandbox:
12+
"""Create modal sandbox"""
1313
return modal.Sandbox.create(
1414
"sleep",
1515
"infinity",
@@ -20,7 +20,10 @@ def create_sandbox(image: modal.Image, nfs: model.NetworkFileSystem) -> modal.Sa
2020
)
2121

2222

23-
def execute_command(sandbox: modal.Sandbox, command: str, timeout=) -> tuple[str,str]:
23+
def execute_command(
24+
sandbox: modal.Sandbox, command: str, timeout: int = 90
25+
) -> tuple[str, str]:
26+
"""Execute command on modal sandbox"""
2427
process = sandbox.exec("bash", "-c", command)
2528
stdout = []
2629
for line in process.stdout:
@@ -31,21 +34,27 @@ def execute_command(sandbox: modal.Sandbox, command: str, timeout=) -> tuple[str
3134
return "\n".join(stdout), "\n".join(stderr)
3235

3336

34-
def copy_file_to_sandbox(sandbox: modal.Sandbox, nfs: modal.NetworkFileSystem, src: Path, dst: Path) -> None:
37+
def copy_file_to_sandbox(
38+
sandbox: modal.Sandbox, nfs: modal.NetworkFileSystem, src: Path, dst: Path
39+
) -> None:
40+
"""Copy file to modal sandbox"""
3541
with src.open("rb") as f:
3642
nfs.write_file(str(src), f)
3743
sandbox.exec("bash", "-c", f"cp /vol/{str(src)} {str(dst)}")
3844

3945

4046
def copy_from_sandbox(sandbox: modal.Sandbox, src: Path, dst: Path) -> None:
47+
"""Copy file from sandbox"""
4148
pass
4249

4350

4451
def delete_file_from_sandbox(sandbox: modal.Sandbox, file_path: str) -> None:
52+
"""Delete file on sandbox"""
4553
pass
4654

4755

4856
def copy_ssh_pubkey_from_sandbox(sandbox: modal.Sandbox) -> None:
57+
"""Copy SSH public key from sandbox"""
4958
process = sandbox.exec("bash", "-c", "cat /root/.ssh/id_rsa.pub")
5059
public_key = "".join([line for line in process.stdout]).strip()
5160

@@ -69,4 +78,5 @@ def copy_ssh_pubkey_from_sandbox(sandbox: modal.Sandbox) -> None:
6978

7079

7180
def write_to_sandbox(sandbox: modal.Sandbox, data: str, dst: Path) -> None:
81+
"""Write file to sandbox"""
7282
pass

commit0/harness/run_pytest_ids.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datasets import load_dataset
22
import docker
33
from enum import StrEnum, auto
4-
import os
54
import traceback
65
from pathlib import Path
76
import logging
@@ -40,7 +39,7 @@ class ExecutionBackend(StrEnum):
4039
def run_docker(
4140
spec: Spec, logger: logging.Logger, eval_file: Path, timeout: int, log_dir: Path
4241
) -> None:
43-
""" Runs the tests in a local docker container.
42+
"""Runs the tests in a local docker container.
4443
4544
1. Creates docker container.
4645
2. Copies ssh public key from container to local machine.
@@ -115,7 +114,7 @@ def run_docker(
115114
def run_modal(
116115
spec: Spec, logger: logging.Logger, eval_file: Path, timeout: int, log_dir: Path
117116
) -> None:
118-
""" Runs the tests in a remote Modal container.
117+
"""Runs the tests in a remote Modal container.
119118
120119
1. Creates modal container.
121120
2. Copies ssh public key from container to local machine.
@@ -126,11 +125,9 @@ def run_modal(
126125
import modal
127126
from commit0.harness.modal_utils import (
128127
create_sandbox,
129-
copy_to_sandbox,
130-
copy_from_sandbox,
131-
delete_file_from_sandbox,
132128
copy_ssh_pubkey_from_sandbox,
133-
write_to_sandbox,
129+
copy_file_to_sandbox,
130+
execute_command,
134131
)
135132

136133
# the image must exist on dockerhub
@@ -147,10 +144,10 @@ def run_modal(
147144
copy_file_to_sandbox(sandbox, nfs, eval_file, Path("/eval.sh"))
148145

149146
# DBG: check if eval file properly copied
150-
print(execute_command("ls /")[0])
147+
print(execute_command(sandbox, "ls /")[0])
151148

152149
# execute tests
153-
output, error = execute_command("/bin/bash /eval.sh")
150+
output, error = execute_command(sandbox, "/bin/bash /eval.sh")
154151
print(output)
155152
print(error)
156153

@@ -183,7 +180,7 @@ def main(
183180
backend: str,
184181
timeout: int,
185182
) -> None:
186-
""" Runs the pytests for repos in a dataset.
183+
"""Runs the pytests for repos in a dataset.
187184
188185
Tests are run either locally through docker
189186
or remotely through Modal.

0 commit comments

Comments
 (0)