@@ -226,16 +226,16 @@ def __init__(
226226 else :
227227 # Default: set up initial environment with Python 3.10
228228 self ._setup_initial_environment ()
229-
230- # Install dependencies
231- if self .install_dependencies :
232- self ._install_dependencies ()
233229 elif self .clone_current_env :
234230 logger .info (
235231 "[ENV CLONE] Skipping environment setup for Docker backend "
236232 "- container is already isolated"
237233 )
238234
235+ # Install dependencies
236+ if self .install_dependencies :
237+ self ._install_dependencies ()
238+
239239 def _setup_cloned_environment (self ):
240240 r"""Set up a cloned Python environment."""
241241 self .cloned_env_path = os .path .join (self .working_dir , ".venv" )
@@ -270,35 +270,49 @@ def _install_dependencies(self):
270270
271271 logger .info ("Installing dependencies..." )
272272
273- pip_cmd = [
274- self .python_executable ,
275- "-m" ,
276- "pip" ,
277- "install" ,
278- "--upgrade" ,
279- * self .install_dependencies ,
280- ]
281-
282- try :
283- subprocess .run (
284- pip_cmd ,
285- check = True ,
286- cwd = self .working_dir ,
287- capture_output = True ,
288- text = True ,
289- timeout = 300 , # 5 minutes timeout for installation
290- )
291- logger .info ("Successfully installed all dependencies." )
292- except subprocess .CalledProcessError as e :
293- logger .error (f"Failed to install dependencies: { e .stderr } " )
294- raise RuntimeError (
295- f"Failed to install dependencies: { e .stderr } "
296- ) from e
297- except subprocess .TimeoutExpired :
298- logger .error ("Dependency installation timed out after 5 minutes" )
299- raise RuntimeError (
300- "Dependency installation timed out after 5 minutes"
273+ if self .use_docker_backend :
274+ pkg_str = " " .join (
275+ shlex .quote (p ) for p in self .install_dependencies
301276 )
277+ install_cmd = f'sh -lc "pip install { pkg_str } "'
278+ exec_id = self .docker_api_client .exec_create (
279+ self .container .id , install_cmd
280+ )["Id" ]
281+ log = self .docker_api_client .exec_start (exec_id )
282+ logger .info (f"Package installation output:\n { log } " )
283+
284+ else :
285+ pip_cmd = [
286+ self .python_executable ,
287+ "-m" ,
288+ "pip" ,
289+ "install" ,
290+ "--upgrade" ,
291+ * self .install_dependencies ,
292+ ]
293+
294+ try :
295+ subprocess .run (
296+ pip_cmd ,
297+ check = True ,
298+ cwd = self .working_dir ,
299+ capture_output = True ,
300+ text = True ,
301+ timeout = 300 , # 5 minutes timeout for installation
302+ )
303+ logger .info ("Successfully installed all dependencies." )
304+ except subprocess .CalledProcessError as e :
305+ logger .error (f"Failed to install dependencies: { e .stderr } " )
306+ raise RuntimeError (
307+ f"Failed to install dependencies: { e .stderr } "
308+ ) from e
309+ except subprocess .TimeoutExpired :
310+ logger .error (
311+ "Dependency installation timed out after 5 minutes"
312+ )
313+ raise RuntimeError (
314+ "Dependency installation timed out after 5 minutes"
315+ )
302316
303317 def _setup_initial_environment (self ):
304318 r"""Set up an initial environment with Python 3.10."""
0 commit comments