B
    H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   s6   g }x,| D ]$}t |tr$|| q
|| q
W |S )z&
    Create a CommandArgs object.
    )
isinstancelistextendappend)r   command_argsarg r   r/var/www/downstreamdata.science/rtclock/rtclock-venv/lib/python3.7/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   secret)r!   r   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|
| x|D ]}||d qvW y0tjt| tjtj|	stjntj||dd}W n6 tk
r } z|rt d||
  W dd}~X Y nX g }|	s|jst|jst|j  xN|j }|s2P | }||d  || |r |s`t|  q W z|  W d|jr|j  X d|}n\| \}}x| D ]}|| qW || x| D ]}|| qW || |}|jo|j|k}|r6|st|r,| d n
| d	 |r|d
krt!|
|j|sX|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criticalr6   AssertionErrorr5   closereadlinerstripr   spinwaitr#   communicate
splitlines
returncodefinishr   r<   r
   r$   warning
ValueError)r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   log_subprocess
used_levelshowing_subprocessuse_spinnerr8   nameprocexc
all_outputlineoutputouterrout_lineerr_lineproc_had_errorr<   r   r   r   call_subprocessG   s    














rp   ).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+   r.   r   c          	      s*   t  }t|  |||d W d Q R X d S )N)r3   r+   r.   r0   )r   rp   )r)   r+   r.   r0   )rq   r   r   runner   s    
z+runner_with_spinner_message.<locals>.runner)NN)r   r    r   r   r   )rq   rr   r   )rq   r   runner_with_spinner_message   s    	 
rs   )	FNr(   NNNNTF)#rF   rJ   r   rO   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intrp   rs   r   r   r   r   <module>   s8   ( 	        N 