
 XUN                 @   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 m Z d d l m Z d d l m Z m Z d d l m Z 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 Z d d l  m! Z! d Z" d/ Z# d d0 d d  Z$ y e% d d   Z& Wn e' k
 r|d d   Z& Yn Xd d   Z( d d   Z) e j* d e j+  Z, d d   Z- d d   Z. d d d d  d! d"  Z/ d# d$   Z0 e0 d% d&    Z1 d' d(   Z2 d) d*   Z3 Gd+ d,   d, e4  Z5 Gd- d.   d. e4  Z6 d S)1zH
Support for installing and building the "wheel" binary package format.
    )with_statementN)urlsafe_b64encode)Parser)ConfigParserStringIO)InvalidWheelFilenameUnsupportedWheel)distutils_scheme)logger)
pep425tags)call_subprocessnormalize_pathmake_path_relative)ScriptMakerz.whl   sha256   c          
   C   s   t  j |  } d } t |  d  O } | j |  } x6 | rn | t |  7} | j |  | j |  } q9 WWd QXd t | j    j d  j	 d  } | | f S)z6Return (hash, length) for path using hashlib.new(algo)r   rbNzsha256=latin1=)
hashlibnewopenreadlenupdater   digestdecoderstrip)pathalgo	blocksizehlengthfblockr    r&   4/home/ubuntu/projects/ifolica/build/pip/pip/wheel.pyrehash!   s    	(r(   c             C   s    t  |  t  r |  j d  S|  S)Nascii)
isinstanceunicodeencode)sr&   r&   r'   binary0   s    r.   c             C   s    t  |  t  r |  j d  Sd  S)Nr)   )r*   strr,   )r-   r&   r&   r'   r.   5   s    c             C   sI   t  j d d k  r" i  } d } n i d d 6} d } t |  | | |  S)Nr      b newline)sysversion_infor   )namemodenlbinr&   r&   r'   open_for_csv9   s    	r:   c             C   s   t  j j |   r t |  d  } zj | j   } | j t d   sI d St j j	 t j
    } t d  | t t  j  } | j   } Wd | j   Xt |  d  } z | j |  | j |  Wd | j   Xd Sd S)zLReplace #!python with #!/path/to/python
    Return True if file was changed.r   z#!pythonFz#!NwbT)osr   isfiler   readline
startswithr.   r4   
executabler,   getfilesystemencodinglinesepr   closewrite)r   script	firstlineexenamerestr&   r&   r'   
fix_scriptB   s     rI   zZ^(?P<namever>(?P<name>.+?)(-(?P<ver>\d.+?))?)
                                \.dist-info$c             C   s   |  j  d d  } x t j |  D] } t j |  } | r" | j d  | k r" t t j j | | d   : } x0 | D]( } | j	   j
   } | d k rz d Sqz WWd QXq" q" Wd S)	zP
    Return True if the extracted wheel in wheeldir should go into purelib.
    -_r6   WHEELzroot-is-purelib: trueTNF)replacer<   listdirdist_info_rematchgroupr   r   joinlowerr   )r6   wheeldirname_foldeditemrP   wheelliner&   r&   r'   root_is_purelib\   s    !rY   c          
   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
 |  i  } i  } | j d  r t | j d   } n  | j d  r t | j d   } n  | | f S)N
