3
LY
}                 @   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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ZddlmZ ddlmZmZ dd	lmZmZm Z  dd
l!m"Z"m#Z# ddlm$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 dZ9d9Z:ej;e<Z=G dd de>Z?dd Z@dd ZAd;ddZBd d! ZCd"d# ZDejEd$ejFZGd%d& ZHd'd( ZId<d+d,ZJd-d. ZKeKd/d0 ZLd1d2 ZMd3d4 ZNG d5d6 d6e>ZOG d7d8 d8e>ZPdS )=zH
Support for installing and building the "wheel" binary package format.
    )absolute_importN)urlsafe_b64encode)Parser)StringIO)
expanduser)path_to_url
unpack_url)InstallationErrorInvalidWheelFilenameUnsupportedWheel)distutils_schemePIP_DELETE_MARKER_FILENAME)
pep425tags)call_subprocess
ensure_dircaptured_stdoutrmtreeread_chunks)open_spinner)
indent_log)SETUPTOOLS_SHIM)ScriptMaker)pkg_resources)canonicalize_name)configparserz.whl   c               @   s    e Zd ZdZdd Zdd ZdS )
WheelCachez&A cache of wheels for future installs.c             C   s   |rt |nd| _|| _dS )zCreate a wheel cache.

        :param cache_dir: The root of the cache.
        :param format_control: A pip.index.FormatControl object to limit
            binaries being read from the cache.
        N)r   
_cache_dir_format_control)self	cache_dirformat_control r"   \/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/pip/pip/wheel.py__init__8   s    zWheelCache.__init__c             C   s   t | j|| j|S )N)cached_wheelr   r   )r   linkpackage_namer"   r"   r#   r%   B   s    zWheelCache.cached_wheelN)__name__
__module____qualname____doc__r$   r%   r"   r"   r"   r#   r   5   s   
r   c             C   s   |j g}|jdk	r4|jdk	r4|jdj|j|jg dj|}tj|j j }|dd |dd |dd |dd g}t	j
j| df| S )a  
    Return a directory to store cached wheels in for link.

    Because there are M wheels for any one sdist, we provide a directory
    to cache them in, and then consult that directory when looking up
    cache hits.

    We only insert things into the cache if they have plausible version
    numbers, so that we don't contaminate the cache with things that were not
    unique. E.g. ./package might have dozens of installs done for it and build
    a version of 0.0...and if we built and cached a wheel, we'd end up using
    the same wheel even if the source has been edited.

    :param cache_dir: The cache_dir being used by pip.
    :param link: The link of the sdist for which this will cache wheels.
    N=#         wheels)url_without_fragment	hash_namehashappendjoinhashlibsha224encode	hexdigestospath)r    r&   	key_partskey_urlhashedpartsr"   r"   r#   _cache_for_linkG   s    
,rA   c             C   s,  | s|S |s|S |j r|S |js$|S |s,|S t|}tjj||}d|krN|S t| |}ytj|}W n: t	k
r } z|j
t
jt
jfkr|S  W Y d d }~X nX g }	xL|D ]D}
yt|
}W n tk
r   wY nX |j sq|	j|j |
f qW |	 s|S |	j  tjj||	d d }tjjt|S )Nbinaryr   r   )is_wheelis_artifactr   pipindexfmt_ctl_formatsrA   r;   listdirOSErrorerrnoENOENTENOTDIRWheelr
   	supportedr5   support_index_minsortr<   r6   Linkr   )r    r&   r!   r'   canonical_nameformatsrootwheel_namese
candidates
wheel_namewheelr<   r"   r"   r#   r%   p   sF    

r%   sha256   c             C   st   t j|}d}t| d2}x*t||dD ]}|t|7 }|j| q(W W dQ R X dt|j jdj	d }||fS )z6Return (hash, length) for path using hashlib.new(algo)r   rb)sizeNzsha256=latin1r,   )
r7   newopenr   lenupdater   digestdecoderstrip)r<   algo	blocksizehlengthfblockrc   r"   r"   r#   rehash   s    

