
    &`i2                        d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
  ej        e          Zdedej        fdZdeded	eee                  d
edej        defdZ G d de
          Z G d de
          ZdS )    N)ListOptional)RuntimeEnvContext)RuntimeEnvPlugin	image_uriloggerc                   K   t          j                    5 }t          j        |d           t          j                            |d          }d}dddd| d| d	d
|g	}|                    d|            t          j        |t          j	        j
        t          j	        j
        d d {V }|                                 d {V \  }}|j        dk    rDt          d| d|j         d|                                 d|                                           t          j                            |          st!          d|            t#          |d          5 }	|	                                                                }
d d d            n# 1 swxY w Y   |
                    d          st+          d|  d|
           |                    d|  d|
            |
cd d d            S # 1 swxY w Y   d S )Ni  zworker_path.txtz{
import ray._private.workers.default_worker as dw
with open('/shared/worker_path.txt', 'w') as f:
    f.write(dw.__file__)
podmanrunz--rm-vz
:/shared:Zpythonz-czPulling image %s)stdoutstderrr   zPodman command failed: cmd=z, returncode=z	, stdout=z	, stderr=z@Worker path file not created when getting worker path for image rz.pyz&Invalid worker path inferred in image z: zInferred worker path in image )tempfileTemporaryDirectoryoschmodpathjoininfoasynciocreate_subprocess_exec
subprocessPIPEcommunicate
returncodeRuntimeErrordecodeexistsFileNotFoundErroropenreadstripendswith
ValueError)r   r   tmpdirresult_fileget_worker_path_scriptcmdprocessr   r   fworker_paths              v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/runtime_env/image_uri.py_create_implr/      s      
	$	&	& /&
gll6+<==" !!!"

 	&	2226+09K9P
 
 
 
 
 
 
 
 
  '2244444444"" Ic  I  I@R  I  I]c]j]j]l]l  I  Iw}  xE  xE  xG  xG  I  I   w~~k** 	#^S\^^   +s## 	+q&&((..**K	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ ##E** 	SSSkSS   	OYOO+OOPPP_/ / / / / / / / / / / / / / / / / /s7   D?G&'F<G&F	G&F	A	G&&G*-G*r-   run_optionscontextray_tmp_dirc           	         ||_         d}|dd|dz   |z   ddddd	g	}t                      }t          j                                        D ]\  }	}
|	                    d
          r|
||	<    |                    |j                   |                                D ]5\  }	}
|                    d           |                    |	 d|
 d           6|                    d           |                    d           |r|	                    |           |                    d           |                    d           |                    |            d
                    |          }|                    d|            ||_        d S )Nr
   r   r   :z--cgroup-manager=cgroupfsz--network=hostz
--pid=hostz
--ipc=hostz--userns=keep-idRAY_z--envz=''zRAY_JOB_ID=$RAY_JOB_IDz--entrypointr    z)Starting worker in container with prefix )override_worker_entrypointdictr   environitems
startswithupdateenv_varsappendextendr   r   py_executable)r   r-   r0   r1   r   r2   container_drivercontainer_commandr>   env_var_nameenv_var_valuecontainer_command_strs               r.   _modify_context_implrG   B   s    *5G&cK'# 	%, vvH (*z'7'7'9'9 3 3#m""6** 	3%2H\" OOG$%%% (0~~'7'7 F F#m  )))  L!D!DM!D!D!DEEEE W%%%5666 .  ---^,,,X&&&Y'''  HH%677
KKS<QSSTTT1G    c            
           e Zd ZdZdZed             ZdefdZde	e         ddd	e
d
ej        def
dZefdee         ddd	e
d
e	ej                 fdZdS )ImageURIPluginz/Starts worker in a container of a custom image.r   c                  
    h dS )N>   configr>   r    rM   rH   r.   get_compatible_keysz"ImageURIPlugin.get_compatible_keys   s    2222rH   r2   c                     || _         d S N_ray_tmp_dirselfr2   s     r.   __init__zImageURIPlugin.__init__       'rH   uriruntime_env
RuntimeEnvr1   r   returnc                    K   |                                 sd S t          |                                 |           d {V | _        d S rP   )r   r/   r-   rT   rW   rX   r1   r   s        r.   createzImageURIPlugin.create   sW       $$&& 	F!-k.C.C.E.Ev!N!NNNNNNNrH   urisc                     |                                 sd S t          |                                 | j        g ||| j                   d S rP   )r   rG   r-   rR   rT   r^   rX   r1   r   s        r.   modify_contextzImageURIPlugin.modify_context   s]     $$&& 	F!!##	
 	
 	
 	
 	
rH   N)__name__
__module____qualname____doc__namestaticmethodrN   strrU   r   r   loggingLoggerfloatr]   default_loggerr   ra   rM   rH   r.   rJ   rJ      s        99D3 3 \3(C ( ( ( (
Oc]
O "
O #	
O
 
O 

O 
O 
O 
O" ,:
 
3i
 "
 #	

 (
 
 
 
 
 
rH   rJ   c            
           e Zd ZdZdZdefdZdee         ddded	e	j
        d
ef
dZefdee         ddded	ee	j
                 fdZdS )ContainerPluginzStarts worker in container.	containerr2   c                     || _         d S rP   rQ   rS   s     r.   rU   zContainerPlugin.__init__   rV   rH   rW   rX   rY   r1   r   rZ   c                    K   |                                 r|                                sd S t          |                                |           d {V | _        d S rP   )has_py_containerpy_container_imager/   r-   r\   s        r.   r]   zContainerPlugin.create   sk       ++-- 	[5S5S5U5U 	F!-k.L.L.N.NPV!W!WWWWWWWrH   r^   c                 X   |                                 r|                                sd S |                                r|                    d           t	          |                                |                                p| j        |                                ||| j                   d S )NzYou are using `container.worker_path`, but the path to `default_worker.py` is now automatically detected from the image. `container.worker_path` is deprecated and will be removed in future versions.)rr   rs   py_container_worker_pathwarningrG   r-   py_container_run_optionsrR   r`   s        r.   ra   zContainerPlugin.modify_context   s     ++-- 	[5S5S5U5U 	F//11 	NN   	**,,0022Fd6F0022	
 	
 	
 	
 	
rH   N)rb   rc   rd   re   rf   rh   rU   r   r   ri   rj   rk   r]   rl   r   ra   rM   rH   r.   rn   rn      s        %%D(C ( ( ( (
Xc]
X "
X #	
X
 
X 

X 
X 
X 
X" ,:
 
3i
 "
 #	

 (
 
 
 
 
 
rH   rn   )r   ri   r   r   typingr   r    ray._private.runtime_env.contextr   ray._private.runtime_env.pluginr   	getLoggerrb   rl   rh   rj   r/   rG   rJ   rn   rM   rH   r.   <module>r|      s_     				  ! ! ! ! ! ! ! ! > > > > > > < < < < < <""8,,2# 2w~ 2 2 2 2jG2G2G2 $s)$G2 	G2
 NG2 G2 G2 G2 G2T)
 )
 )
 )
 )
% )
 )
 )
X-
 -
 -
 -
 -
& -
 -
 -
 -
 -
rH   