Skip to content

Commit 86904ac

Browse files
pyright
1 parent 844487b commit 86904ac

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

commit0/harness/execution_context.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import os
1111
import modal
12+
import modal.io_streams
1213
from pathlib import Path
1314
from typing import Optional, Type
1415
from types import TracebackType
@@ -70,12 +71,14 @@ def copy_to_remote(self, local_path: Path, remote_path: Path) -> None:
7071
raise NotImplementedError
7172

7273
@abstractmethod
73-
def exec_run_with_timeout(self, command: str, timeout: int) -> None:
74+
def exec_run_with_timeout(
75+
self, command: str, timeout: int
76+
) -> tuple[str, bool, float]:
7477
"""Exec"""
7578
raise NotImplementedError
7679

7780
@abstractmethod
78-
def exec_run(self, command: str) -> None:
81+
def exec_run(self, command: str) -> tuple[int, str]:
7982
"""Exec"""
8083
raise NotImplementedError
8184

@@ -109,7 +112,7 @@ def write_test_output(self, test_output: str, timed_out: bool) -> None:
109112
# Check the exit code of the command
110113
if exit_code == 0:
111114
self.copy_from_remote(report_file, self.log_dir / "report.json")
112-
self.delete_file_from_remote(str(report_file))
115+
self.delete_file_from_remote(report_file)
113116

114117
def __enter__(self):
115118
return self
@@ -120,7 +123,7 @@ def __exit__(
120123
exctype: Optional[Type[BaseException]],
121124
excinst: Optional[BaseException],
122125
exctb: Optional[TracebackType],
123-
) -> bool:
126+
) -> None:
124127
raise NotImplementedError
125128

126129

@@ -154,11 +157,13 @@ def copy_to_remote(self, local_file: Path, remote_path: Path) -> None:
154157
"""Copy"""
155158
copy_to_container(self.container, local_file, remote_path)
156159

157-
def exec_run_with_timeout(self, command: str, timeout: int) -> ():
160+
def exec_run_with_timeout(
161+
self, command: str, timeout: int
162+
) -> tuple[str, bool, float]:
158163
"""Exec"""
159164
return exec_run_with_timeout(self.container, command, timeout)
160165

161-
def exec_run(self, command: str) -> (int, str):
166+
def exec_run(self, command: str) -> tuple[int, str]:
162167
"""Exec"""
163168
return self.container.exec_run(command, demux=True)
164169

@@ -175,7 +180,7 @@ def __exit__(
175180
exctype: Optional[Type[BaseException]],
176181
excinst: Optional[BaseException],
177182
exctb: Optional[TracebackType],
178-
) -> bool:
183+
) -> None:
179184
cleanup_container(self.client, self.container, self.logger)
180185
close_logger(self.logger)
181186

@@ -189,7 +194,7 @@ def __init__(
189194
timeout: int,
190195
log_dir: Path,
191196
):
192-
super().__init_(spec, logger, eval_file, timeout, log_dir)
197+
super().__init__(spec, logger, eval_file, timeout, log_dir)
193198

194199
# the image must exist on dockerhub
195200
reponame = spec.repo.split("/")[-1]
@@ -233,12 +238,15 @@ def copy_ssh_pubkey_from_remote(self) -> None:
233238

234239
def copy_to_remote(self, local_path: Path, remote_path: Path) -> None:
235240
"""Copy"""
236-
tempname = "tmpfile"
237-
with local_path.open("rb") as f:
238-
self.nfs.write_file(tempname, f)
239-
self.sandbox.exec("bash", "-c", f"cp /vol/{tempname} {str(remote_path)}")
240-
241-
def exec_run_with_timeout(self, command: str, timeout: int) -> None:
241+
raise NotImplementedError
242+
# tempname = "tmpfile"
243+
# with local_path.open("rb") as f:
244+
# self.nfs.write_file(tempname, f)
245+
# self.sandbox.exec("bash", "-c", f"cp /vol/{tempname} {str(remote_path)}")
246+
247+
def exec_run_with_timeout(
248+
self, command: str, timeout: int
249+
) -> tuple[str, bool, float]:
242250
"""Execute command on modal sandbox"""
243251
print("Executing:", command)
244252
process = self.sandbox.exec("bash", "-c", command)
@@ -247,10 +255,10 @@ def exec_run_with_timeout(self, command: str, timeout: int) -> None:
247255
print("stderr")
248256
stderr = read_stream(process.stderr)
249257
print(stderr)
250-
return stdout, False, 1
258+
return stdout, False, 1.0
251259
return stdout, stderr
252260

253-
def exec_run(self, command: str) -> (int, str):
261+
def exec_run(self, command: str) -> tuple[int, str]:
254262
"""Execute command on modal sandbox"""
255263
process = self.sandbox.exec("bash", "-c", command)
256264
stdout = read_stream(process.stdout)
@@ -274,6 +282,6 @@ def __exit__(
274282
exctype: Optional[Type[BaseException]],
275283
excinst: Optional[BaseException],
276284
exctb: Optional[TracebackType],
277-
) -> bool:
285+
) -> None:
278286
self.sandbox.terminate()
279287
close_logger(self.logger)

commit0/harness/run_pytest_ids.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def main(
7979
eval_file = Path(log_dir / "eval.sh")
8080
eval_file.write_text(eval_script)
8181

82-
execution_context = None
82+
# Not sure how to appease typechecker
83+
execution_context = Docker
8384
if ExecutionBackend(backend) == ExecutionBackend.MODAL:
8485
execution_context = Modal
8586
elif ExecutionBackend(backend) == ExecutionBackend.LOCAL:

0 commit comments

Comments
 (0)