r   console_scriptsgui_scripts)r<   r   existsr   r   rD   stripseekr   RawConfigParserreadfphas_sectiondictitems)filenamefpdatarX   cpconsoleguir&   r&   r'   get_entrypointsl   s"    
	rk   FTc       #         s  t  |  d | d | d | } t |    r: | d  n
 | d  g   g    j t j j  t j j } i   t     g  }	 | r t j | d d d d n  d	 d
    d       f d d  	 d d   	 
 f d d  }
 |
 |  d   st	 d 
   t j j
  d d  } t |  \     f d d   } x  D] } d } d } x t j t j j
  |   D]e } d } | d k rt } | } n  t j j
  | |  } | | } |
 | | d d | d | qWqaWt d | d   t d2   _ d  _  f d d   } |  _ d  _  j d d  } | rJd t j k rd | } |	 j  j |   n  t j j d d  d  k rd! t j d d"  | f } |	 j  j |   n  d! t j d d#  | f } |	 j  j |   d$ d%    D } x | D] }  | =q6Wn   j d& d  } | rd t j k rd' | } |	 j  j |   n  d( t j d d#  | f } |	 j  j |   d) d%    D } x | D] }  | =qWn  t   d k r3|	 j  j d* d%    j   D   n  t   d k r{|	 j  j d+ d%    j   D i d d, 6  n  t j j
  d d-  } t j j
  d d.  } t | d/  } t | d0   } t j |  } t j  |  } xj | D]b }  j | d | d  | d <| d   k rKt! | d  \ | d" <| d1 <n  | j" |  qWx6 |	 D]. }  t! |   \ }! }" | j" |  |! |" f  qcWx(  D]  }  | j"  |  d d f  qWWd QXWd QXt# j$ | |  d S)3zInstall a wheeluserhomerootpurelibplatlibforceTquietc             S   s   t  |  |  j t j j d  S)N/)r   rM   r<   r   sep)srcpr&   r&   r'   normpath   s    z"move_wheel_files.<locals>.normpathFc                sB    |    }  |   } |  | <| r>   j  |  n  d S)z6Map archive RECORD paths to installation RECORD paths.N)add)srcfiledestfilemodifiedoldpathnewpath)changed	installedlib_dirrw   rT   r&   r'   record_installed   s
    
z*move_wheel_files.<locals>.record_installedNc                s  t  j j |  s" t  j |  n  xt  j |   D]\ } } } | t |   d   j t  j j  } | r | j t  j j d  d j	 d  r q2 n  x | D] }	 t  j j
 | | |	  }
 | r | d k r |
 j	 d  r   j |	  q nb | rR|	 j	 d  rR|	 j   j  j j d d  j    rR sBt d    j |
  n  t  j j |
  s t  j |
  q q Wx | D] } | r| |  rqn  t  j j
 | |  } t  j j
 | | |  } t j | |  d	 } | r| |  } n   | | |  qWq2 Wd  S)
Nr   r   z.datar2   z
.dist-inforJ   rK   zMultiple .dist-info directoriesF)r<   r   r]   makedirswalkr   lstriprt   splitendswithrR   appendrS   r?   project_namerM   AssertionErrorshutilmove)sourcedestis_basefixerfilterdirsubdirsfilesbasedirr-   
destsubdirr$   ry   rz   r~   )	data_dirsinfo_dirr   reqr&   r'   clobber   s8    %+!*z!move_wheel_files.<locals>.clobberz!%s .dist-info directory not foundr   zentry_points.txtc                s   |  j    j d  r( |  d  d  } nV |  j    j d  rP |  d  d  } n. |  j    j d  rx |  d  d  } n |  } |   k p |  k S)	Nz.exe   z
-script.py
   z.pyair   )rS   r   )r6   	matchname)ri   rj   r&   r'   is_entrypoint_wrapper   s    z/move_wheel_files.<locals>.is_entrypoint_wrapperscriptsr   r   r2   c                s6     j  i |  j d 6|  j j d  d d 6|  j d 6S)Nmodule.r   import_namefunc)script_templateprefixsuffixr   )entry)makerr&   r'   _get_script_text   s    	
z*move_wheel_files.<locals>._get_script_textz# -*- coding: utf-8 -*-
import re
import sys

from %(module)s import %(import_name)s

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(%(func)s())
pipENSUREPIP_OPTIONSzpip = 
altinstallz
pip%s = %sr   r0   c             S   s(   g  |  ] } t  j d  |  r |  q S)zpip(\d(\.\d)?)?$)rerP   ).0kr&   r&   r'   
<listcomp>A  s   	 z$move_wheel_files.<locals>.<listcomp>easy_installzeasy_install = zeasy_install-%s = %sc             S   s(   g  |  ] } t  j d  |  r |  q S)zeasy_install(-\d\.\d)?$)r   rP   )r   r   r&   r&   r'   r   M  s   	 c             S   s   g  |  ] } d  |  q S)z%s = %sr&   )r   kvr&   r&   r'   r   T  s   	 c             S   s   g  |  ] } d  |  q S)z%s = %sr&   )r   r   r&   r&   r'   r   V  s   	 rj   RECORDz
RECORD.piprzw+   )r2   )%r	   rY   r   r<   r   rt   set
compileallcompile_dirr   rR   rk   rN   rI   r   variantsset_moder   r   popenvironextendmakegetr4   versionr   make_multiplerd   r:   csvreaderwriterr(   writerowr   r   )#r6   r   rT   rl   rm   rn   	pycompileschemer   	generatedr   ep_filer   datadirr   r   subdirr   r   
pip_scriptspecpip_epr   easy_install_scripteasy_install_eprecordtemp_record	record_in
record_outr   r   rowr$   r"   lr&   )r~   ri   r   rj   r   r   r   r   rw   r   r   rT   r'   move_wheel_files   s    
	!!!%	
