
    &`i              	           d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ  G d dej                  Z	 ej
        d          ddee         dej        d	ej        d
efdZdS )    N)Listc                   Z     e Zd ZdZdZdd fd
Zedededefd	            Z	 fd
Z
 xZS )SubprocessCalledProcessErrorz7The subprocess.CalledProcessError with stripped stdout.2   N)	cmd_indexc                H    || _          t                      j        |i | d S )N)r   super__init__)selfr   argskwargs	__class__s       r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/runtime_env/utils.pyr
   z%SubprocessCalledProcessError.__init__   s,    "$)&)))))    str_datalast_n_linesreturnc                     |dk     r| S |                                                      d          }d                    || d                    S )Nr   
)stripsplitjoin)r   r   liness      r   _get_last_n_linez-SubprocessCalledProcessError._get_last_n_line   sL    !O  &&t,,yy}~~.///r   c           	         | j         g nd| j          dg}|                    t                                                                 | j        | j        d}|                                D ]o\  }}|rhd| j         d| d}|                     || j                  	                                }|                    | dt          j        |d                      pd                    |          S )	NRun cmd[z$] failed with the following details.stdoutstderrzLast z
 lines of :r   z    )r   appendr	   __str__r   r   itemsLAST_N_LINESr   r   textwrapindentr   )r   str_listoutnamessubtitlelast_n_line_strr   s          r   r"   z$SubprocessCalledProcessError.__str__   s    ~% BQT^QQQR 	
 	))***kk
 
 yy{{ 	 	GD! G4#4GGGGG"&"7"74;L"M"M"S"S"U"UNN8??G#L#LNN   yy"""r   )__name__
__module____qualname____doc__r$   r
   staticmethodstrintr   r"   __classcell__)r   s   @r   r   r   
   s        AAL(, * * * * * * * 03 0c 0c 0 0 0 \0# # # # # # # # #r   r      )cmd_index_gencmdloggerr6   r   c                  K   t          |          }|                    d|t          |                      d}	 t          j        | t          j        j        t          j        j        d| d{V }|                                 d{V \  }}|	                    d          }|r|                    d||           n|                    d|           |j
        dk    rt          |j
        | ||          ||A	 |                                 n# t          $ r Y nw xY w|                                 d{V  S S # t          j        j        $ r}|d}~wt"          $ r}t%          d	| d
          |d}~ww xY w# |A	 |                                 n# t          $ r Y nw xY w|                                 d{V  w w xY w)a  Run command with arguments and return its output.

    If the return code was non-zero it raises a CalledProcessError. The
    CalledProcessError object will have the return code in the returncode
    attribute and any output in the output attribute.

    Args:
        cmd: The cmdline should be a sequence of program arguments or else
            a single string or path-like object. The program to execute is
            the first item in cmd.
        logger: The logger instance.
        cmd_index_gen: The cmd index generator, default is itertools.count(1).
        kwargs: All arguments are passed to the create_subprocess_exec.

    Returns:
        The stdout of cmd.

    Raises:
        CalledProcessError: If the return code of cmd is not 0.
    zRun cmd[%s] %sNr   zutf-8zOutput of cmd[%s]: %szNo output for cmd[%s]r   )outputr   r   z] got exception.)nextinforeprasynciocreate_subprocess_exec
subprocessPIPESTDOUTcommunicatedecode
returncoder   killProcessLookupErrorwait
exceptionsCancelledErrorBaseExceptionRuntimeError)	r7   r8   r6   r   r   procr   _es	            r   check_output_cmdrP   /   si     8 ]##I
KK )T#YY777D&3%*%,
 
 	
 
 
 
 
 
 
 
 **,,,,,,,,	 w'' 	<KK/FCCCCKK/;;;?a.Vy    		%    ))++ % ,     J J JAiAAABBIJ 		%    ))++ sm   AD; A)E: :D
DD;E7EE7E22E77E: :F?>FF?
F F?F  F?)r>   	itertoolsloggingr@   r%   typestypingr   CalledProcessErrorr   countr2   LoggerGeneratorTyperP    r   r   <module>rZ      s                     "# "# "# "# "#:#@ "# "# "#R *9););	F F F	cF NF &	F 	F F F F F Fr   