3 igJ'@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(----------------------------------------)argsreturncGs6g}x,|D]$}t|tr$|j|q |j|q W|S)z& Create a CommandArgs object. ) isinstancelistextendappend)rZ command_argsargr=/tmp/pip-build-88gy_88q/pip/pip/_internal/utils/subprocess.py make_command!s    rcCsdjdd|DS)z/ Format command arguments for display.  css0|](}t|trtjt|ntj|VqdS)N)rrshlexquotestr).0rrrr <sz&format_command_args..)join)rrrrformat_command_args2s r"cCsdd|DS)z= Return the arguments in their raw, unredacted form. cSs g|]}t|tr|jn|qSr)rrZsecret)rrrrr Esz'reveal_command_args..r)rrrrreveal_command_argsAsr$)cmd_argscwdlines exit_statusrcCs0t|}dj|}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(commandr*msgrrrmake_subprocess_output_errorHs  r0FraiseTz"Literal["raise", "warn", "ignore"]) cmd show_stdoutr& on_returncodeextra_ok_returncodes command_desc extra_environ unset_environspinnerlog_failed_cmd stdout_onlyrc Cs|dkr g}|dkrg}|r*tj} tj} n tj} t} tj| k} | oL|dk }|dkr^t|}| d|tj j }|r|j |x|D]}|j |dqWy0t jt|t jt j| st jnt j||dd}Wn8tk r}z| rtjd||WYdd}~XnXg}| s|jst|js&t|jjxN|jj}|sDP|j}|j|d| ||r2|srt|jq2Wz |jWd|jr|jjXdj|}n\|j\}}x|jD]}| |qW|j|x|jD]}| |qW|j||}|j o|j |k}|rH|s,t|r>|j!dn |j!d |r|d kr| r| rt"||||j d }tj#|t$|j |n8|d krtj%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)errordoner1)r%r&r'r(warnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=)'rinfologgingINFOverboser getEffectiveLevelr"osenvironcopyupdatepop subprocessPopenr$PIPESTDOUT Exceptioncriticalr>AssertionErrorr=closereadlinerstriprspinwaitr! communicate splitlines returncodefinishr0rCr warning ValueError)r2r3r&r4r5r6r7r8r9r:r;Zlog_subprocessZ used_levelZshowing_subprocessZ use_spinnerr@nameprocexc all_outputliner*outerrZout_lineZerr_lineZproc_had_errorr/rrrcall_subprocessks                         rj.)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)r2r&r7rc s(t}t||||dWdQRXdS)N)r&r7r9)r rj)r2r&r7r9)rkrrrunners  z+runner_with_spinner_message..runner)NN)rrrrr)rkrlr)rkrrunner_with_spinner_message s  rm) FNr1NNNNNTF).N)#rHrLrrQZtypingrrrrrrrr Zpip._internal.cli.spinnersr r Zpip._internal.exceptionsr Zpip._internal.utils.loggingr rZpip._internal.utils.miscrrrZ CommandArgsr-rr"r$intr0boolrjrmrrrrsB(      T