9
9
import logging
10
10
import os
11
11
import modal
12
+ import modal .io_streams
12
13
from pathlib import Path
13
14
from typing import Optional , Type
14
15
from types import TracebackType
@@ -70,12 +71,14 @@ def copy_to_remote(self, local_path: Path, remote_path: Path) -> None:
70
71
raise NotImplementedError
71
72
72
73
@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 ]:
74
77
"""Exec"""
75
78
raise NotImplementedError
76
79
77
80
@abstractmethod
78
- def exec_run (self , command : str ) -> None :
81
+ def exec_run (self , command : str ) -> tuple [ int , str ] :
79
82
"""Exec"""
80
83
raise NotImplementedError
81
84
@@ -109,7 +112,7 @@ def write_test_output(self, test_output: str, timed_out: bool) -> None:
109
112
# Check the exit code of the command
110
113
if exit_code == 0 :
111
114
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 )
113
116
114
117
def __enter__ (self ):
115
118
return self
@@ -120,7 +123,7 @@ def __exit__(
120
123
exctype : Optional [Type [BaseException ]],
121
124
excinst : Optional [BaseException ],
122
125
exctb : Optional [TracebackType ],
123
- ) -> bool :
126
+ ) -> None :
124
127
raise NotImplementedError
125
128
126
129
@@ -154,11 +157,13 @@ def copy_to_remote(self, local_file: Path, remote_path: Path) -> None:
154
157
"""Copy"""
155
158
copy_to_container (self .container , local_file , remote_path )
156
159
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 ]:
158
163
"""Exec"""
159
164
return exec_run_with_timeout (self .container , command , timeout )
160
165
161
- def exec_run (self , command : str ) -> ( int , str ) :
166
+ def exec_run (self , command : str ) -> tuple [ int , str ] :
162
167
"""Exec"""
163
168
return self .container .exec_run (command , demux = True )
164
169
@@ -175,7 +180,7 @@ def __exit__(
175
180
exctype : Optional [Type [BaseException ]],
176
181
excinst : Optional [BaseException ],
177
182
exctb : Optional [TracebackType ],
178
- ) -> bool :
183
+ ) -> None :
179
184
cleanup_container (self .client , self .container , self .logger )
180
185
close_logger (self .logger )
181
186
@@ -189,7 +194,7 @@ def __init__(
189
194
timeout : int ,
190
195
log_dir : Path ,
191
196
):
192
- super ().__init_ (spec , logger , eval_file , timeout , log_dir )
197
+ super ().__init__ (spec , logger , eval_file , timeout , log_dir )
193
198
194
199
# the image must exist on dockerhub
195
200
reponame = spec .repo .split ("/" )[- 1 ]
@@ -233,12 +238,15 @@ def copy_ssh_pubkey_from_remote(self) -> None:
233
238
234
239
def copy_to_remote (self , local_path : Path , remote_path : Path ) -> None :
235
240
"""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 ]:
242
250
"""Execute command on modal sandbox"""
243
251
print ("Executing:" , command )
244
252
process = self .sandbox .exec ("bash" , "-c" , command )
@@ -247,10 +255,10 @@ def exec_run_with_timeout(self, command: str, timeout: int) -> None:
247
255
print ("stderr" )
248
256
stderr = read_stream (process .stderr )
249
257
print (stderr )
250
- return stdout , False , 1
258
+ return stdout , False , 1.0
251
259
return stdout , stderr
252
260
253
- def exec_run (self , command : str ) -> ( int , str ) :
261
+ def exec_run (self , command : str ) -> tuple [ int , str ] :
254
262
"""Execute command on modal sandbox"""
255
263
process = self .sandbox .exec ("bash" , "-c" , command )
256
264
stdout = read_stream (process .stdout )
@@ -274,6 +282,6 @@ def __exit__(
274
282
exctype : Optional [Type [BaseException ]],
275
283
excinst : Optional [BaseException ],
276
284
exctb : Optional [TracebackType ],
277
- ) -> bool :
285
+ ) -> None :
278
286
self .sandbox .terminate ()
279
287
close_logger (self .logger )
0 commit comments