1717
1818from commit0 .harness .constants import Files
1919from commit0 .harness .spec import Spec
20- from commit0 .harness .utils import (
21- EvaluationError ,
22- )
2320from commit0 .harness .docker_build import (
2421 close_logger ,
2522)
@@ -46,7 +43,7 @@ def __init__(
4643 num_cpus : int ,
4744 log_dir : Path ,
4845 files_to_copy : Optional [Files ] = None ,
49- files_to_collect : Optional [Files ] = None ,
46+ files_to_collect : Optional [list [ str ] ] = None ,
5047 ):
5148 """Create the remote execution context
5249
@@ -87,9 +84,17 @@ def __init__(
8784 num_cpus : int ,
8885 log_dir : Path ,
8986 files_to_copy : Optional [Files ] = None ,
90- files_to_collect : Optional [Files ] = None ,
87+ files_to_collect : Optional [list [ str ] ] = None ,
9188 ):
92- super ().__init__ (spec , logger , timeout , num_cpus , log_dir , files_to_copy = files_to_copy , files_to_collect = files_to_collect )
89+ super ().__init__ (
90+ spec ,
91+ logger ,
92+ timeout ,
93+ num_cpus ,
94+ log_dir ,
95+ files_to_copy = files_to_copy ,
96+ files_to_collect = files_to_collect ,
97+ )
9398
9499 self .client = docker .from_env ()
95100 self .container = create_container (
@@ -108,18 +113,16 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
108113 """Exec"""
109114 output = exec_run_with_timeout (self .container , command , self .timeout )
110115
111- for fname in self .files_to_collect :
112- # copy back report.json if there is any
113- file = Path (self .spec .repo_directory ) / fname
114- # Run the test command inside the container to check if the file exists
115- exit_code , test_output = self .container .exec_run (
116- f"test -e { file } " , demux = True
117- )
118- # Check the exit code of the command
119- if exit_code == 0 :
120- copy_from_container (
121- self .container , file , self .log_dir / fname
116+ if self .files_to_collect :
117+ for fname in self .files_to_collect :
118+ file = Path (self .spec .repo_directory ) / fname
119+ # Run the test command inside the container to check if the file exists
120+ exit_code , test_output = self .container .exec_run (
121+ f"test -e { file } " , demux = True
122122 )
123+ # Check the exit code of the command
124+ if exit_code == 0 :
125+ copy_from_container (self .container , file , self .log_dir / fname )
123126 return output
124127
125128 def __exit__ (
@@ -141,9 +144,17 @@ def __init__(
141144 num_cpus : int ,
142145 log_dir : Path ,
143146 files_to_copy : Optional [Files ] = None ,
144- files_to_collect : Optional [Files ] = None ,
147+ files_to_collect : Optional [list [ str ] ] = None ,
145148 ):
146- super ().__init__ (spec , logger , timeout , num_cpus , log_dir , files_to_copy = files_to_copy , files_to_collect = files_to_collect )
149+ super ().__init__ (
150+ spec ,
151+ logger ,
152+ timeout ,
153+ num_cpus ,
154+ log_dir ,
155+ files_to_copy = files_to_copy ,
156+ files_to_collect = files_to_collect ,
157+ )
147158
148159 self .app = modal .App ()
149160
@@ -161,10 +172,11 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
161172 start_time = time .time ()
162173 with modal .Volume .ephemeral () as vol :
163174 cp_cmd = ""
164- for fname in self .files_to_collect :
165- remote_file = Path (self .spec .repo_directory ) / fname
166- curr_cp_cmd = f" && cp { str (remote_file )} /vol/{ fname } 2>/dev/null"
167- cp_cmd += curr_cp_cmd
175+ if self .files_to_collect :
176+ for fname in self .files_to_collect :
177+ remote_file = Path (self .spec .repo_directory ) / fname
178+ curr_cp_cmd = f" && cp { str (remote_file )} /vol/{ fname } 2>/dev/null"
179+ cp_cmd += curr_cp_cmd
168180
169181 command += cp_cmd
170182 self .sandbox = modal .Sandbox .create (
@@ -186,10 +198,11 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
186198 else :
187199 timed_out = False
188200
189- for fname in self .files_to_collect :
190- with (self .log_dir / fname ).open ("wb" ) as f :
191- for data in vol .read_file (fname ):
192- f .write (data )
201+ if self .files_to_collect :
202+ for fname in self .files_to_collect :
203+ with (self .log_dir / fname ).open ("wb" ) as f :
204+ for data in vol .read_file (fname ):
205+ f .write (data )
193206
194207 self .sandbox .terminate ()
195208 end_time = time .time ()
0 commit comments