ó
0±E^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-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/pip/pip/_internal/operations/install/wheel.pys	   <genexpr>…   s    c         3@  s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   R[   R\   (   RZ   (    sC   /tmp/pip-build-iCT__d/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-iCT__d/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-iCT__d/pip/pip/_internal/operations/install/wheel.pys
   <dictcomp>£   s   	 	i   s   script {} isi    s   scripts {} ares   , iÿÿÿÿs    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-iCT__d/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-iCT__d/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-iCT__d/pip/pip/_internal/operations/install/wheel.pys	   <genexpr>â   s    (   t   tuple(   t   row(    (    sC   /tmp/pip-build-iCT__d/pip/pip/_internal/operations/install/wheel.pyt   <lambda>â   s    (   R}   (   t   outrows(    (    sC   /tmp/pip-build-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/pip/pip/_internal/operations/install/wheel.pyR¬     s    
N(   R¤   R¥   RI   R¬   (    (    (    sC   /tmp/pip-build-iCT__d/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-iCT__d/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-iCT__d/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   .exeiüÿÿÿs
   -script.pyiöÿÿÿs   .pya(   RQ   R»   (   R6   t	   matchname(   Ri   Rj   (    sC   /tmp/pip-build-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/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-iCT__d/pip/pip/_internal/operations/install/wheel.pyt   <module>   s`   L					#	G		$	ÿ 5