$		
	#

,6!*r   c                s%   t  j      f d d    } | S)Nc              ?   sH   t    } x8   |  |   D]' } | | k r | j |  | Vq q Wd  S)N)r   rx   )argskwseenrV   )fnr&   r'   uniquek  s
    	z_unique.<locals>.unique)	functoolswraps)r   r   r&   )r   r'   _uniquej  s    !r   c             c   s   d d l  m } t j | |  j d    } x | D] } t j j |  j | d  } | V| j	 d  r5 t j j
 |  \ } } | d d  } t j j | | d  } | Vq5 q5 Wd S)	a  
    Yield all the uninstallation paths for dist based on RECORD-without-.pyc

    Yield paths to all the files in RECORD. For each .py file in RECORD, add
    the .pyc in the same directory.

    UninstallPathSet.add() takes care of the __pycache__ .pyc.
    r   )FakeFiler   z.pyNr0   z.pyc)pip.reqr   r   r   get_metadata_linesr<   r   rR   locationr   r   )distr   r   r   r   dnr   baser&   r&   r'   uninstallation_pathsu  s    
r   c             C   s   yz d d   t  j d |   D d } | j d  } t   j |  } | d j   } t t t | j	 d    } | SWn d SYn Xd S)	z
    Return the Wheel-Version of an extracted wheel, if possible.

    Otherwise, return False if we couldn't parse / extract it.
    c             S   s   g  |  ] } |  q Sr&   r&   )r   dr&   r&   r'   r     s   	 z!wheel_version.<locals>.<listcomp>Nr   rL   zWheel-Versionr   F)
pkg_resourcesfind_on_pathget_metadatar   parsestrr^   tuplemapintr   )
source_dirr   
wheel_datar   r&   r&   r'   wheel_version  s    #r   c             C   s   |  s t  d |   n  |  d t d k rX t  d | d j t t |    f   n2 |  t k r t j d d j t t |     n  d S)a  
    Raises errors or warns if called with an incompatible Wheel-Version.

    Pip should refuse to install a Wheel-Version that's a major series
    ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
    installing a version only minor version ahead (e.g 1.2 > 1.1).

    version: a 2-tuple representing a Wheel-Version (Major, Minor)
    name: name of wheel or package to raise exception about

    :raises UnsupportedWheel: when an incompatible Wheel-Version is given
    z(%s is in an unsupported or invalid wheelr   zB%s's Wheel-Version (%s) is not compatible with this version of pipr   z*Installing from a newer Wheel-Version (%s)N)r   VERSION_COMPATIBLErR   r   r/   r
   warn)r   r6   r&   r&   r'   check_compatibility  s    %	r   c               @   sU   e  Z d  Z d Z e j d e j  Z d d   Z d d d  Z	 d d d	  Z
 d S)
WheelzA wheel filez^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))
                ((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
                \.whl|\.dist-info)$c                s     j  j |  } | s+ t d |   n  |   _ | j d  j d d    _ | j d  j d d    _ | j d  j d    _	 | j d  j d    _
 | j d	  j d    _ t   f d
 d     j	 D    _ d S)zX
        :raises InvalidWheelFilename: when the filename is invalid for a wheel
        z!%s is not a valid wheel filename.r6   rK   rJ   verpyverr   abiplatc             3   s>   |  ]4 }   j  D]$ }   j D] } | | | f Vq q q d  S)N)abisplats)r   xyz)selfr&   r'   	<genexpr>  s    z!Wheel.__init__.<locals>.<genexpr>N)wheel_file_rerP   r   re   rQ   rM   r6   r   r   
