@@ -71,21 +71,6 @@ def exec_run_with_timeout(
71
71
"""Exec"""
72
72
raise NotImplementedError
73
73
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
-
89
74
def write_test_output (
90
75
self , log_dir : Path , test_output : str , timed_out : bool
91
76
) -> None :
@@ -101,16 +86,6 @@ def write_test_output(
101
86
self .logger ,
102
87
)
103
88
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
- """
114
89
115
90
def __enter__ (self ):
116
91
return self
@@ -134,7 +109,7 @@ def __init__(
134
109
log_dir : Path ,
135
110
files_to_copy : Optional [Files ] = None ,
136
111
):
137
- super ().__init__ (spec , logger , timeout )
112
+ super ().__init__ (spec , logger , timeout , log_dir )
138
113
139
114
self .client = docker .from_env ()
140
115
self .container = create_container (
@@ -149,20 +124,30 @@ def __init__(
149
124
copy_to_container (self .container , f ["src" ], f ["dest" ]) # type: ignore
150
125
151
126
def exec_run_with_timeout (
152
- self , command : str , timeout : int
127
+ self , command : str , timeout : int , log_dir : Path ,
153
128
) -> tuple [str , bool , float ]:
154
129
"""Exec"""
155
- return exec_run_with_timeout (self .container , command , timeout )
130
+ output = exec_run_with_timeout (self .container , command , timeout )
156
131
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 ]:
158
143
"""Exec"""
159
144
return self .container .exec_run (command , demux = True )
160
145
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 :
162
147
"""Copy"""
163
148
copy_from_container (self .container , remote_path , local_path )
164
149
165
- def delete_file_from_remote (self , remote_path : Path ) -> None :
150
+ def _delete_file_from_remote (self , remote_path : Path ) -> None :
166
151
"""Delete"""
167
152
delete_file_from_container (self .container , str (remote_path ))
168
153
@@ -222,6 +207,7 @@ def exec_run_with_timeout(
222
207
223
208
print ("stdout" )
224
209
stdout = read_stream (self .sandbox .stdout )
210
+ print (stdout )
225
211
print ("stderr" )
226
212
stderr = read_stream (self .sandbox .stderr )
227
213
print (stderr )
@@ -233,29 +219,11 @@ def exec_run_with_timeout(
233
219
f .write (data )
234
220
235
221
self .sandbox .terminate ()
222
+ import pdb ; pdb .set_trace ()
236
223
237
224
# TODO: add timing
238
225
return stdout , False , 1.0
239
226
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
-
259
227
def __exit__ (
260
228
self ,
261
229
exctype : Optional [Type [BaseException ]],
0 commit comments