ó
'—^c        
   @@  sr  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l 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 d  d	 l m Z e rd  d
 l m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z e e e e f Z  n  d Z! d „  Z" d „  Z# d „  Z$ d „  Z% e& d d d d d d d e( d „	 Z) d „  Z* d S(   i    (   t   absolute_importN(   t   shlex_quote(   t   InstallationError(   t   console_to_strt   str_to_display(   t   subprocess_logger(   t
   HiddenTextt   path_to_display(   t   MYPY_CHECK_RUNNING(   t   open_spinner(   t   Anyt   Callablet   Iterablet   Listt   Mappingt   Optionalt   Textt   Union(   t   SpinnerInterfaces(   ----------------------------------------c          G@  sG   g  } x: |  D]2 } t  | t ƒ r2 | j | ƒ q | j | ƒ q W| S(   s&   
    Create a CommandArgs object.
    (   t
   isinstancet   listt   extendt   append(   t   argst   command_argst   arg(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   make_command   s    c         C@  s   d j  d „  |  Dƒ ƒ S(   s/   
    Format command arguments for display.
    t    c         s@  s<   |  ]2 } t  | t ƒ r* t t | ƒ ƒ n	 t | ƒ Vq d  S(   N(   R   R   R   t   str(   t   .0R   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pys	   <genexpr><   s   (   t   join(   R   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   format_command_args1   s    
c         C@  s/   g  |  D]$ } t  | t ƒ r% | j n | ^ q S(   s=   
    Return the arguments in their raw, unredacted form.
    (   R   R   t   secret(   R   R   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   reveal_command_argsA   s    c   	      C@  ss   t  |  ƒ } t | d d ƒ} t | ƒ } d j | ƒ } d j d | d | d | d t | ƒ d	 | d
 t ƒ } | S(   s§   
    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.
    t   descs   command bytest    uŸ   Command errored out with exit status {exit_status}:
 command: {command_display}
     cwd: {cwd_display}
Complete output ({line_count} lines):
{output}{divider}t   exit_statust   command_displayt   cwd_displayt
   line_countt   outputt   divider(   R   R   R   R   t   formatt   lent   LOG_DIVIDER(	   t   cmd_argst   cwdt   linesR$   t   commandR%   R&   R(   t   msg(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   make_subprocess_output_errorK   s    		t   raisec
         C@  s  | d	 k r g  } n  | d	 k r* g  } n  | rE t j }
 t j } n t j }
 t j } t j ƒ  | k } | oy | d	 k	 } | d	 k r— t |  ƒ } n  |
 d | ƒ t	 j
 j ƒ  } | rÉ | j | ƒ n  x | D] } | j | d	 ƒ qÐ WyM t j t |  ƒ d t j d t j d t j d | d | ƒ} | j j ƒ  Wn2 t k
 rk} |	 ret j d | | ƒ n  ‚  n Xg  } xc t r×t | j j ƒ  ƒ } | sšPn  | j ƒ  } | j | d ƒ |
 | ƒ | ru| j ƒ  ququWz | j ƒ  Wd	 | j r| j j ƒ  n  X| j o| j | k } | rG| r7| j  d
 ƒ qG| j  d ƒ n  | r| d k r¾| rš|	 ršt! d |  d | d | d | j ƒ } t j" | ƒ n  d j# | j | ƒ } t$ | ƒ ‚ q| d k ræt j% d | | j | ƒ q| d k rõqt& d t' | ƒ ƒ ‚ n  d j( | ƒ S(   sí  
    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.
    s   Running command %st   stderrt   stdint   stdoutR.   t   envs#   Error %s while executing command %ss   
Nt   errort   doneR3   R-   R/   R$   sS   Command errored out with exit status {}: {} Check the logs for full command output.t   warns$   Command "%s" had error code %s in %st   ignores   Invalid value: on_returncode=%sR#   ()   t   NoneR   t   infot   loggingt   INFOt   debugt   DEBUGt   getEffectiveLevelR   t   ost   environt   copyt   updatet   popt
   subprocesst   PopenR!   t   STDOUTt   PIPER5   t   closet	   Exceptiont   criticalt   TrueR   R6   t   readlinet   rstripR   t   spint   waitt
   returncodet   finishR2   R8   R*   R   t   warningt
   ValueErrort   reprR   (   t   cmdt   show_stdoutR.   t   on_returncodet   extra_ok_returncodest   command_desct   extra_environt   unset_environt   spinnert   log_failed_cmdt   log_subprocesst
   used_levelt   showing_subprocesst   use_spinnerR7   t   namet   proct   exct
   all_outputt   linet   proc_had_errorR1   t   exc_msg(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   call_subprocessu   sŒ    						
	c         @  s   d d ‡  f d † } | S(   sÜ   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.
    c         @  s5   t  ˆ  ƒ # } t |  d | d | d | ƒWd  QXd  S(   NR.   R^   R`   (   R	   Rm   (   RY   R.   R^   R`   (   t   message(    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   runner  s    N(   R<   (   Rn   Ro   (    (   Rn   s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   runner_with_spinner_message   s    
(+   t
   __future__R    R>   RC   RH   t   pip._vendor.six.movesR   t   pip._internal.exceptionsR   t   pip._internal.utils.compatR   R   t   pip._internal.utils.loggingR   t   pip._internal.utils.miscR   R   t   pip._internal.utils.typingR   t   pip._internal.utils.uiR	   t   typingR
   R   R   R   R   R   R   R   R   R   t   CommandArgsR,   R   R   R!   R2   t   FalseR<   RO   Rm   Rp   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/subprocess.pyt   <module>   s:   :			
	,