o
    0g;'                     @   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)argscommand_argsarg r   e/home/www/bk.finsightngr.online/venv20/lib/python3.10/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   s2    | ]}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>9   s     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_statuscommand_displaycwd_display
line_countoutputdivider)r"   r    formatlenLOG_DIVIDER)cmd_argscwdlinesr'   commandr+   msgr   r   r   make_subprocess_output_error<   s   
r5   FraiseTc              
   C   s  |du rg }|du rg }|rt j}tj}nt j}t}t  |k}| o&|du}|du r/t| }|d| tj	
 }|r@|| |D ]}||d qBztjt| tjtj|
sZtjntj||dd}W n tyy } z
|	rtt d||  d}~ww g }|
s|jsJ |jsJ |j  	 |j }|sq| }||d  || |r|sJ |  qz|  W |jr|j  n
|jr|j  w w d|}n(| \}}| D ]}|| q|| | D ]}|| q|| |}|jo|j|v}|r|sJ |r| d	 n| d
 |rV|dkr7|s1|	r1t!| |||jd}t "| t#|j||dkrGt $d||j| |S |dkrO	 |S 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stderrr1   enverrorsz#Error %s while executing command %sT
r&   errordoner6   )r0   r1   r2   r'   warnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=)&r   infologgingINFOverboser   getEffectiveLevelr"   osenvironcopyupdatepop
subprocessPopenr%   PIPESTDOUT	Exceptioncriticalr9   r8   closereadlinerstripr   spinwaitr    communicate
splitlines
returncodefinishr5   r>   r   warning
ValueError)cmdshow_stdoutr1   on_returncodeextra_ok_returncodescommand_descextra_environunset_environspinnerlog_failed_cmdstdout_onlylog_subprocess
used_levelshowing_subprocessuse_spinnerr;   nameprocexc
all_outputliner+   outerrout_lineerr_lineproc_had_errorr4   r   r   r   call_subprocess`   s   





















ru   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    d S 1 sw   Y  d S )N)r1   rb   rd   )r
   ru   )r]   r1   rb   rd   messager   r   runner  s   
"z+runner_with_spinner_message.<locals>.runner)NNr   )rw   rx   r   rv   r   runner_with_spinner_message  s   
ry   )
FNr6   NNNNNTF)rC   rG   r   rL   typingr   r   r   r   r   r   r   pip._internal.cli.spinnersr	   r
   pip._internal.exceptionsr   pip._internal.utils.loggingr   r   pip._internal.utils.miscr   r   CommandArgsr/   r   r"   r%   r5   ru   ry   r   r   r   r   <module>   s8    $&
 $