a
    !6a;'                  
   @   s   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 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dZdd	 Zd
d Zdd Zdd ZdddZdd ZdS )    N)AnyCallableIterableListMappingOptionalUnion)SpinnerInterfaceopen_spinner)InstallationSubprocessError)VERBOSEsubprocess_logger)
HiddenTextz(----------------------------------------c                  G   s2   g }| D ]$}t |tr"|| q|| q|S )z&
    Create a CommandArgs object.
    )
isinstancelistextendappend)argsZcommand_argsarg r   =lib/python3.9/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   shlexZ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   Zsecretr   r   r   r   
<listcomp>9       z'reveal_command_args.<locals>.<listcomp>r   r   r   r   r   reveal_command_args4   s    r#   c                 C   s0   t | }d|}dj|||t||td}|S )z
    Create and return the error message to use to log a subprocess error
    with command output.

    :param lines: A list of lines, each ending with a newline.
     zCommand errored out with exit status {exit_status}:
 command: {command_display}
     cwd: {cwd_display}
Complete output ({line_count} lines):
{output}{divider})exit_statusZcommand_displayZcwd_displayZ
line_countoutputZdivider)r    r   formatlenLOG_DIVIDER)cmd_argscwdlinesr%   Zcommandr&   msgr   r   r   make_subprocess_output_error<   s    
	r.   FraiseTc              
   C   s  |du rg }|du rg }|r*t j}tj}n
t j}t}t  |k}| oL|du}|du r^t| }|d| tj	
 }|r|| |D ]}||d qz0tjt| tjtj|
stjntj||dd}W n8 ty } z |	rt d||  W Y d}~n
d}~0 0 g }|
s|jsJ |js"J |j  |j }|s@qz| }||d  || |r,|snJ |  q,z|  W |jr|j  n|jr|j  0 d|}nT| \}}| D ]}|| q|| | D ]}|| q|| |}|jo|j|v}|rL|s0J |rB| d n
| d	 |r|d
kr|s|	rt!| |||jd}t "| t#|j|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
r$   errorZdoner/   )r*   r+   r,   r%   warnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=)&r   infologgingINFOverboser   ZgetEffectiveLevelr    osenvironcopyupdatepop
subprocessPopenr#   PIPEZSTDOUT	ExceptionZcriticalr2   r1   closereadlinerstripr   Zspinwaitr   Zcommunicate
splitlines
returncodeZfinishr.   r7   r   Zwarning
ValueError)cmdZshow_stdoutr+   Zon_returncodeZextra_ok_returncodesZcommand_descextra_environZunset_environspinnerZlog_failed_cmdZstdout_onlyZlog_subprocessZ
used_levelZshowing_subprocessZuse_spinnerr4   nameprocexcZ
all_outputliner&   outerrZout_lineZerr_lineZproc_had_errorr-   r   r   r   call_subprocess`   s    
















rW   c                    s   d fdd	}|S )zProvide a subprocess_runner that shows a spinner message.

    Intended for use with for pep517's Pep517HookCaller. Thus, the runner has
    an API that matches what's expected by Pep517HookCaller.subprocess_runner.
    Nc                    s<   t   }t| |||d W d    n1 s.0    Y  d S )N)r+   rO   rP   )r
   rW   )rN   r+   rO   rP   messager   r   runner  s    
z+runner_with_spinner_message.<locals>.runner)NNr   )rY   rZ   r   rX   r   runner_with_spinner_message  s    
  r[   )
FNr/   NNNNNTF)r;   r>   r   rC   typingr   r   r   r   r   r   r   Zpip._internal.cli.spinnersr	   r
   Zpip._internal.exceptionsr   Zpip._internal.utils.loggingr   r   Zpip._internal.utils.miscr   r   ZCommandArgsr)   r   r    r#   r.   rW   r[   r   r   r   r   <module>   s6   $&          
 $