ó
Ð²Ebc           @@  sk  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 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 rd  d
 l m Z m Z m Z m Z m Z m Z m Z 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( e& d „
 Z) d „  Z* d S(   i    (   t   absolute_importN(   t   shlex_quote(   t   SpinnerInterfacet   open_spinner(   t   InstallationSubprocessError(   t   console_to_strt   str_to_display(   t   subprocess_logger(   t
   HiddenTextt   path_to_display(   t   MYPY_CHECK_RUNNING(   t   Anyt   Callablet   Iterablet   Listt   Mappingt   Optionalt   Textt   Unions(   ----------------------------------------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-UPPWic/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-UPPWic/pip/pip/_internal/utils/subprocess.pys	   <genexpr>6   s   (   t   join(   R   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/subprocess.pyt   format_command_args+   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-UPPWic/pip/pip/_internal/utils/subprocess.pyt   reveal_command_args;   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-UPPWic/pip/pip/_internal/utils/subprocess.pyt   make_subprocess_output_errorE   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Ð WyO t j t |  ƒ d t j d t j d |
 s t j n t j d | d | ƒ} Wn2 t k
 rm} |	 rgt j d | | ƒ n  ‚  n Xg  } |
 sT| j s‰t ‚ | j s˜t ‚ | j j ƒ  xo t rt | j j ƒ  ƒ } | sÍPn  | j ƒ  } | j | d ƒ | | ƒ | r¨| st ‚ | j ƒ  q¨q¨Wz | j ƒ  Wd	 | j rA| j j ƒ  n  Xd
 j  | ƒ } nŒ | j! ƒ  \ } } t | ƒ } x | j" ƒ  D] } | | ƒ qW| j | ƒ t | ƒ } x | j" ƒ  D] } | | ƒ q¹W| j | ƒ | } | j# oõ| j# | k } | r0| s
t ‚ | r | j$ d ƒ q0| j$ d ƒ n  | rç| d k r˜| rƒ|	 rƒt% d |  d | d | d | j# ƒ } t j& | ƒ n  t' | j# | ƒ ‚ qç| d k rÀt j( d | | j# | ƒ qç| d k rÏqçt) d j* | ƒ ƒ ‚ n  | 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.
      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.
    s   Running command %st   stdint   stdoutt   stderrR.   t   envs#   Error %s while executing command %ss   
NR#   t   errort   doneR3   R-   R/   R$   t   warns$   Command "%s" had error code %s in %st   ignores!   Invalid value: on_returncode={!r}(+   t   NoneR   t   infot   loggingt   INFOt   debugt   DEBUGt   getEffectiveLevelR   t   ost   environt   copyt   updatet   popt
   subprocesst   PopenR!   t   PIPEt   STDOUTt	   Exceptiont   criticalR5   t   AssertionErrorR4   t   closet   TrueR   t   readlinet   rstripR   t   spint   waitR   t   communicatet
   splitlinest
   returncodet   finishR2   R8   R   t   warningt
   ValueErrorR*   (   t   cmdt   show_stdoutR.   t   on_returncodet   extra_ok_returncodest   command_desct   extra_environt   unset_environt   spinnert   log_failed_cmdt   stdout_onlyt   log_subprocesst
   used_levelt   showing_subprocesst   use_spinnerR7   t   namet   proct   exct
   all_outputt   lineR(   t	   out_bytest	   err_bytest   outt   out_linet   errt   err_linet   proc_had_errorR1   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/subprocess.pyt   call_subprocesso   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`   Rb   (   R   Ru   (   R[   R.   R`   Rb   (   t   message(    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/subprocess.pyt   runner  s    N(   R<   (   Rv   Rw   (    (   Rv   s;   /tmp/pip-build-UPPWic/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.cli.spinnersR   R   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   typingR   R   R   R   R   R   R   R   R   t   CommandArgsR,   R   R   R!   R2   t   FalseR<   RP   Ru   Rx   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/subprocess.pyt   <module>   s:   :			
	,›