rl   c             C   s6   t jd dk ri }d}nddi}d}t| || f|S )Nr      bnewline )sysversion_infor`   )namemodenlbinr"   r"   r#   open_for_csv   s    rw   c             C   s   t jj| rt| dH}|j }|jds.dS tjjtj	 }d| t j
jd }|j }W dQ R X t| d}|j| |j| W dQ R X dS dS )	zLReplace #!python with #!/path/to/python
    Return True if file was changed.r\   s   #!pythonFs   #!asciiNwbT)r;   r<   isfiler`   readline
startswithrq   
executabler9   getfilesystemencodinglinesepreadwrite)r<   script	firstlineexenamerestr"   r"   r#   
fix_script   s    

r   zZ^(?P<namever>(?P<name>.+?)(-(?P<ver>\d.+?))?)
                                \.dist-info$c             C   s   | j dd}xttj|D ]f}tj|}|r|jd|krttjj||d,}x$|D ]}|j	 j
 }|dkrTdS qTW W dQ R X qW dS )	zP
    Return True if the extracted wheel in wheeldir should go into purelib.
    -_rs   WHEELzroot-is-purelib: trueTNF)replacer;   rH   dist_info_rematchgroupr`   r<   r6   lowerre   )rs   wheeldirname_foldeditemr   rY   liner"   r"   r#   root_is_purelib   s    

r   c          
   C   s   t jj| si i fS t| <}t }x$|D ]}|j|j  |jd q*W |jd W d Q R X tj	 }dd |_
|j| i }i }|jdrt|jd}|jdrt|jd}||fS )N
r   c             S   s   | S )Nr"   )optionr"   r"   r#   <lambda>   s    z!get_entrypoints.<locals>.<lambda>console_scriptsgui_scripts)r;   r<   existsr`   r   r   stripseekr   RawConfigParseroptionxformreadfphas_sectiondictitems)filenamefpdatar   cpconsoleguir"   r"   r#   get_entrypoints   s$    





r   FTc
       )   (      s  |st | |||||	d}t| r,|d n|d g g jtjjtjj }
i t  g }|rt 4}tj	   tj
d tj|
ddd W dQ R X W dQ R X tj|j  dd	 d3 fdd		d4	
fdd	}||
d std
 tjjd d}t|\fdd}xvD ]n}d}d}x^tjtjj|D ]F}d}|dkrpt}|}tjj||}
|| }||
|d
||d qVW q4W td|d d_td5_d_
fdd}|_d_jdd}|rdtjkrd| }|jj| tjjdddkrTdt j!dd |f }|jj| dt j!dd  |f }|jj| d!d" D }x|D ]}|= qW jd#d}|rdtjkrd$| }|jj| d%t j!dd  |f }|jj| d&d" D }x|D ]}|= qW t"dkrJ|jj#d'd" j$ D  t"dkr||jj#d(d" j$ D d)di tjjd d*}tjjd d+}t%|d,}|j&d- W dQ R X t'j(|| |j)| tjjd d.}tjjd d/} t*|d0}!t*| d1}"t+j,|!}#t+j-|"}$xV|#D ]N}%j|%d |%d |%d< |%d  krnt.|%d \|%d< |%d2< |$j/|% q,W x0|D ](}&t.|&\}'}(|$j/|&|'|(f qW x"D ]}&|$j/|& ddf qW W dQ R X W dQ R X t'j(| | dS )6zInstall a wheel)userhomerT   isolatedprefixpurelibplatlibignoreT)forcequietNc             S   s   t jj| |jt jjdS )N/)r;   r<   relpathr   sep)srcpr"   r"   r#   normpath  s    z"move_wheel_files.<locals>.normpathFc                s.   | }|}||< |r* j | dS )z6Map archive RECORD paths to installation RECORD paths.N)add)srcfiledestfilemodifiedoldpathnewpath)changed	installedlib_dirr   r   r"   r#   record_installed  s
    

