Skip to content

Commit 304c8d5

Browse files
make docker container methods private
1 parent 130c4da commit 304c8d5

File tree

1 file changed

+18
-50
lines changed

1 file changed

+18
-50
lines changed

commit0/harness/execution_context.py

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,6 @@ def exec_run_with_timeout(
7171
"""Exec"""
7272
raise NotImplementedError
7373

74-
@abstractmethod
75-
def exec_run(self, command: str) -> tuple[int, str]:
76-
"""Exec"""
77-
raise NotImplementedError
78-
79-
@abstractmethod
80-
def copy_from_remote(self, remote_path: Path, local_path: Path) -> None:
81-
"""Copy"""
82-
raise NotImplementedError
83-
84-
@abstractmethod
85-
def delete_file_from_remote(self, remote_path: Path) -> None:
86-
"""Delete"""
87-
raise NotImplementedError
88-
8974
def write_test_output(
9075
self, log_dir: Path, test_output: str, timed_out: bool
9176
) -> None:
@@ -101,16 +86,6 @@ def write_test_output(
10186
self.logger,
10287
)
10388

104-
"""
105-
# copy back report.json if there is any
106-
report_file = Path(self.spec.repo_directory) / "report.json"
107-
# Run the test command inside the container to check if the file exists
108-
exit_code, output = self.exec_run(f"test -e {report_file}")
109-
# Check the exit code of the command
110-
if exit_code == 0:
111-
self.copy_from_remote(report_file, log_dir / "report.json")
112-
self.delete_file_from_remote(report_file)
113-
"""
11489

11590
def __enter__(self):
11691
return self
@@ -134,7 +109,7 @@ def __init__(
134109
log_dir: Path,
135110
files_to_copy: Optional[Files] = None,
136111
):
137-
super().__init__(spec, logger, timeout)
112+
super().__init__(spec, logger, timeout, log_dir)
138113

139114
self.client = docker.from_env()
140115
self.container = create_container(
@@ -149,20 +124,30 @@ def __init__(
149124
copy_to_container(self.container, f["src"], f["dest"]) # type: ignore
150125

151126
def exec_run_with_timeout(
152-
self, command: str, timeout: int
127+
self, command: str, timeout: int, log_dir: Path,
153128
) -> tuple[str, bool, float]:
154129
"""Exec"""
155-
return exec_run_with_timeout(self.container, command, timeout)
130+
output = exec_run_with_timeout(self.container, command, timeout)
156131

157-
def exec_run(self, command: str) -> tuple[int, str]:
132+
# copy back report.json if there is any
133+
report_file = Path(self.spec.repo_directory) / "report.json"
134+
# Run the test command inside the container to check if the file exists
135+
exit_code, test_output = self._exec_run(f"test -e {report_file}")
136+
# Check the exit code of the command
137+
if exit_code == 0:
138+
self._copy_from_remote(report_file, log_dir / "report.json")
139+
self._delete_file_from_remote(report_file)
140+
return output
141+
142+
def _exec_run(self, command: str) -> tuple[int, str]:
158143
"""Exec"""
159144
return self.container.exec_run(command, demux=True)
160145

161-
def copy_from_remote(self, remote_path: Path, local_path: Path) -> None:
146+
def _copy_from_remote(self, remote_path: Path, local_path: Path) -> None:
162147
"""Copy"""
163148
copy_from_container(self.container, remote_path, local_path)
164149

165-
def delete_file_from_remote(self, remote_path: Path) -> None:
150+
def _delete_file_from_remote(self, remote_path: Path) -> None:
166151
"""Delete"""
167152
delete_file_from_container(self.container, str(remote_path))
168153

@@ -222,6 +207,7 @@ def exec_run_with_timeout(
222207

223208
print("stdout")
224209
stdout = read_stream(self.sandbox.stdout)
210+
print(stdout)
225211
print("stderr")
226212
stderr = read_stream(self.sandbox.stderr)
227213
print(stderr)
@@ -233,29 +219,11 @@ def exec_run_with_timeout(
233219
f.write(data)
234220

235221
self.sandbox.terminate()
222+
import pdb; pdb.set_trace()
236223

237224
# TODO: add timing
238225
return stdout, False, 1.0
239226

240-
def exec_run(self, command: str) -> tuple[int, str]:
241-
"""Execute command on modal sandbox"""
242-
process = self.sandbox.exec("bash", "-c", command)
243-
stdout = read_stream(process.stdout)
244-
stderr = read_stream(process.stderr)
245-
print(stderr)
246-
return 1, stdout
247-
248-
def copy_from_remote(self, remote_path: Path, local_path: Path) -> None:
249-
"""Copy file from modal sandbox"""
250-
process = self.sandbox.exec("bash", "-c", f"cat {str(remote_path)}")
251-
output = "".join([line for line in process.stdout]).strip()
252-
with local_path.open("w") as f:
253-
f.write(output)
254-
255-
def delete_file_from_remote(self, remote_path: Path) -> None:
256-
"""Delete"""
257-
self.sandbox.exec("bash", "-c", f"rm {str(remote_path)}")
258-
259227
def __exit__(
260228
self,
261229
exctype: Optional[Type[BaseException]],

0 commit comments

Comments
 (0)