Current File : //lib/python3.9/site-packages/pip/_internal/utils/__pycache__/subprocess.cpython-39.pyc
a

[��fJ'�@s�ddlZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZddl
mZmZddlmZddlmZmZddlmZer�ddlmZe	eeefZdZeeeefed	�d
d�Zee	eefed	�dd
�Zee	eefe	ed	�dd�Zee	eefeee	eeed�dd�Zdee	eefe eedeeeeeee
eefeeeeeee ee ed�dd�Z!eedd�dd�Z"dS)�N)�
TYPE_CHECKING�Any�Callable�Iterable�List�Mapping�Optional�Union)�SpinnerInterface�open_spinner)�InstallationSubprocessError)�VERBOSE�subprocess_logger)�
HiddenText)�Literalz(----------------------------------------)�args�returncGs2g}|D]$}t|t�r"|�|�q|�|�q|S)z&
    Create a CommandArgs object.
    )�
isinstance�list�extend�append)rZcommand_args�arg�r�B/usr/lib/python3.9/site-packages/pip/_internal/utils/subprocess.py�make_command!s
rcCsd�dd�|D��S)z/
    Format command arguments for display.
    � css0|](}t|t�rt�t|��nt�|�VqdS)N)rr�shlex�quote�str��.0rrrr�	<genexpr>;s�z&format_command_args.<locals>.<genexpr>)�join�rrrr�format_command_args2s	
�r$cCsdd�|D�S)z=
    Return the arguments in their raw, unredacted form.
    cSs g|]}t|t�r|jn|�qSr)rrZsecretrrrr�
<listcomp>E�z'reveal_command_args.<locals>.<listcomp>rr#rrr�reveal_command_argsAsr')�cmd_args�cwd�lines�exit_statusrcCs0t|�}d�|�}dj|||t|�|td�}|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.
    �z�Command errored out with exit status {exit_status}:
 command: {command_display}
     cwd: {cwd_display}
Complete output ({line_count} lines):
{output}{divider})r+Zcommand_displayZcwd_displayZ
line_count�outputZdivider)r$r"�format�len�LOG_DIVIDER)r(r)r*r+Zcommandr-�msgrrr�make_subprocess_output_errorHs
�	�r2F�raiseTz"Literal["raise", "warn", "ignore"])�cmd�show_stdoutr)�
on_returncode�extra_ok_returncodes�command_desc�
extra_environ�
unset_environ�spinner�log_failed_cmd�stdout_onlyrc
Cs�|durg}|durg}|r*tj}tj}n
tj}t}t��|k}
|
oL|du}|dur^t|�}|d|�tj	�
�}|r�|�|�|D]}|�|d�q�z0t
jt|�t
jt
j|
s�t
jnt
j||dd�}Wn8ty�}z |	r�t�d||��WYd}~n
d}~00g}|
�s�|j�sJ�|j�s"J�|j��|j��}|�s@�qz|��}|�|d�||�|�r,|�snJ�|���q,z|��W|j�r�|j��n|j�r�|j��0d�|�}nT|��\}}|��D]}||��q�|�|�|��D]}||��q�|�|�|}|j�o|j|v}|�rL|�s0J�|�rB|� d�n
|� d	�|�r�|d
k�r�|
�s�|	�r�t!||||jd�}t�"|�t#|j|��n8|dk�r�t�$d
||j|�n|dk�r�nt%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.
    NzRunning command %s�backslashreplace)�stdin�stdout�stderrr)�env�errorsz#Error %s while executing command %s�
r,�errorZdoner3)r(r)r*r+�warnz$Command "%s" had error code %s in %s�ignorezInvalid value: on_returncode=)&r�info�logging�INFO�verboser
ZgetEffectiveLevelr$�os�environ�copy�update�pop�
subprocess�Popenr'�PIPEZSTDOUT�	ExceptionZcriticalr@r?�close�readline�rstriprZspin�waitr"Zcommunicate�
splitlines�
returncodeZfinishr2rErZwarning�
ValueError)r4r5r)r6r7r8r9r:r;r<r=Zlog_subprocessZ
used_levelZshowing_subprocessZuse_spinnerrB�name�proc�excZ
all_output�liner-�out�errZout_lineZerr_lineZproc_had_errorr1rrr�call_subprocessks�


�

�



�




�

�
rb).N)�messagercs2dttttttttfdd��fdd�
}|S)z�Provide 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.
    N)r4r)r9rcs<t��� }t||||d�Wd�n1s.0YdS)N)r)r9r;)rrb)r4r)r9r;�rcrr�runners
�z+runner_with_spinner_message.<locals>.runner)NN)rrrrr)rcrerrdr�runner_with_spinner_message
s	��
rf)
FNr3NNNNNTF)#rIrLrrQ�typingrrrrrrrr	Zpip._internal.cli.spinnersr
rZpip._internal.exceptionsrZpip._internal.utils.loggingr
rZpip._internal.utils.miscrrrZCommandArgsr0rr$r'�intr2�boolrbrfrrrr�<module>s^( �%�

�#