z*move_wheel_files.<locals>.record_installedc                s  t | xtj| D ]\}}}|t| d  jtjj}tjj||}	|rj|jtjjdd j	drjqx|D ]}
tjj|||
}|r|dkr|j	dr j
|
 qpqp|rp|
j	drpt|
jtjrp std| d dj j
| qpW x|D ]}|r||rqtjj||}tjj|||}t |	 tj|| tj|}ttdrptj||j|jf tj|tjrtj|}|jtjB tjB tjB }tj|| d	}|r||}||| qW qW d S )
Nr   r   z.datarp   z
.dist-infoz!Multiple .dist-info directories: z, utimeF)r   r;   walkra   lstripr<   r   r6   splitendswithr5   r   r|   rs   AssertionErrorshutilcopyfilestathasattrr   st_atimest_mtimeaccessX_OKst_modeS_IXUSRS_IXGRPS_IXOTHchmod)sourcedestis_basefixerfilterdirsubdirsfilesbasedirdestdirs
destsubdirrj   r   r   stpermissionsr   )	data_dirsinfo_dirr   reqr"   r#   clobber  sJ    






z!move_wheel_files.<locals>.clobberz!%s .dist-info directory not foundr   zentry_points.txtc                sh   | j  jdr| d d }n<| j  jdr8| d d }n | j  jdrT| d d }n| }| kpf|kS )	Nz.exer/   z
-script.py
   z.pyair   )r   r   )rs   	matchname)r   r   r"   r#   is_entrypoint_wrappera  s    z/move_wheel_files.<locals>.is_entrypoint_wrapperscripts)r   r   rp   c                s<   | j d krtd| f  j| j| j jdd | j d S )NzInvalid script entry point: %s for req: %s - A callable suffix is required. Cf https://packaging.python.org/en/latest/distributing.html#console-scripts for more information..r   )moduleimport_namefunc)suffixr	   script_templater   r   )entry)makerr   r"   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())
