
    &`in                         d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZ dZdZd	ed
ee         fdZedededej        fd            Zdedeee                  defdZdS )z1Util functions to manage dependency requirements.    N)asynccontextmanager)ListOptionalTuple)virtualenv_utils)check_output_cmdz-ray_runtime_env_internal_pip_requirements.txtd   requirements_filepip_packagesc                     t          | d          5 }|D ]}|                    |dz              	 ddd           dS # 1 swxY w Y   dS )zIDump [pip_packages] to the given [requirements_file] for later env setup.w
N)openwrite)r
   r   filelines       }/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/runtime_env/dependency_utils.pygen_requirements_txtr      s    		%	% $  	$ 	$DJJtd{####	$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   =AApythoncwdloggerc                4   K   dt           t          t          f         f fd} |             d{V \  }}dW V   |             d{V \  }}||k    rt          d| d| d| d| d	          ||k    r                    d	| d
| d           dS dS )a  A context manager to check ray is not overwritten.

    Currently, we only check ray version and path. It works for virtualenv,
        - ray is in Python's site-packages.
        - ray is overwritten during yield.
        - ray is in virtualenv's site-packages.
    returnc                  R  K   t          j        d          5 } t          j                            | d          }dd                    |          g}t          j        rt          j        	                                }ni }t          |
	|           d {V }
                    d|            t          |d	          5 }|                                }d d d            n# 1 swxY w Y   d
 |                                D             ^}}}d d d            n# 1 swxY w Y   ||fS )Ncheck_ray_version_tempfile)prefixzray_version.txtz-cz
import ray
with open(r"{ray_version_path}", "wt") as f:
    f.write(ray.__version__)
    f.write(" ")
    f.write(ray.__path__[0])
                )ray_version_path)r   r   envz)try to write ray version information in: rtc                 6    g | ]}|                                 S  )strip).0ss     r   
<listcomp>z@check_ray.<locals>._get_ray_version_and_path.<locals>.<listcomp>>   s     (K(K(Kq(K(K(K    )tempfileTemporaryDirectoryospathjoinformatr   _WIN32environcopyr   infor   readsplit)tmp_dirr   check_ray_cmdr   outputfray_versionray_path_r   r   r   s            r   _get_ray_version_and_pathz,check_ray.<locals>._get_ray_version_and_path!   s     (/
 
 
 	L!w||G5FGG F%5   M  & joo''+f#3        F KKVDTVVWWW&-- "" " " " " " " " " " " " " " " )L(KFLLNN(K(K(K%KA9	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L: H$$s6   B(DC"D"C&	&D)C&	*$DD!DNz=Changing the ray version is not allowed: 
  current version: z,   expect version: z,   current path: z,   expect path: zh, Please ensure the dependencies in the runtime_env pip field do not install a different version of Ray.z2Detected new Ray package with the same version at z (vs system z).)r   strRuntimeErrorr0   )r   r   r   r:   versionr*   actual_versionactual_paths   ```     r   	check_rayr@      sB     %U38_ % % % % % % % %@ 4355555555MGT	EEEE(A(A(C(C"C"C"C"C"C"CNK  9"09 9!(9 9  +9 9 #	9 9 9
 
 	
 dbbbZ^bbb	
 	
 	
 	
 	
 r&   
target_dirpip_listr   c                 0   dt           dt          ffd}t          }Yd} ||          r2|t          k     r't           d| }|dz  } ||          r|t          k     '|t          k    rt	          d          t
          j                            | |          S )au  Returns the path to the requirements file to use for this runtime env.

    If pip_list is not None, we will check if the internal pip filename is in any of
    the entries of pip_list. If so, we will append numbers to the end of the
    filename until we find one that doesn't conflict. This prevents infinite
    recursion if the user specifies the internal pip filename in their pip list.

    Args:
        target_dir: The directory to store the requirements file in.
        pip_list: A list of pip requirements specified by the user.

    Returns:
        The path to the requirements file to use for this runtime env.
    filenamer   c                      D ]	}| |v r dS 
dS )NTFr!   )rD   	pip_entryrB   s     r   filename_in_pip_listz3get_requirements_file.<locals>.filename_in_pip_listd   s.    ! 	 	I9$$tt %ur&   N   .zCould not find a valid filename for the internal pip requirements file. Please specify a different pip list in your runtime env.)r;   boolINTERNAL_PIP_FILENAMEMAX_INTERNAL_PIP_FILENAME_TRIESr<   r)   r*   r+   )rA   rB   rG   rD   is    `   r   get_requirements_filerN   T   s     s t       %H""8,, 	5T1T1T/55!55HFA #"8,, 	5T1T1T ///0  
 7<<
H---r&   )__doc__loggingr)   r'   
contextlibr   typingr   r   r   ray._private.runtime_envr   ray._private.runtime_env.utilsr   rK   rL   r;   r   Loggerr@   rN   r!   r&   r   <module>rV      s!   7 7  				  * * * * * * ( ( ( ( ( ( ( ( ( ( 5 5 5 5 5 5 ; ; ; ; ; ;G "% $C $tCy $ $ $ $ 9
C 9
c 9
7> 9
 9
 9
 9
x".c ".Xd3i5H ".S ". ". ". ". ". ".r&   