U ��.e�&� @sddlmZddlZddlZddlZddlmZddlmZddl m Z m Z ddl m Z ddlmZmZddlmZdd lmZer�dd lmZmZmZmZmZmZmZmZdd lmZeeeefZ d Z!d d�Z"dd�Z#dd�Z$dd�Z%ddd�Z&dd�Z'dS)�)�absolute_importN)� shlex_quote)�InstallationError)�console_to_str�str_to_display)�subprocess_logger)� HiddenText�path_to_display)�MYPY_CHECK_RUNNING)� open_spinner)�Any�Callable�Iterable�List�Mapping�Optional�Text�Union)�SpinnerInterfacez(----------------------------------------cGs2g}|D]$}t|t�r"|�|�q|�|�q|S)z& Create a CommandArgs object. )� isinstance�list�extend�append)�argsZ command_args�arg�r�B/usr/lib/python3.8/site-packages/pip/_internal/utils/subprocess.py� make_commands    rcCsd�dd�|D��S)z/ Format command arguments for display. � css,|]$}t|t�rtt|��nt|�VqdS)N)rrr�str��.0rrrr� ;s�z&format_command_args..)�join�rrrr�format_command_args1s �r%cCsdd�|D�S)z= Return the arguments in their raw, unredacted form. cSs g|]}t|t�r|jn|�qSr)rrZsecretr rrr� Fsz'reveal_command_args..rr$rrr�reveal_command_argsAs�r'c CsDt|�}t|dd�}t|�}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 bytes)Zdesc�z�Command 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_displayZ line_count�outputZdivider)r%rr r#�format�len� LOG_DIVIDER) �cmd_args�cwd�linesr)Zcommandr*r+r,�msgrrr�make_subprocess_output_errorKs   � �r4F�raiseTc  Cs4|dkr g}|dkrg}|r*tj} tj} n tj} tj} t��| k} | oN|dk } |dkr`t|�}| d|�tj � �}|r�|� |�|D]}|� |d�q�z.t jt|�t jt jt j||d�}|j��Wn6tk r�}z| r�t�d||��W5d}~XYnXg}t|j���}|�s�qJ|��}|�|d�| |�| �r|���qz |��W5|j�rj|j��X|j�o||j|k}| �r�|�r�|�d�n |�d�|�r*|dk�r�| �s�| �r�t||||jd �}t� |�d �!|j|�}t"|��n:|d k�rt�#d ||j|�n|d k�rnt$dt%|���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. NzRunning command %s)�stderr�stdin�stdoutr1�envz#Error %s while executing command %s� �errorZdoner5)r0r1r2r)zSCommand errored out with exit status {}: {} Check the logs for full command output.�warnz$Command "%s" had error code %s in %s�ignorezInvalid value: on_returncode=%sr()'r�info�logging�INFO�debug�DEBUGZgetEffectiveLevelr%�os�environ�copy�update�pop� subprocess�Popenr'ZSTDOUT�PIPEr7�close� ExceptionZcriticalrr8�readline�rstriprZspin�wait� returncodeZfinishr4r;r-rZwarning� ValueError�reprr#)�cmdZ show_stdoutr1Z on_returncodeZextra_ok_returncodesZ command_desc� extra_environZ unset_environ�spinnerZlog_failed_cmdZlog_subprocessZ used_levelZshowing_subprocessZ use_spinnerr9�name�proc�excZ all_output�lineZproc_had_errorr3Zexc_msgrrr�call_subprocessus�    ��   �    � ��  � �rZcsd�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. Nc s(t���}t||||d�W5QRXdS)N)r1rTrU)r rZ)rSr1rTrU��messagerr�runners �z+runner_with_spinner_message..runner)NNr)r\r]rr[r�runner_with_spinner_messages �r^) FNr5NNNNNT)(Z __future__rr?rCrHZpip._vendor.six.movesrZpip._internal.exceptionsrZpip._internal.utils.compatrrZpip._internal.utils.loggingrZpip._internal.utils.miscrr Zpip._internal.utils.typingr Zpip._internal.utils.uir �typingr r rrrrrrrrZ CommandArgsr/rr%r'r4rZr^rrrr�s>      (  ,