pyversionsr   r   r   	file_tags)r  re   
wheel_infor&   )r  r'   __init__  s    	zWheel.__init__Nc                sH     d k r t  j   n    f d d   |  j D } | rD t |  Sd S)a"  
        Return the lowest index that one of the wheel's file_tag combinations
        achieves in the supported_tags list e.g. if there are 8 supported tags,
        and one of the file tags is first in the list, then return 0.  Returns
        None is the wheel is not supported.
        Nc                s+   g  |  ]! } |   k r   j  |   q Sr&   )index)r   c)tagsr&   r'   r     s   	 z+Wheel.support_index_min.<locals>.<listcomp>)r   supported_tagsr  min)r  r
  indexesr&   )r
  r'   support_index_min  s    zWheel.support_index_minc             C   s4   | d k r t  j } n  t t |  j |  j   S)z'Is this wheel supported on this system?N)r   r  boolr   intersectionr  )r  r
  r&   r&   r'   	supported  s    zWheel.supported)__name__
__module____qualname____doc__r   compileVERBOSEr  r  r  r  r&   r&   r&   r'   r     s   r   c               @   s@   e  Z d  Z d Z g  g  d d  Z d d   Z d d   Z d S)	WheelBuilderz#Build wheels from a RequirementSet.c             C   s7   | |  _  | |  _ t |  |  _ | |  _ | |  _ d  S)N)requirement_setfinderr   	wheel_dirbuild_optionsglobal_options)r  r  r  r  r  r  r&   r&   r'   r    s
    			zWheelBuilder.__init__c             C   s   t  j d d | j g t |  j  } t j d | j  t j d |  j  | d d |  j g |  j	 } y! t
 | d | j d d	 d
 SWn  t j d | j  d	 SYn Xd S)zBuild one wheel.z-czjimport setuptools;__file__=%r;exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))z#Running setup.py bdist_wheel for %szDestination directory: %sbdist_wheelz-dcwdshow_stdoutFTzFailed building wheel for %sN)r4   r@   setup_pylistr  r
   notifyr6   r  r  r   r   error)r  r   	base_args
wheel_argsr&   r&   r'   
_build_one  s    	
zWheelBuilder._build_onec             C   s5  |  j  j |  j  |  j  j j   } d d   | D } | sB d St j d d j d d   | D   t j d 7_ g  g  } } x: | D]2 } |  j	 |  r | j
 |  q | j
 |  q Wt j d 8_ | rt j d d	 j d
 d   | D   n  | r1t j d d	 j d d   | D   n  d S)zBuild wheels.c             S   s   g  |  ] } | j  s |  q Sr&   )is_wheel)r   r   r&   r&   r'   r     s   	 z&WheelBuilder.build.<locals>.<listcomp>Nz*Building wheels for collected packages: %s,c             S   s   g  |  ] } | j   q Sr&   )r6   )r   r   r&   r&   r'   r     s   	 r   zSuccessfully built %s c             S   s   g  |  ] } | j   q Sr&   )r6   )r   r   r&   r&   r'   r   %  s   	 zFailed to build %sc             S   s   g  |  ] } | j   q Sr&   )r6   )r   r   r&   r&   r'   r   '  s   	 )r  prepare_filesr  requirementsvaluesr
   r#  rR   indentr'  r   )r  reqsetbuildsetbuild_successbuild_failurer   r&   r&   r'   build  s&    *zWheelBuilder.buildN)r  r  r  r  r  r'  r3  r&   r&   r&   r'   r    s   r  )r   r   i   )7r  
__future__r   r   r   r   r   r<   r   r   r4   base64r   email.parserr   Zpip.backwardcompatr   r   pip.exceptionsr   r   pip.locationsr	   pip.logr
   r   r   pip.utilr   r   r   r   distlib.scriptsr   	wheel_extr   r(   r+   r.   	NameErrorr:   rI   r  r  rO   rY   rk   r   r   r   r   r   objectr   r  r&   r&   r&   r'   <module>   sR   		2