@@ -44,6 +44,7 @@ def __init__(
4444 log_dir : Path ,
4545 files_to_copy : Optional [Files ] = None ,
4646 files_to_collect : Optional [list [str ]] = None ,
47+ rebuild_image : bool = False ,
4748 ):
4849 """Create the remote execution context
4950
@@ -85,6 +86,7 @@ def __init__(
8586 log_dir : Path ,
8687 files_to_copy : Optional [Files ] = None ,
8788 files_to_collect : Optional [list [str ]] = None ,
89+ rebuild_image : bool = False ,
8890 ):
8991 super ().__init__ (
9092 spec ,
@@ -145,6 +147,7 @@ def __init__(
145147 log_dir : Path ,
146148 files_to_copy : Optional [Files ] = None ,
147149 files_to_collect : Optional [list [str ]] = None ,
150+ rebuild_image : bool = False ,
148151 ):
149152 super ().__init__ (
150153 spec ,
@@ -161,7 +164,7 @@ def __init__(
161164 # the image must exist on dockerhub
162165 reponame = spec .repo .split ("/" )[- 1 ]
163166 image_name = f"wentingzhao/{ reponame } :latest" .lower ()
164- image = modal .Image .from_registry (image_name )
167+ image = modal .Image .from_registry (image_name , force_build = rebuild_image )
165168 if files_to_copy :
166169 for _ , f in files_to_copy .items ():
167170 image = image .copy_local_file (f ["src" ], f ["dest" ]) # type: ignore
@@ -175,9 +178,8 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
175178 command += " && "
176179 for fname in self .files_to_collect :
177180 remote_file = Path (self .spec .repo_directory ) / fname
178- cp_cmd = f"cp { str (remote_file )} /vol/{ fname } 2>/dev/null ; "
181+ cp_cmd = f"test -e { str ( remote_file ) } && cp { str (remote_file )} /vol/{ fname } ; "
179182 command += cp_cmd
180-
181183 self .sandbox = modal .Sandbox .create (
182184 "bash" ,
183185 "-c" ,
@@ -198,7 +200,9 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
198200 timed_out = False
199201
200202 if self .files_to_collect :
201- for fname in self .files_to_collect :
203+ fnames = vol .listdir ("" )
204+ for fname in fnames :
205+ fname = fname .path
202206 with (self .log_dir / fname ).open ("wb" ) as f :
203207 for data in vol .read_file (fname ):
204208 f .write (data )
0 commit comments