a
    ñ»j#  ã                   @  s  d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZmZmZ d dl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
ddœdd„Zdddœdd„Zdddœdd„Zd(ddddddddd d ddd!œd"d#„Z dd$d%œd&d'„Z!dS ))é    )ÚannotationsN)ÚIterableÚMapping)ÚAnyÚCallableÚLiteralÚUnion)Úescape)ÚSpinnerInterfaceÚopen_spinner)ÚInstallationSubprocessError)ÚVERBOSEÚsubprocess_logger)Ú
HiddenTextzstr | HiddenText | CommandArgsÚCommandArgs)ÚargsÚreturnc                  G  s2   g }| D ]$}t |tƒr"| |¡ q| |¡ q|S )z&
    Create a CommandArgs object.
    )Ú
isinstanceÚlistÚextendÚappend)r   Úcommand_argsÚarg© r   úDE:\soccer\ml_env\Lib\site-packages\pip/_internal/utils/subprocess.pyÚmake_command   s    
r   zlist[str] | CommandArgsÚstrc                 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   ÚshlexÚquoter   ©Ú.0r   r   r   r   Ú	<genexpr>.   s   ÿz&format_command_args.<locals>.<genexpr>)Újoin©r   r   r   r   Úformat_command_args%   s    	
þr%   ú	list[str]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>8   ó    z'reveal_command_args.<locals>.<listcomp>r   r$   r   r   r   Úreveal_command_args4   s    r*   FÚraiseTÚboolú
str | Nonez"Literal['raise', 'warn', 'ignore']zIterable[int] | NoneúMapping[str, Any] | NonezIterable[str] | NonezSpinnerInterface | Nonezbool | None)ÚcmdÚshow_stdoutÚcwdÚon_returncodeÚextra_ok_returncodesÚextra_environÚunset_environÚspinnerÚlog_failed_cmdÚstdout_onlyÚcommand_descr   c
             
   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|
ƒ tj 	¡ }|rp| 
|¡ |D ]}| |d¡ qtz0tjt| ƒtjtj|	s¤tjntj||dd�}W n8 tyî } z |rØt  d||
¡ ‚ W Y d}~n
d}~0 0 g }|	�sª|j�sJ ‚|j�sJ ‚|j ¡  |j ¡ }|�s0�qj| ¡ }| |d ¡ ||ƒ |�r|�s^J ‚| ¡  �qz| ¡  W |j�rž|j ¡  n|j�rœ|j ¡  0 d |¡}nT| ¡ \}}| ¡ D ]}||ƒ �q¾| |¡ | ¡ D ]}||ƒ �qà| |¡ |}|j�o|j|v}|�r<|�s J ‚|�r2| d¡ n
| d	¡ |�rø|d
k�rÀt |
|j|�s^|ndd�}|�rºt j!d|ddid� t jdt"t#| ƒƒddid� t jdt"|�p¬dƒddid� |‚n8|dk�rÞt  $d|
|j|¡ n|dk�rên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 %sÚ
Ú ÚerrorÚdoner+   )Úcommand_descriptionÚ	exit_codeÚoutput_linesz%sÚrichT)Úextraz*[bold magenta]full command[/]: [blue]%s[/]Úmarkupz[bold magenta]cwd[/]: %sz	[inherit]Úwarnz$Command "%s" had error code %s in %sÚignorezInvalid value: on_returncode=)&r   ÚinfoÚloggingÚINFOÚverboser   ÚgetEffectiveLevelÚosÚenvironÚcopyÚupdateÚpopÚ
subprocessÚPopenr*   ÚPIPEÚSTDOUTÚ	ExceptionÚcriticalr<   r;   ÚcloseÚreadlineÚrstripr   ÚspinÚwaitr#   ÚcommunicateÚ
splitlinesÚ
returncodeÚfinishr   rB   r	   r%   ÚwarningÚ
ValueError)r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   Úlog_subprocessÚ
used_levelÚshowing_subprocessÚuse_spinnerr>   ÚnameÚprocÚexcÚ
all_outputÚlineÚoutputÚoutÚerrÚout_lineÚerr_lineÚproc_had_errorrB   r   r   r   Úcall_subprocess;   sÊ    


ø

ý



ÿ




ý
ýý
ü
rv   zCallable[..., None])Úmessager   c                   s   d	dddddœ‡ fdd„}|S )
zßProvide a subprocess_runner that shows a spinner message.

    Intended for use with for BuildBackendHookCaller. Thus, the runner has
    an API that matches what's expected by BuildBackendHookCaller.subprocess_runner.
    Nr&   r-   r.   ÚNone)r/   r1   r4   r   c                   s>   t ˆ ƒ�"}t| ˆ |||d� W d   ƒ n1 s00    Y  d S )N)r9   r1   r4   r6   )r   rv   )r/   r1   r4   r6   ©rw   r   r   Úrunnerê   s    
ûz+runner_with_spinner_message.<locals>.runner)NNr   )rw   rz   r   ry   r   Úrunner_with_spinner_messageã   s    	  ýr{   )	FNr+   NNNNTF)"Ú
__future__r   rM   rQ   r   rV   Úcollections.abcr   r   Útypingr   r   r   r   Zpip._vendor.rich.markupr	   Úpip._internal.cli.spinnersr
   r   Úpip._internal.exceptionsr   Úpip._internal.utils.loggingr   r   Úpip._internal.utils.miscr   r   r   r   r   r%   r*   rv   r{   r   r   r   r   Ú<module>   s6   	         ö& )