o
    f}”eJ'  ã                   @   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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rHd dlmZ e	eeef  ZdZd	eeeef d
efdd„Zd	ee	e ef d
efdd„Zd	ee	e ef d
e	e fdd„Zdee	e ef dee de	e ded
ef
dd„Z										d+dee	e ef de dee dddeee  dee d ee
eef  d!eee  d"ee d#ee  d$ee  d
efd%d&„Z!d'ed
ed( fd)d*„Z"dS ),é    N)ÚTYPE_CHECKINGÚAnyÚCallableÚIterableÚListÚMappingÚOptionalÚUnion)ÚSpinnerInterfaceÚopen_spinner)ÚInstallationSubprocessError)ÚVERBOSEÚsubprocess_logger)Ú
HiddenText)ÚLiteralz(----------------------------------------ÚargsÚreturnc                  G   s2   g }| D ]}t |tƒr| |¡ q| |¡ q|S )z&
    Create a CommandArgs object.
    )Ú
isinstanceÚlistÚextendÚappend)r   Zcommand_argsÚarg© r   úg/Users/abhinavbhinder/Documents/map/venv/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_args2   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>E   s     z'reveal_command_args.<locals>.<listcomp>r   r#   r   r   r   Úreveal_command_argsA   s   r'   Úcmd_argsÚcwdÚlinesÚexit_statusc                 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.
    Ú zŸCommand errored out with exit status {exit_status}:
 command: {command_display}
     cwd: {cwd_display}
Complete output ({line_count} lines):
{output}{divider})r+   Zcommand_displayZcwd_displayZ
line_countÚoutputZdivider)r$   r"   ÚformatÚlenÚLOG_DIVIDER)r(   r)   r*   r+   Úcommandr-   Úmsgr   r   r   Úmake_subprocess_output_errorH   s   
òr3   FÚraiseTÚcmdÚshow_stdoutÚon_returncodez"Literal["raise", "warn", "ignore"]Úextra_ok_returncodesÚcommand_descÚextra_environÚunset_environÚspinnerÚlog_failed_cmdÚstdout_onlyc              
   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sƒJ ‚|jsˆJ ‚|j ¡  	 |j ¡ }|s–n| ¡ }| |d ¡ ||ƒ |r¯|s«J ‚| ¡  qŽz| ¡  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Ústderrr)   ÚenvÚerrorsz#Error %s while executing command %sTÚ
r,   ÚerrorÚdoner4   )r(   r)   r*   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ÚcriticalrA   r@   ÚcloseÚreadlineÚrstripr   ZspinÚwaitr"   ÚcommunicateÚ
splitlinesÚ
returncodeÚfinishr3   rF   r   ÚwarningÚ
ValueError)r5   r6   r)   r7   r8   r9   r:   r;   r<   r=   r>   Zlog_subprocessZ
used_levelZshowing_subprocessZuse_spinnerrC   ÚnameÚprocÚexcZ
all_outputÚliner-   ÚoutÚerrZout_lineZerr_lineZproc_had_errorr2   r   r   r   Úcall_subprocessk   sÌ   



ø
ý€ù



ô

€ÿÿ






ü

ü

üÿrj   Úmessage).Nc              
      s<   		ddt t dtt dttttf  ddf‡ fdd„}|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.
    Nr5   r)   r:   r   c                    s>   t ˆ ƒ�}t| |||d� W d   ƒ d S 1 sw   Y  d S )N)r)   r:   r<   )r   rj   )r5   r)   r:   r<   ©rk   r   r   Úrunner  s   
ü"ÿz+runner_with_spinner_message.<locals>.runner)NN)r   r   r   r   r   )rk   rm   r   rl   r   Úrunner_with_spinner_message  s   	ýÿþýürn   )
FNr4   NNNNNTF)#rK   rO   r   rT   Útypingr   r   r   r   r   r   r   r	   Zpip._internal.cli.spinnersr
   r   Úpip._internal.exceptionsr   Úpip._internal.utils.loggingr   r   Úpip._internal.utils.miscr   r   r   ZCommandArgsr0   r   r$   r'   Úintr3   Úboolrj   rn   r   r   r   r   Ú<module>   s€    ("ÿþýü
û%õÿþýü
ûúù
ø	÷
öõ
ô #