
'^c           @@  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 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 d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z m  Z  m! Z! d d l" m# Z# d d l$ m% Z% d d l& m' Z' d d l( m) Z) e% rd d l* m+ Z+ d d l, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 d d l8 m9 Z9 e1 e: d f Z; n  e j< e=  Z> d   Z? d d >d  Z@ d   ZA d   ZB d   ZC d   ZD d   ZE d   ZF d   ZG d  eH f d!     YZI d"   ZJ d# e f d$     YZK eL eL d%  ZM eL eL eN d&  ZO d S('   sG   Support for installing and building the "wheel" binary package format.
i    (   t   absolute_importN(   t   urlsafe_b64encode(   t   ZipFile(   t   pkg_resources(   t   ScriptMaker(   t   get_export_entry(   t   StringIO(   t   InstallationError(   t   get_major_minor_version(   t   captured_stdoutt
   ensure_dirt	   hash_file(   t   TempDirectory(   t   MYPY_CHECK_RUNNING(   t   unpack_file(   t   parse_wheel(   t   Message(   t   Dictt   Listt   Optionalt   Sequencet   Tuplet   IOt   Textt   Anyt   Iterablet   Callablet   Set(   t   Scheme.c         C@  s%   t  j j |  |  j t  j j d  S(   Nt   /(   t   ost   patht   relpatht   replacet   sep(   t   srct   p(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   normpath2   s    i   i   c         C@  sM   t  |  |  \ } } d t | j    j d  j d  } | t |  f S(   s?   Return (encoded_digest, length) for path using hashlib.sha256()s   sha256=t   latin1t   =(   R   R   t   digestt   decodet   rstript   str(   R   t	   blocksizet   ht   lengthR(   (    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   rehash7   s
    c         C@  sI   t  j d d k  r" i  } d } n i d d 6} d } t |  | | |  S(   Ni    i   t   bt    t   newline(   t   syst   version_infot   open(   t   namet   modet   nlt   bin(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   open_for_csvB   s    	c         C@  s   t  j j |   r t |  d  d } | j   } | j d  sC t St j j	 t j
    } d | t  j j	 d  } | j   } Wd QXt |  d  ! } | j |  | j |  Wd QXt Sd S(   sQ   Replace #!python with #!/path/to/python
    Return True if file was changed.
    t   rbs   #!pythons   #!t   asciiNt   wb(   R   R   t   isfileR5   t   readlinet
   startswitht   FalseR3   t
   executablet   encodet   getfilesystemencodingt   linesept   readt   writet   Truet   None(   R   t   scriptt	   firstlinet   exenamet   rest(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt
   fix_scriptM   s    c         C@  s   |  j  d d  j   d k S(   Ns   Root-Is-PurelibR1   t   true(   t   gett   lower(   t   metadata(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   wheel_root_is_purelibb   s    c         @  s  t  j j |   s i  i  f St |   N } t   } x. | D]& } | j | j    | j d  q; W| j d  Wd  QXt j	 j
 |  } | j d i   } | j d i   } d     t   f d   | j   D  } t   f d   | j   D  } | | f S(   Ns   
i    t   console_scriptst   gui_scriptsc         S@  s3   t  |   j d d  j d  } | d | d f S(   s[   get the string representation of EntryPoint,
        remove space and split on '='
        t    R1   R'   i    i   (   R+   R!   t   split(   t   st   split_parts(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt	   _split_ep|   s    !c         3@  s   |  ] }   |  Vq d  S(   N(    (   t   .0t   v(   RZ   (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pys	   <genexpr>   s    c         3@  s   |  ] }   |  Vq d  S(   N(    (   R[   R\   (   RZ   (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pys	   <genexpr>   s    (   R   R   t   existsR5   R   RG   t   stript   seekR   t
   EntryPointt	   parse_mapRP   t   dictt   values(   t   filenamet   fpt   datat   linet   entry_pointst   consolet   gui(    (   RZ   sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   get_entrypointsg   s    
			""c         @  s2  |  s
 d St j t  } xC |  D]; } t j j |  } t j j |  } | | j |  q  Wg  t j	 j
 d d  j t j  D]$ } t j j |  j t j  ^ q     j t j j t j j t j      f d   | j   D } | s d Sg  } x | j   D] \ } } t |  }	 t |	  d k rLd j |	 d  }
 n( d j d j |	 d	   d
 |	 d	  }
 | j d j |
 |   qWd } t |  d k r| j | j d   n | j | j d   t d   t j	 j
 d d  j t j  D  } | r%d } | j |  n  d j |  S(   s   Determine if any scripts are not on PATH and format a warning.
    Returns a warning message if one or more scripts are not on PATH,
    otherwise None.
    t   PATHR1   c         @  s7   i  |  ]- \ } } t  j j |    k r | |  q S(    (   R   R   t   normcase(   R[   t
   parent_dirt   scripts(   t   not_warn_dirs(    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pys
   <dictcomp>   s   	 	i   s   script {} isi    s   scripts {} ares   , is    and s.   The {} installed in '{}' which is not on PATH.se   Consider adding {} to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.s   this directorys   these directoriesc         s@  s%   |  ] } | r | d  d k Vq d S(   i    t   ~N(    (   R[   t   i(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pys	   <genexpr>   s    si   NOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications.s   
N(   RI   t   collectionst   defaultdictt   setR   R   t   dirnamet   basenamet   addt   environRP   RW   t   pathsepRm   R*   R"   t   appendR3   RB   t   itemst   sortedt   lent   formatt   joint   any(   Ro   t   grouped_by_dirt   destfileRn   t   script_nameRr   t   warn_fort	   msg_linest   dir_scriptst   sorted_scriptst
   start_textt   last_line_fmtt   warn_for_tildet   tilde_warning_msg(    (   Rp   sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt!   message_about_scripts_not_on_PATH   sB    I(".c         C@  s   t  |  d d   S(   s6  Return the given rows of a RECORD file in sorted order.

    Each row is a 3-tuple (path, hash, size) and corresponds to a record of
    a RECORD file (see PEP 376 and PEP 427 for details).  For the rows
    passed to this function, the size can be an integer as an int or string,
    or the empty string.
    t   keyc         S@  s   t  d   |  D  S(   Nc         s@  s   |  ] } t  |  Vq d  S(   N(   R+   (   R[   t   x(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pys	   <genexpr>   s    (   t   tuple(   t   row(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   <lambda>   R1   (   R}   (   t   outrows(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   sorted_outrows   s    c         C@  s3  g  } x |  D] } t  |  d k r> t j d j |   n  t |  } | d } | j | |  } | | d <| | k r t |  \ }	 }
 |	 | d <|
 | d <n  | j t |   q WxE | D]= } t |  \ }	 }
 | j t	 | |  |	 t
 |
  f  q Wx( | D]  } | j | | d d f  qW| S(   s_   
    :param installed: A map from archive RECORD path to installation RECORD
        path.
    i   s,   RECORD line has more than three elements: {}i    i   i   R1   (   R~   t   loggert   warningR   t   listt   popR/   R{   R   R%   R+   (   t   old_csv_rowst	   installedt   changedt	   generatedt   lib_dirt   installed_rowsR   t   old_patht   new_pathR(   R.   t   f(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   get_csv_rows_for_installed   s(    


)t   MissingCallableSuffixc           B@  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyR   	  s   c         C@  s@   t  |   } | d  k	 r< | j d  k r< t t |    n  d  S(   N(   R   RI   t   suffixR   R+   (   t   specificationt   entry(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   _raise_for_invalid_entrypoint  s    t   PipScriptMakerc           B@  s   e  Z d d   Z RS(   c         C@  s#   t  |  t t |   j | |  S(   N(   R   t   superR   t   make(   t   selfR   t   options(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyR     s    
N(   R   R   RI   R   (    (    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyR     s   c   0      @  s   j  t j j  t j j } t | |   \ } }	 t |	  rL | j  n	 | j  t j |  }
 g  |
 D] } | j	 d  rk | ^ qk } i   t
     g  } | rt   @ } t j   + t j d  t j | d t d t Wd QXWd QXt j | j    n  t      f d   d d  f d  } | |  t  t j j  |  } t j j | d  } t |  \     f d	   } x | D] } d } d } x t j t j j  |   D]j } d } | d
 k rt } | } n  t j j  | |  } t | |  } | | | t d | d | qWqWt d | j  } t | _ d h | _ t | _ g  }  j  d d  } | rMd t j! k r| j" d |  n  t j! j# d d  d k r| j" d t$ j% d | f  n  | j" d t&   | f  g   D] } t' j( d |  r| ^ q} x | D] }  | =q9Wn   j  d d  } | rd t j! k r| j" d |  n  | j" d t&   | f  g   D] } t' j( d |  r| ^ q} x | D] }  | =qWn  | j) d    j*   D  g   j*   D] } d | ^ q}  g  }! y@ | j+ |  }! | j) |!  | j) | j+ |  i t d 6  Wn8 t, k
 r}" |" j- d }# t. d j/ |# |    n X| rt0 |!  }$ |$ d k	 rt j1 |$  qn  t j j | d  }% t j j | d  }& t2 |& d   }' |' j3 d   Wd QXt4 j5 |& |%  | j" |%  t j j | d!  }( t j j | d"  }) t6 |( d#   }* t6 |) d$  m }+ t7 j8 |*  }, t9 |, d%  d&   d' | d(  }- t7 j: |+  }. x! t; |-  D] }/ |. j< |/  qWWd QXWd QXt4 j5 |) |(  d S()   s  Install a wheel.

    :param name: Name of the project to install
    :param wheeldir: Base directory of the unpacked wheel
    :param wheel_zip: open ZipFile for wheel being installed
    :param scheme: Distutils scheme dictating the install directories
    :param req_description: String used in place of the requirement, for
        logging
    :param pycompile: Whether to byte-compile installed Python files
    :param warn_script_location: Whether to check that scripts are installed
        into a directory on PATH
    :raises UnsupportedWheel:
        * when the directory holds an unpacked wheel with incompatible
          Wheel-Version
        * when the .dist-info dir does not match the wheel
    s   .datat   ignoret   forcet   quietNc         @  sB   t  |    } t  |   } |  | <| r>   j |  n  d S(   s6   Map archive RECORD paths to installation RECORD paths.N(   R%   Rx   (   t   srcfileR   t   modifiedt   oldpatht   newpath(   R   R   R   t   wheeldir(    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   record_installedU  s
    
c         @  s  t  |  xt j |   D]\ } } } | t |   j t j j  } t j j | |  }	 | r | d k r g  | D] }
 |
 j d  sv |
 ^ qv | (n  xL| D]D} | r | |  r q n  t j j | |  } t j j | | |  } t  |	  t j j	 |  rt j
 |  n  t j | |  t j |  } t t d  rft j | | j | j f  n  t j | t j  rt j |  } | j t j Bt j Bt j B} t j | |  n  t } | r| |  } n    | | |  q Wq Wd  S(   NR1   s   .datat   utime(   R
   R   t   walkR~   t   lstripR   R"   R   t   endswithR]   t   unlinkt   shutilt   copyfilet   statt   hasattrR   t   st_atimet   st_mtimet   accesst   X_OKt   st_modet   S_IXUSRt   S_IXGRPt   S_IXOTHt   chmodRA   (   t   sourcet   destt   is_baset   fixert   filtert   dirt   subdirst   filest   basedirt   destdirRX   R   R   R   t   stt   permissionsR   (   R   (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   clobber^  s4    
,

s   entry_points.txtc         @  s   |  j    j d  r" |  d  } nJ |  j    j d  rD |  d  } n( |  j    j d  rf |  d  } n |  } |   k p |  k S(   Ns   .exeis
   -script.pyis   .pya(   RQ   R   (   R6   t	   matchname(   Ri   Rj   (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   is_entrypoint_wrapper  s    Ro   R   R   R1   t   pipt   ENSUREPIP_OPTIONSs   pip = t
   altinstalls
   pip%s = %si    s   pip(\d(\.\d)?)?$t   easy_installs   easy_install = s   easy_install-%s = %ss   easy_install(-\d\.\d)?$c         s@  s   |  ] } d  | Vq d S(   s   %s = %sN(    (   R[   t   kv(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pys	   <genexpr>  s    s   %s = %sRj   s   Invalid script entry point: {} for req: {} - A callable suffix is required. Cf https://packaging.python.org/specifications/entry-points/#use-for-scripts for more information.t	   INSTALLERs   INSTALLER.pipR=   s   pip
t   RECORDs
   RECORD.pipt   rs   w+R   R   R   R   (=   R*   R   R   R"   R   RS   t   purelibt   platlibt   listdirR   Ru   R	   t   warningst   catch_warningst   filterwarningst
   compileallt   compile_dirRH   R   t   debugt   getvalueRA   RI   R   Rk   RN   t   getattrR   Ro   R   t   variantst   set_modeR   Ry   R{   RP   R3   R4   R   t   ret   matcht   extendR|   t   make_multipleR   t   argsR   R   R   R   R5   RG   R   t   moveR:   t   csvt   readerR   t   writerR   t   writerow(0   R6   R   t	   wheel_zipt   schemet   req_descriptiont	   pycompilet   warn_script_locationR   t   info_dirRR   R   RX   t	   data_dirsR   t   stdoutR   t   dest_info_dirt   ep_fileR   t   datadirR   R   t   subdirR   t   makert   scripts_to_generatet
   pip_scriptt   kt   pip_ept   easy_install_scriptt   easy_install_epR   t   gui_scripts_to_generatet   generated_console_scriptst   eR   t   msgt	   installert   temp_installert   installer_filet   recordt   temp_recordt	   record_int
   record_outR   R   R   R   (    (   R   Ri   Rj   R   R   R   R   sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   install_unpacked_wheel  s    	(	%;%	$		#++#c   	      C@  s   t  d | d d  f } t | d t K } t | | j  t d |  d | j d | d | d	 | d
 | d |  Wd  QXWd  QXd  S(   NR   t   kinds   unpacked-wheelt
   allowZip64R6   R   R   R   R   R   R   (   R   R   RH   R   R   R  (	   R6   t
   wheel_pathR   R   R   R   t   _temp_dir_for_testingt   unpacked_dirt   z(    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   install_wheelQ  s    
 	(P   t   __doc__t
   __future__R    Rs   R   R   t   loggingt   os.pathR   R   R   R   R3   R   t   base64R   t   zipfileR   t   pip._vendorR   t   pip._vendor.distlib.scriptsR   t   pip._vendor.distlib.utilR   t   pip._vendor.sixR   t   pip._internal.exceptionsR   t   pip._internal.locationsR   t   pip._internal.utils.miscR	   R
   R   t   pip._internal.utils.temp_dirR   t   pip._internal.utils.typingR   t   pip._internal.utils.unpackingR   t   pip._internal.utils.wheelR   t   email.messageR   t   typingR   R   R   R   R   R   R   R   R   R   R   t   pip._internal.models.schemeR   R+   t   InstalledCSVRowt	   getLoggerR   R   R%   R/   R:   RN   RS   Rk   R   R   R   t	   ExceptionR   R   R   RH   R  RI   R  (    (    (    sC   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/install/wheel.pyt   <module>   s`   L					#	G		$	 5