a [fJ'@sddlZddlZddlZddlZddlmZmZmZmZm Z m Z m Z m Z ddl mZmZddlmZddlmZmZddlmZerddlmZe e eefZdZe eeefed d d Ze e eefed d d Ze e eefe ed ddZe e eefe ee eeedddZde e eefe e ede eee ee e eefe eee ee e e e ed ddZ!eeddddZ"dS)N) TYPE_CHECKINGAnyCallableIterableListMappingOptionalUnion)SpinnerInterface open_spinner)InstallationSubprocessError)VERBOSEsubprocess_logger) HiddenText)Literalz(----------------------------------------)argsreturncGs2g}|D]$}t|tr"||q||q|S)z& Create a CommandArgs object. ) isinstancelistextendappend)rZ command_argsargrB/usr/lib/python3.9/site-packages/pip/_internal/utils/subprocess.py make_command!s    rcCsddd|DS)z/ Format command arguments for display.  css0|](}t|trtt|nt|VqdS)N)rrshlexquotestr.0rrrr ;sz&format_command_args..)joinrrrrformat_command_args2s r$cCsdd|DS)z= Return the arguments in their raw, unredacted form. cSs g|]}t|tr|jn|qSr)rrZsecretrrrr Ez'reveal_command_args..rr#rrrreveal_command_argsAsr')cmd_argscwdlines 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. zCommand errored out with exit status {exit_status}: command: {command_display} cwd: {cwd_display} Complete output ({line_count} lines): {output}{divider})r+Zcommand_displayZ cwd_displayZ line_countoutputZdivider)r$r"formatlen LOG_DIVIDER)r(r)r*r+Zcommandr-msgrrrmake_subprocess_output_errorHs   r2FraiseTz"Literal["raise", "warn", "ignore"]) cmd show_stdoutr) on_returncodeextra_ok_returncodes command_desc extra_environ unset_environspinnerlog_failed_cmd stdout_onlyrc  Cs|dur g}|durg}|r*tj} tj} n tj} t} t| k} | oL|du}|dur^t|}| d|tj }|r| ||D]}| |dqz0t jt|t jt j| st jnt j||dd}Wn8ty}z | rtd||WYd}~n d}~00g}| s|j|j}|s(qX|}||d| ||r|qz|W|jr|jn|jr|j0d|}nT|\}}|D]}| |q|||D]}| |q|||}|jo|j|v}|r |r| dn | d |r|d krf| sX| rXt!||||jd }t"|t#|j|n8|d krt$d ||j|n|dkrnt%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 %sbackslashreplace)stdinstdoutstderrr)enverrorsz#Error %s while executing command %s r,errorZdoner3)r(r)r*r+warnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=)&rinfologgingINFOverboser ZgetEffectiveLevelr$osenvironcopyupdatepop subprocessPopenr'PIPEZSTDOUT ExceptionZcriticalr?closer@readlinerstriprZspinwaitr"Z communicate splitlines returncodeZfinishr2rEr Zwarning ValueError)r4r5r)r6r7r8r9r:r;r<r=Zlog_subprocessZ used_levelZshowing_subprocessZ use_spinnerrBnameprocexcZ all_outputliner-outerrZout_lineZerr_lineZproc_had_errorr1rrrcall_subprocessks                          rb).N)messagercs2dttttttttfddfdd }|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. N)r4r)r9rcs<t }t||||dWdn1s.0YdS)N)r)r9r;)r rb)r4r)r9r;rcrrrunners z+runner_with_spinner_message..runner)NN)rrrrr)rcrerrdrrunner_with_spinner_message s  rf) FNr3NNNNNTF)#rIrLrrQtypingrrrrrrrr Zpip._internal.cli.spinnersr r Zpip._internal.exceptionsr Zpip._internal.utils.loggingr rZpip._internal.utils.miscrrrZ CommandArgsr0rr$r'intr2boolrbrfrrrrs^(      %   #