rE   ENSUREPIP_OPTIONSzpip = 
altinstallz
pip%s = %sr   rm   c             S   s   g | ]}t jd |r|qS )zpip(\d(\.\d)?)?$)rer   ).0kr"   r"   r#   
<listcomp>  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   r   )r   r   r"   r"   r#   r     s    c             S   s   g | ]}d | qS )z%s = %sr"   )r   kvr"   r"   r#   r     s    c             S   s   g | ]}d | qS )z%s = %sr"   )r   r   r"   r"   r#   r     s    r   	INSTALLERzINSTALLER.pipry   s   pip
RECORDz
RECORD.piprzw+r.   )F)NN)rp   )0r   r   re   r;   r<   r   setr   warningscatch_warningsfilterwarnings
compileallcompile_dirloggerdebuggetvaluer   r6   r   rH   r   r   r   variantsset_moder   r   popenvironextendmakegetrq   versionra   make_multipler   r`   r   r   mover5   rw   csvreaderwriterrl   writerow))rs   r   r   r   r   rT   	pycompileschemer   r   r   	generatedstdoutr   ep_filer   datadirr   r   subdirr   r   
pip_scriptspecpip_epr   easy_install_scripteasy_install_ep	installertemp_installerinstaller_filerecordtemp_record	record_in
record_outr  r  rowrj   rh   lr"   )r   r   r   r   r   r   r   r   r   r   r   r   r#   move_wheel_files   s    




$;



#







.r,  c                s   t j  fdd}|S )Nc              ?   s6   t  }x* | |D ]}||kr|j| |V  qW d S )N)r   r   )argskwseenr   )fnr"   r#   unique  s
    
z_unique.<locals>.unique)	functoolswraps)r0  r1  r"   )r0  r#   _unique  s    r4  c             c   s   ddl m} tj|| jd}xd|D ]\}tjj| j|d }|V  |j	dr&tjj
|\}}|dd }tjj||d }|V  q&W d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.pyNrm   z.pyc)	pip.utilsr5  r  r  get_metadata_linesr;   r<   r6   locationr   r   )distr5  r   r*  r<   dnr0  baser"   r"   r#   uninstallation_paths  s    


r=  c             C   sd   yTdd t jd| D d }|jd}t j|}|d j }ttt|j	d}|S    dS d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S r"   r"   )r   dr"   r"   r#   r   ;  s    z!wheel_version.<locals>.<listcomp>Nr   r   zWheel-Versionr   F)
r   find_on_pathget_metadatar   parsestrr   tuplemapintr   )
source_dirr:  
wheel_datar  r"   r"   r#   wheel_version4  s    
rG  c             C   sb   | st d| | d td kr>t d|djtt| f n | tkr^tjddjtt|  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_COMPATIBLEr6   rC  strr  warning)r  rs   r"   r"   r#   check_compatibilityG  s    
rK  c               @   s:   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 )rM   z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| | _|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.rs   r   r   verpyverr   abiplatc             3   s0   | ](} j D ]} jD ]}|||fV  qqqd S )N)abisplats)r   xyz)r   r"   r#   	<genexpr>  s    z!Wheel.__init__.<locals>.<genexpr>N)wheel_file_rer   r
   r   r   r   rs   r  r   
pyversionsrP  rQ  r   	file_tags)r   r   
wheel_infor"   )r   r#   r$   p  s    
zWheel.__init__Nc                s2    dkrt j  fdd| jD }|r.t|S d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S r"   )rF   )r   c)tagsr"   r#   r     s    z+Wheel.support_index_min.<locals>.<listcomp>)r   supported_tagsrX  min)r   r[  indexesr"   )r[  r#   rO     s    zWheel.support_index_minc             C   s"   |dkrt j}tt|j| jS )z'Is this wheel supported on this system?N)r   r\  boolr   intersectionrX  )r   r[  r"   r"   r#   rN     s    zWheel.supported)N)N)r(   r)   r*   r+   r   compileVERBOSErV  r$   rO   rN   r"   r"   r"   r#   rM   d  s   
rM   c               @   sH   e Zd ZdZdddZdddZdd Zdd	d
Zdd ZdddZ	dS )WheelBuilderz#Build wheels from a RequirementSet.Nc             C   s6   || _ || _|jj| _|j| _|p$g | _|p.g | _d S )N)	requirement_setfinder_wheel_cacher   _cache_rootwheel_download_dir
_wheel_dirbuild_optionsglobal_options)r   rd  re  rj  rk  r"   r"   r#   r$     s    

zWheelBuilder.__init__c             C   s   t jd}zn| j|||drlyBtj|d }tjj||}tjtjj||| t	j
d| |S    Y nX | j| dS t| X dS )ziBuild one wheel.

        :return: The filename of the built wheel, or None if the build failed.
        z
pip-wheel-)
python_tagr   zStored in directory: %sN)tempfilemkdtemp_WheelBuilder__build_oner;   rH   r<   r6   r   r  r  info
_clean_oner   )r   r   
output_dirrl  tempdrX   
wheel_pathr"   r"   r#   
_build_one  s    

zWheelBuilder._build_onec             C   s   t jddt|j gt| j S )Nz-uz-c)rq   r}   r   setup_pylistrk  )r   r   r"   r"   r#   _base_setup_args  s    
zWheelBuilder._base_setup_argsc             C   s   | j |}d|jf }t|t}tjd| |dd|g | j }|d k	rT|d|g7 }yt||jd|d dS    |jd	 tj	d
|j dS W d Q R X d S )Nz#Running setup.py bdist_wheel for %szDestination directory: %sbdist_wheelz-dz--python-tagF)cwdshow_stdoutspinnerTerrorzFailed building wheel for %s)
rx  rs   r   r  r  rj  r   setup_py_dirfinishr}  )r   r   rs  rl  	base_argsspin_messager|  
wheel_argsr"   r"   r#   __build_one  s    



zWheelBuilder.__build_onec             C   sV   | j |}tjd|j |ddg }yt||jdd dS    tjd|j dS d S )NzRunning setup.py clean for %scleanz--allF)rz  r{  Tz Failed cleaning build dir for %s)rx  r  rp  rs   r   rE  r}  )r   r   r  
clean_argsr"   r"   r#   rq    s    
zWheelBuilder._clean_oneFc             C   s  | j s|r| jst| jj| j | jjj }g }x|D ]}|jrDq8|j	r^|st
jd|j q8|rj|jrjq8|r|jr|jj rq8|r|j rq8|r|j}|j \}}tjj|d|dkrq8dtjj| jjt|jkrt
jd|j q8|j| q8W | sdS t
jddjdd	 |D  t J g g  }}	x6|D ],}d}
|rtj}
t| j|j}yt| W nB tk
r } z$t
j d
|j| |	j| w6W Y dd}~X nX n| j }| j!|||
d}|rX|j| |rb|jrt"j#j$t"j#j|jt% rtd|j&  |j'| jj(|_tjj)t*||_|jj	s<tt+|j|jdd| jj,d n
|	j| q6W W dQ R X |rt
jddjdd	 |D  |	rt
jddjdd	 |	D  t-|	dkS )zBuild wheels.

        :param unpack: If True, replace the sdist we built from with the
            newly built wheel, in preparation for installation.
        :return: True if all the wheels built correctly.
        z(Skipping %s, due to already being wheel.NrB   zCSkipping bdist_wheel for %s, due to binaries being disabled for it.Tz*Building wheels for collected packages: %sz, c             S   s   g | ]
}|j qS r"   )rs   )r   r   r"   r"   r#   r     s    z&WheelBuilder.build.<locals>.<listcomp>z Building wheel for %s failed: %s)rl  zbad source dir - missing markerF)sessionzSuccessfully built %s c             S   s   g | ]
}|j qS r"   )rs   )r   r   r"   r"   r#   r   M  s    zFailed to build %sc             S   s   g | ]
}|j qS r"   )rs   )r   r   r"   r"   r#   r   R  s    r   ).ri  rg  r   rd  prepare_filesre  requirementsvalues
constraintrC   r  rp  rs   editabler&   rD   rE  splitextrE   rF   egg_info_matchesrG   r!   r   r5   r6   r   r   implementation_tagrA   r   rI   rJ  ru  r;   r<   r   r   remove_temporary_sourcebuild_location	build_dirrQ   r   r   r  ra   )r   autobuildingreqsetbuildsetr   r&   r<  extbuild_successbuild_failurerl  rr  rV   
wheel_filer"   r"   r#   build  s    






zWheelBuilder.build)NN)N)N)F)
r(   r)   r*   r+   r$   ru  rx  ro  rq  r  r"   r"   r"   r#   rc    s    


rc  )r   r      )rZ   r  )FNNTNFN)Qr+   
__future__r   r  r  rJ   r2  r7   loggingr;   os.pathr   r   r   rq   rm  r  base64r   email.parserr   pip._vendor.sixr   rE   
pip.compatr   pip.downloadr   r   pip.exceptionsr	   r
   r   pip.locationsr   r   r   r7  r   r   r   r   r   pip.utils.uir   pip.utils.loggingr   pip.utils.setuptools_buildr   pip._vendor.distlib.scriptsr   pip._vendorr   pip._vendor.packaging.utilsr   pip._vendor.six.movesr   	wheel_extrH  	getLoggerr(   r  objectr   rA   r%   rl   rw   r   ra  rb  r   r   r   r,  r4  r=  rG  rK  rM   rc  r"   r"   r"   r#   <module>   sn   
)'


 
  #7