
    &`iD              	       n   d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlZd dlmZ d dlmZ  e j        e          Zdeddfd	Zd
efdZdefdZdee         dee         fdZdee         dee         fdZdedefdZdedefdZde
eef         de
eef         fdZde
eee         ef         de	e         fdZde
eee         ef         de	e         fdZdee         dee         fdZdee         dee         fdZ d eeef         de	eeef                  fd!Z!eee eeee!ed"Z"eed#Z#dS )$    N)OrderedDict)Path)DictListOptionalUnion)is_path
parse_pathpathreturnc                 $    t          |            dS )z6Parse the path to ensure it is well-formed and exists.Nr
   )r   s    w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/runtime_env/validation.pyvalidate_pathr      s    t    uric                    	 ddl m}m}  ||           \  }}n # t          $ r t          |  d          w xY w||                                v r9|                    d          s&|                    d          st          d          d S d S d S )Nr   )Protocol	parse_uriz is not a valid URI. Passing directories or modules to be dynamically uploaded is only supported at the job level (i.e., passed to `ray.init`).z.zipz.whlz2Only .zip or .whl files supported for remote URIs.)"ray._private.runtime_env.packagingr   r   
ValueErrorremote_protocolsendswith)r   r   r   protocolr   s        r   validate_urir      s    	
JJJJJJJJ"3$$ 
 
 
 , , ,
 
 	

 	H--////f%% 	0f%% 	0 MNNN	 	0/////s    6requirements_filec                     t          |           }|                                st          | d          |                                                                                    d          S )zIRead the given [requirements_file], and return all required dependencies.z is not a valid file
)r   is_filer   	read_textstripsplit)r   requirements_paths     r   #_handle_local_deps_requirement_filer$   (   sj    .//$$&& E-CCCDDD&&((..0066t<<<r   py_modules_urisc                    t          | t                    s t          dt          |            d          | D ]F}t          |t                    s t          dt          |           d          t          |           GdS )z^Parses and validates a 'py_modules' option.

    Expects py_modules to be a list of URIs.
    ,`py_modules` must be a list of strings, got ."`py_module` must be a string, got N)
isinstancelist	TypeErrortypestrr   )r%   modules     r   validate_py_modules_urisr0   0   s    
 ot,, 
Vd?>S>SVVV
 
 	
 "  &#&& 	USDLLSSSTTTV r   
py_modulesc                 @   t          | t                    s t          dt          |            d          | D ]e}t          |t                    s t          dt          |           d          t          |          rt          |           Vt          |           f| S )zmParses and validates a 'py_modules' option.

    Expects py_modules to be a list of local paths or URIs.
    r'   r(   r)   )r*   r+   r,   r-   r.   r	   r   r   )r1   r/   s     r   parse_and_validate_py_modulesr3   B   s    
 j$'' 
Qd:>N>NQQQ
 
 	
  ! !&#&& 	USDLLSSSTTT6?? 	!&!!!!    r   working_dir_uric                     t          | t                    s t          dt          |            d          t	          |            dS )z,Parses and validates a 'working_dir' option.$`working_dir` must be a string, got r(   N)r*   r.   r,   r-   r   )r4   s    r   validate_working_dir_urir7   Y   sR    os++ 
Nd?6K6KNNN
 
 	
 !!!!!r   working_dirc                     | J t          | t                    s t          dt          |            d          t	          |           rt          |            nt          |            | S )zSParses and validates a 'working_dir' option.

    This can be a URI or a path.
    Nr6   r(   )r*   r.   r,   r-   r	   r   r   )r8   s    r   parse_and_validate_working_dirr:   c   sz    
 """k3'' XV${BSBSVVVWWW{ "k""""[!!!r   condac                    | J t           j        dk    rt                              d           | }t	          | t
                    rt          |           }|j        dv rw|                                st          d| d          	 t          j        |                                          }n# t          $ r}t          d| d| d          d}~ww xY w|                                r6|                                st          d	| d          t          |          }n8t	          | t                     r| }n t#          d
t%          |            d          |S )a  Parses and validates a user-provided 'conda' option.

    Conda can be one of three cases:
        1) A dictionary describing the env. This is passed through directly.
        2) A string referring to the name of a preinstalled conda env.
        3) A string pointing to a local conda YAML file. This is detected
           by looking for a '.yaml' or '.yml' suffix. In this case, the file
           will be read as YAML and passed through as a dictionary.
    Nwin32runtime environment support is experimental on Windows. If you run into issues please file a report at https://github.com/ray-project/ray/issues.)z.yamlz.ymlzCan't find conda YAML file r(   zFailed to read conda file z: zCan't find conda env directory z6runtime_env['conda'] must be of type str or dict, got )sysplatformloggerwarningr*   r.   r   suffixr   r   yaml	safe_loadr    	Exceptionis_absoluteis_dirdictr,   r-   )r;   result	file_pathes       r   parse_and_validate_condarM   u   s    
|w9	
 	
 	
 F% 
KK	000$$&& M !Ky!K!K!KLLLQ	(;(;(=(=>> Q Q Q !Oi!O!O1!O!O!OPPPQ""$$ 	$##%% Q !O9!O!O!OPPP^^F	E4	 	  
VUVVV
 
 	
 Ms   &B- -
C7CCuvc                    | J t           j        dk    rt                              d           d}t	          | t
                    r"t          |           }t          |d          }nt	          | t                    r,t          d | D                       rt          | d          }nIt	          | t                    rt          |                                           h dz
  r1t          d	t          |                                                      d
| vrt          d|            d| v r@t	          | d         t                    s%t          dt          | d                              d| v r@t	          | d         t
                    s%t          dt          | d                              d| v rt	          | d         t                    s%t          dt          | d                              t!          | d                   D ]=\  }}t	          |t
                    s#t          dt          |           d| d          >|                                 }|                     dd          |d<   |                     ddg          |d<   t	          | d
         t                    s%t          dt          | d
                              nt          dt          |                      t          t'          j        |d
                             |d
<   t+          |d
                   dk    rd}t                              d|  d| d           |S )uH  Parses and validates a user-provided 'uv' option.

    The value of the input 'uv' field can be one of two cases:
        1) A List[str] describing the requirements. This is passed through.
           Example usage: ["tensorflow", "requests"]
        2) a string containing the path to a local pip “requirements.txt” file.
        3) A python dictionary that has one field:
            a) packages (required, List[str]): a list of uv packages, it same as 1).
            b) uv_check (optional, bool): whether to enable pip check at the end of uv
               install, default to False.
            c) uv_version (optional, str): user provides a specific uv to use; if
               unspecified, default version of uv will be used.
            d) uv_pip_install_options (optional, List[str]): user-provided options for
              `uv pip install` command, default to ["--no-cache"].

    The returned parsed value will be a list of packages. If a Ray library
    (e.g. "ray[serve]") is specified, it will be deleted and replaced by its
    dependencies (e.g. "uvicorn", "requests").
    Nr=   r>    F)packagesuv_checkc              3   @   K   | ]}t          |t                    V  d S Nr*   r.   .0deps     r   	<genexpr>z(parse_and_validate_uv.<locals>.<genexpr>   s,      %I%Isjc&:&:%I%I%I%I%I%Ir   >   rQ   rR   
uv_versionuv_pip_install_optionszrruntime_env['uv'] can only have these fields: packages, uv_check, uv_version and uv_pip_install_options, but got: rQ   z9runtime_env['uv'] must include field 'packages', but got rR   z8runtime_env['uv']['uv_check'] must be of type bool, got rZ   z9runtime_env['uv']['uv_version'] must be of type str, got r[   zJruntime_env['uv']['uv_pip_install_options'] must be of type list[str] got  for 	-th item.z
--no-cachez9runtime_env['uv']['packages'] must be of type list, got: z:runtime_env['uv'] must be of type List[str], or dict, got r   z$Rewrote runtime_env `uv` field from  to r(   r?   r@   rA   rB   r*   r.   r$   rI   r+   allsetkeysr   boolr,   r-   	enumeratecopygetr   fromkeyslendebug)rN   rJ   uv_listidxcur_opts        r   parse_and_validate_uvrm      s   ( >>>
|w9	
 	
 	
 F"c :
5b99w777	B		 7
#%I%Ib%I%I%I"I"I 7
rE222	B		 5
rwwyy>> 
 
 
 
 
	 %		??% %  
 RPBPP   Jr*~t$D$D.BzN++. .   2jL1A3&G&G0B|,--0 0   $r))b!9:DAA J%)"-E*F%G%GJ J  
 !*"-E*F G G  W!'3// #L)-gL L=@L L L   VVJ66z+-66$|n,
 ,
'( "Z.$// 	/R
^,,/ /  	 VDQSHHVV
 
 	

 k26*3EFFGGF:
6*!##
LLIIIIIIJJJMr   pipc                    | J d}t           j        dk    rt                              d           t	          | t
                    r"t          |           }t          |d          }nt	          | t                    r,t          d | D                       rt          | d          }nct	          | t                    r.t          |                                           h dz
  r1t          dt          |                                                      d	| v r@t	          | d	         t                    s%t          d
t          | d	                              d| v r@t	          | d         t
                    s%t          dt          | d                              d| v rt	          | d         t                    s%t          dt          | d                              t!          | d                   D ]=\  }}t	          |t
                    s#t          dt          |           d| d          >|                                 }|                     d	d          |d	<   d| vrt          d|            t	          | d         t
                    rt          | d                   |d<   n`t	          | d         t                    s%t          dt          | d                              nt          dt          |                      t          t'          j        |d                             |d<   t+          |d                   dk    rd}t                              d|  d| d           |S )a  Parses and validates a user-provided 'pip' option.

    The value of the input 'pip' field can be one of two cases:
        1) A List[str] describing the requirements. This is passed through.
        2) A string pointing to a local requirements file. In this case, the
           file contents will be read split into a list.
        3) A python dictionary that has three fields:
            a) packages (required, List[str]): a list of pip packages, it same as 1).
            b) pip_check (optional, bool): whether to enable pip check at the end of pip
               install, default to False.
            c) pip_version (optional, str): the version of pip, ray will spell
               the package name 'pip' in front of the `pip_version` to form the final
               requirement string, the syntax of a requirement specifier is defined in
               full in PEP 508.
            d) pip_install_options (optional, List[str]): user-provided options for
              `pip install` command, defaults to ["--disable-pip-version-check", "--no-cache-dir"].

    The returned parsed value will be a list of pip packages. If a Ray library
    (e.g. "ray[serve]") is specified, it will be deleted and replaced by its
    dependencies (e.g. "uvicorn", "requests").
    Nr=   r>   F)rQ   	pip_checkc              3   @   K   | ]}t          |t                    V  d S rT   rU   rV   s     r   rY   z)parse_and_validate_pip.<locals>.<genexpr>(  s,      &K&Kz#s';';&K&K&K&K&K&Kr   >   rQ   rp   pip_versionpip_install_optionszrruntime_env['pip'] can only have these fields: packages, pip_check, pip_install_options and pip_version, but got: rp   z:runtime_env['pip']['pip_check'] must be of type bool, got rr   z;runtime_env['pip']['pip_version'] must be of type str, got rs   zHruntime_env['pip']['pip_install_options'] must be of type list[str] got r\   r]   rQ   z:runtime_env['pip'] must include field 'packages', but got zAruntime_env['pip']['packages'] must be of type str of list, got: z9runtime_env['pip'] must be of type str or List[str], got r   z%Rewrote runtime_env `pip` field from r^   r(   r_   )rn   rJ   pip_listrk   rl   s        r   parse_and_validate_pipru     s   , ???F
|w9	
 	
 	

 #s B
6s;;
 
 
 
C		 ;
3&K&Ks&K&K&K#K#K ;
se444	C		 9
sxxzz?? 
 
 
 
 
	 &

##& &   #j[1A4&H&H0C,--0 0   Cc-0#66 6M 2336 6   !C''c"78$?? H%)#.C*D%E%EH H  
 !*#.C*D E E  W!'3// #L)-gL L=@L L L    "ggk599{S  RSRR   J-- 	!DS_!U!UF:C
OT22 	0S_--0 0  	 V4PS99VV
 
 	
 k26*3EFFGGF:
6*!##
LLKKK&KKKLLLMr   	containerc                     | J | S )zwParses and validates a user-provided 'container' option.

    This is passed through without validation (for now).
     )rv   s    r   parse_and_validate_containerry   s  s    
    r   excludesc                     | J t          | t                    rt          |           dk    rdS t          | t                    rt          d | D                       r| S t	          dt          |                      )zParses and validates a user-provided 'excludes' option.

    This is validated to verify that it is of type List[str].

    If an empty list is passed, we return `None` for consistency.
    Nr   c              3   @   K   | ]}t          |t                    V  d S rT   rU   )rW   r   s     r   rY   z.parse_and_validate_excludes.<locals>.<genexpr>  s,      )U)UD*T3*?*?)U)U)U)U)U)Ur   z7runtime_env['excludes'] must be of type List[str], got )r*   r+   rh   r`   r,   r-   )rz   s    r   parse_and_validate_excludesr}   |  s     (D!! c(mmq&8&8t(D!! 
c)U)UH)U)U)U&U&U 
/"8nn/ /
 
 	
r   env_varsc           	         | J t          |           dk    rdS t          | t                    st          dt	          |                      |                                 D ]s\  }}t          |t                    s"t          d| dt	          |                     t          |t                    s"t          d| dt	          |                     t| S )a(  Parses and validates a user-provided 'env_vars' option.

    This is validated to verify that all keys and vals are strings.

    If an empty dictionary is passed, we return `None` for consistency.

    Args:
        env_vars: A dictionary of environment variables to set in the
            runtime environment.

    Returns:
        The validated env_vars dictionary, or None if it was empty.

    Raises:
        TypeError: If the env_vars is not a dictionary of strings. The error message
            will include the type of the invalid value.
    Nr   z<runtime_env['env_vars'] must be of type Dict[str, str], got zDruntime_env['env_vars'] must be of type Dict[str, str], but the key z is of type zFruntime_env['env_vars'] must be of type Dict[str, str], but the value )rh   r*   rI   r,   r-   itemsr.   )r~   keyvals      r   parse_and_validate_env_varsr     s+   $ 
8}}th%% 
4#'>>4 4
 
 	

 NN$$ 
 
S#s## 	L/2L L@DS		L L   #s## 	N14N NBFs))N N  	 Or   )r1   r8   rz   r;   rn   rN   r~   rv   )r8   r1   )$loggingr?   collectionsr   pathlibr   typingr   r   r   r   rD   ray._private.path_utilsr	   r   r   	getLogger__name__rA   r.   r   r   r$   r0   r3   r7   r:   rI   rM   rm   ru   ry   r}   r   OPTION_TO_VALIDATION_FNOPTION_TO_NO_PATH_VALIDATION_FNrx   r   r   <module>r      s    



 # # # # # #       . . . . . . . . . . . .  + + + + + + 9 9 9 9 9 9		8	$	$     
Oc O O O O(=3 = = = =d3i DI    $d3i DI    ."c "c " " " "     $(E#t)$4 (sDy9I ( ( ( (V_eCcD$89 _htn _ _ _ _Dnc49d&: ; n n n n nbDI $s)    
$s) 
S	 
 
 
 
*($sCx. (Xd3PS8n=U ( ( ( (\ 01+%!
+-	 	 " ,*# #   r   