U
    „~$h#  ã                   @   sh  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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)ÚAnyÚCallableÚIterableÚListÚLiteralÚMappingÚOptionalÚUnion)Úescape)ÚSpinnerInterfaceÚopen_spinner)ÚInstallationSubprocessError)ÚVERBOSEÚsubprocess_logger)Ú
HiddenText)Ú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   úB/tmp/pip-unpacked-wheel-g27rp152/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_args"   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>5   s     z'reveal_command_args.<locals>.<listcomp>r   r$   r   r   r   Úreveal_command_args1   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|	s¤tjntj||dd�}W n6 tk
rì } z|rÚt  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�r¬t!|
|j|�sJ|ndd�}|�r¦t j"d|ddid� t jdt#t$| ƒƒddid� t jdt#|�p˜dƒddid� |‚n8|dk�rÊt  %d|
|j|¡ n|dk�rÖn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)   )Zcommand_descriptionZ	exit_codeZoutput_linesz%sZrichT)Úextraz*[bold magenta]full command[/]: [blue]%s[/]Zmarkupz[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Úcriticalr7   ÚAssertionErrorr6   ÚcloseÚreadlineÚrstripr   ÚspinÚwaitr#   ÚcommunicateÚ
splitlinesÚ
returncodeÚfinishr   r=   r
   r%   ÚwarningÚ
ValueError)r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   Úlog_subprocessÚ
used_levelÚshowing_subprocessÚuse_spinnerr9   ÚnameÚprocÚexcÚ
all_outputÚlineÚoutputÚoutÚerrZout_lineZerr_lineÚproc_had_errorr=   r   r   r   Úcall_subprocess8   sÆ    


ø

ý







ý
ýý
ü
rk   ).N)Úmessager   c                    s2   dt t tt ttttf  ddœ‡ fdd„}|S )zßProvide 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 5 Q R X d S )N)r4   r,   r/   r1   )r   rk   )r*   r,   r/   r1   ©rl   r   r   Úrunnerç   s    
ûz+runner_with_spinner_message.<locals>.runner)NN)r   r   r   r   r   )rl   rn   r   rm   r   Úrunner_with_spinner_messageà   s    	  ýüro   )	FNr)   NNNNTF)"rC   rG   r   rL   Útypingr   r   r   r   r   r   r   r	   Zpip._vendor.rich.markupr
   Zpip._internal.cli.spinnersr   r   Úpip._internal.exceptionsr   Úpip._internal.utils.loggingr   r   Úpip._internal.utils.miscr   r   ZCommandArgsr   r%   r(   ÚboolÚintrk   ro   r   r   r   r   Ú<module>   sL   ( 	         ö

ó )