U
    &%e#                     @   sx  d dl Z d dlZd dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZ d dlmZ erd dlmZ e	eeef  Zeeeef ed	d
dZee	e ef ed	ddZee	e ef e	e d	ddZdee	e ef eee deee   ee
eef  eee  ee ee ee eedddZ!eed dddZ"dS )    N)TYPE_CHECKINGAnyCallableIterableListMappingOptionalUnion)escape)SpinnerInterfaceopen_spinner)InstallationSubprocessError)VERBOSEsubprocess_logger)
HiddenText)Literal)argsreturnc                  G   s2   g }| D ]$}t |tr"|| q|| q|S )z&
    Create a CommandArgs object.
    )
isinstancelistextendappend)r   command_argsarg r   ]/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/pip/_internal/utils/subprocess.pymake_command    s    
r   c                 C   s   d dd | D S )z/
    Format command arguments for display.
     c                 s   s0   | ](}t |trtt|nt|V  qd S )N)r   r   shlexquotestr.0r   r   r   r   	<genexpr>:   s   z&format_command_args.<locals>.<genexpr>)joinr   r   r   r   format_command_args1   s    	
r&   c                 C   s   dd | D S )z=
    Return the arguments in their raw, unredacted form.
    c                 S   s    g | ]}t |tr|jn|qS r   )r   r   secretr!   r   r   r   
<listcomp>D   s     z'reveal_command_args.<locals>.<listcomp>r   r%   r   r   r   reveal_command_args@   s    r)   FraiseTz"Literal["raise", "warn", "ignore"])cmdshow_stdoutcwdon_returncodeextra_ok_returncodesextra_environunset_environspinnerlog_failed_cmdstdout_onlycommand_descr   c
             
   C   s  |dkrg }|dkrg }|r*t j}tj}n
t j}t}t  |k}| oL|dk	}|d|
 tj	 }|rp|
| |D ]}||d qtz0tjt| tjtj|	stjntj||dd}W n6 tk
r } z|rt d||
  W 5 d}~X Y nX g }|	s|jst|jst|j  |j }|s.qh| }||d  || |r|s\t|  qz|  W 5 |jr|j  X d|}nT| \}}| D ]}|| q|| | D ]}|| q|| |}|jo|j|k}|r(|st|r| d n
| d	 |r|d
krt!|
|j|sJ|ndd}|rt "d| t jdt#t$| ddid t jdt#|pdddid |n8|dkrt %d|
|j| n|dkrnt&d||S )a  
    Args:
      show_stdout: if true, use INFO to log the subprocess's stderr and
        stdout streams.  Otherwise, use DEBUG.  Defaults to False.
      extra_ok_returncodes: an iterable of integer return codes that are
        acceptable, in addition to 0. Defaults to None, which means [].
      unset_environ: an iterable of environment variable names to unset
        prior to calling subprocess.Popen().
      log_failed_cmd: if false, failed commands are not logged, only raised.
      stdout_only: if true, return only stdout, else return both. When true,
        logging of both stdout and stderr occurs when the subprocess has
        terminated, else logging occurs as subprocess output is produced.
    NzRunning command %sbackslashreplace)stdinstdoutstderrr-   enverrorsz#Error %s while executing command %s
 errordoner*   )command_description	exit_codeoutput_linesz[present-rich] %sz*[bold magenta]full command[/]: [blue]%s[/]markupT)extraz[bold magenta]cwd[/]: %sz	[inherit]warnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=)'r   infologgingINFOverboser   getEffectiveLevelosenvironcopyupdatepop
subprocessPopenr)   PIPESTDOUT	Exceptioncriticalr8   AssertionErrorr7   closereadlinerstripr   spinwaitr$   communicate
splitlines
returncodefinishr   r>   r
   r&   warning
ValueError)r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   log_subprocess
used_levelshowing_subprocessuse_spinnerr:   nameprocexc
all_outputlineoutputouterrout_lineerr_lineproc_had_errorr>   r   r   r   call_subprocessG   s    















rr   ).N)messager   c                    s2   dt t tt ttttf  dd fdd}|S )zProvide a subprocess_runner that shows a spinner message.

    Intended for use with for BuildBackendHookCaller. Thus, the runner has
    an API that matches what's expected by BuildBackendHookCaller.subprocess_runner.
    N)r+   r-   r0   r   c              	      s*   t  }t|  |||d W 5 Q R X d S )N)r5   r-   r0   r2   )r   rr   )r+   r-   r0   r2   rs   r   r   runner   s    
z+runner_with_spinner_message.<locals>.runner)NN)r   r    r   r   r   )rs   ru   r   rt   r   runner_with_spinner_message   s    	  rv   )	FNr*   NNNNTF)#rH   rL   r   rQ   typingr   r   r   r   r   r   r   r	   Zpip._vendor.rich.markupr
   pip._internal.cli.spinnersr   r   pip._internal.exceptionsr   pip._internal.utils.loggingr   r   pip._internal.utils.miscr   r   r    CommandArgsr   r&   r)   boolintrr   rv   r   r   r   r   <module>   sP   ( 	         

 )