U jaT( @sddlZddlZddlZddlZddlmZmZmZmZm Z m Z m Z ddl m Z mZddlmZddlmZmZddlmZee eefZdZdd Zd d Zd d ZddZdddZddZdS)N)AnyCallableIterableListMappingOptionalUnion)SpinnerInterface open_spinner)InstallationSubprocessError)VERBOSEsubprocess_logger) HiddenTextz(----------------------------------------cGs2g}|D]$}t|tr"||q||q|S)z& Create a CommandArgs object. ) isinstancelistextendappend)args command_argsargrv/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-bug3gbve/pip/_internal/utils/subprocess.py make_commands    rcCsddd|DS)z/ Format command arguments for display.  css0|](}t|trtt|nt|VqdS)N)rrshlexquotestr.0rrrr .sz&format_command_args..)joinrrrrformat_command_args$s r"cCsdd|DS)z= Return the arguments in their raw, unredacted form. cSs g|]}t|tr|jn|qSr)rrsecretrrrr 9sz'reveal_command_args..rr!rrrreveal_command_args4sr%cCs0t|}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}) exit_statuscommand_display cwd_display line_countoutputdivider)r"r formatlen LOG_DIVIDER)cmd_argscwdlinesr'commandr+msgrrrmake_subprocess_output_error<s   r5FraiseTc  Cs|dkr g}|dkrg}|r*tj} tj} n tj} t} t| k} | oL|dk }|dkr^t|}| d|tj }|r| ||D]}| |dqz0t jt|t jt j| st jnt j||dd}Wn6tk r}z| rtd||W5d}~XYnXg}| s|jst|js t|j|j}|s>qx|}||d| ||r*|slt|q*z |W5|jr|jXd|}nT|\}}|D]}| |q|||D]}| |q|||}|j o |j |k}|r8|st|r.|!dn |!d |r|d kr~| sp| rpt"||||j d }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)stdinstdoutstderrr1enverrorsz#Error %s while executing command %s r&errordoner6)r0r1r2r'warnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=)'r infologgingINFOverboser getEffectiveLevelr"osenvironcopyupdatepop subprocessPopenr%PIPESTDOUT Exceptioncriticalr9AssertionErrorr8closereadlinerstriprspinwaitr communicate splitlines returncodefinishr5r>r warning ValueError)cmd show_stdoutr1 on_returncodeextra_ok_returncodes command_desc extra_environ unset_environspinnerlog_failed_cmdZ stdout_onlylog_subprocess used_levelshowing_subprocess use_spinnerr;nameprocexc all_outputliner+outerrZout_lineZerr_lineproc_had_errorr4rrrcall_subprocess`s                             rscsdfdd }|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. Nc s(t}t||||dW5QRXdS)N)r1rcre)r rs)r^r1rcremessagerrrunner s z+runner_with_spinner_message..runner)NNr)rurvrrtrrunner_with_spinner_messages rw) FNr6NNNNNTF)rCrGrrLtypingrrrrrrrpip._internal.cli.spinnersr r pip._internal.exceptionsr pip._internal.utils.loggingr r pip._internal.utils.miscrrZ CommandArgsr/rr"r%r5rsrwrrrrs6$  & $