3
ÀÞL]E¥  ã               @   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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* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: e8�rúddl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZE ddlFmGZG ddlHmIZI ddlmJZJ ddlKmLZLmMZM ddlNmOZO ddlPmQZQ ddlRmSZS eAeTdf ZUdOZVejWeXƒZYd d!„ ZZdQd#d$„Z[dSd%d&„Z\d'd(„ Z]d)d*„ Z^d+d,„ Z_e
j`d-e
jaƒZbd.d/„ Zcd0d1„ Zdd2d3„ Zed4d5„ Zfd6d7„ ZgdTd:d;„Zhd<d=„ Zid>d?„ Zjd@dA„ ZkG dBdC„ dCelƒZme
j`dDe
jnƒfdEdF„ZodGdH„ ZpdIdJ„ ZqdKdL„ ZrG dMdN„ dNelƒZsdS )UzH
Support for installing and building the "wheel" binary package format.
é    )Úabsolute_importN)Úurlsafe_b64encode)ÚParser)Úpkg_resources)ÚScriptMaker)Úcanonicalize_name)ÚStringIO)Ú
pep425tags)Ú
unpack_url)ÚInstallationErrorÚInvalidWheelFilenameÚUnsupportedWheel)Údistutils_scheme)ÚLink)Ú
indent_log)ÚPIP_DELETE_MARKER_FILENAME)ÚLOG_DIVIDERÚcall_subprocessÚcaptured_stdoutÚ
ensure_dirÚformat_command_argsÚpath_to_urlÚread_chunks)Úmake_setuptools_shim_args)ÚTempDirectory)ÚMYPY_CHECK_RUNNING)Úopen_spinner)
ÚDictÚListÚOptionalÚSequenceÚMappingÚTupleÚIOÚTextÚAnyÚIterable)ÚRequirement)ÚInstallRequirement)Ú
PipSession)ÚFormatControlÚPackageFinder)ÚRequirementPreparer)Ú
WheelCache)Ú	Pep425Tag.é   c             C   s   t jj| |ƒjt jjdƒS )Nú/)ÚosÚpathÚrelpathÚreplaceÚsep)ÚsrcÚp© r8   ú2/tmp/pip-build-69lrc5qx/pip/pip/_internal/wheel.pyÚnormpathB   s    r:   é   c             C   sV   t jƒ }d}t| dƒ�2}x*t||d�D ]}|t|ƒ7 }|j|ƒ q&W W dQ R X ||fS )z5Return (hash, length) for path using hashlib.sha256()r   Úrb)ÚsizeN)ÚhashlibÚsha256Úopenr   ÚlenÚupdate)r2   Ú	blocksizeÚhÚlengthÚfÚblockr8   r8   r9   Ú	hash_fileF   s    rH   c             C   s6   t | |ƒ\}}dt|jƒ ƒjdƒjdƒ }|t|ƒfS )z?Return (encoded_digest, length) for path using hashlib.sha256()zsha256=Úlatin1ú=)rH   r   ÚdigestÚdecodeÚrstripÚstr)r2   rC   rD   rE   rK   r8   r8   r9   ÚrehashR   s
    
rO   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Úbinr8   r8   r9   Úopen_for_csv]   s    rZ   c             C   s   | j dƒ}||d< dj|ƒS )zBReplace the Python tag in a wheel file name with a new value.
    ú-rP   éýÿÿÿ)ÚsplitÚjoin)Z	wheelnameZnew_tagÚpartsr8   r8   r9   Úreplace_python_tagh   s    
r`   c             C   s–   t jj| ƒr’t| 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)r1   r2   Úisfiler@   ÚreadlineÚ
startswithrT   Ú
executableÚencodeÚgetfilesystemencodingÚlinesepÚreadÚwrite)r2   ÚscriptÚ	firstlineÚexenameÚrestr8   r8   r9   Ú
fix_scriptq   s    

rp   zX^(?P<namever>(?P<name>.+?)(-(?P<ver>.+?))?)
                                \.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.
    r[   Ú_rV   ÚWHEELzroot-is-purelib: trueTNF)r4   r1   ÚlistdirÚdist_info_reÚmatchÚgroupr@   r2   r^   ÚlowerrM   )rV   ÚwheeldirÚname_foldedÚitemru   ÚwheelÚliner8   r8   r9   Úroot_is_purelib‰   s    

r}   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	j
|ƒ}|jdi ƒ}|jdi ƒ}dd„ ‰ t‡ fdd„|jƒ D ƒƒ}t‡ fd	d„|jƒ D ƒƒ}||fS )
NÚ
r   Úconsole_scriptsÚgui_scriptsc             S   s   t | ƒjddƒjdƒS )zRget the string representation of EntryPoint, remove space and split
        on '='ú rS   rJ   )rN   r4   r]   )Úsr8   r8   r9   Ú	_split_ep¯   s    z"get_entrypoints.<locals>._split_epc             3   s   | ]}ˆ |ƒV  qd S )Nr8   )Ú.0Úv)rƒ   r8   r9   ú	<genexpr>µ   s    z"get_entrypoints.<locals>.<genexpr>c             3   s   | ]}ˆ |ƒV  qd S )Nr8   )r„   r…   )rƒ   r8   r9   r†   ¶   s    )r1   r2   Úexistsr@   r   rk   ÚstripÚseekr   Ú
EntryPointÚ	parse_mapÚgetÚdictÚvalues)ÚfilenameÚfpÚdatar|   Úentry_pointsÚconsoleÚguir8   )rƒ   r9   Úget_entrypointsš   s    

r•   c       
         sR  | sdS t jtƒ}x2| D ]*}tjj|ƒ}tjj|ƒ}|| j|ƒ qW dd„ tjj	ddƒj
tjƒD ƒ‰ ˆ jtjjtjjtjƒƒƒ ‡ fdd„|jƒ D ƒ}|s dS g }xn|jƒ D ]b\}} t| ƒ}t|ƒdkrÚd	j|d
 ƒ}n$djdj|dd… ƒd |d  ƒ}|jdj||ƒƒ q®W d}	t|ƒdk�r8|j|	jdƒƒ n|j|	jdƒƒ dj|ƒS )zž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.
    Nc             S   s    g | ]}t jj|ƒjt jƒ‘qS r8   )r1   r2   ÚnormcaserM   r5   )r„   Úir8   r8   r9   ú
<listcomp>Í   s    z5message_about_scripts_not_on_PATH.<locals>.<listcomp>ÚPATHrS   c                s&   i | ]\}}t jj|ƒˆ kr||“qS r8   )r1   r2   r–   )r„   Ú
parent_dirÚscripts)Únot_warn_dirsr8   r9   ú
<dictcomp>Ó   s   z5message_about_scripts_not_on_PATH.<locals>.<dictcomp>r/   zscript {} isr   zscripts {} arez, z and z.The {} installed in '{}' which is not on PATH.zeConsider adding {} to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.zthis directoryzthese directoriesr~   éÿÿÿÿrž   )ÚcollectionsÚdefaultdictÚsetr1   r2   ÚdirnameÚbasenameÚaddÚenvironrŒ   r]   ÚpathsepÚappendr–   rT   rf   ÚitemsÚsortedrA   Úformatr^   )
r›   Zgrouped_by_dirÚdestfilerš   Úscript_nameZwarn_forZ	msg_linesZsorted_scriptsZ
start_textZlast_line_fmtr8   )rœ   r9   Ú!message_about_scripts_not_on_PATHº   s:    


 r­   c             C   s   t | dd„ d�S )a;  
    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.
    c             S   s   t dd„ | D ƒƒS )Nc             s   s   | ]}t |ƒV  qd S )N)rN   )r„   Úxr8   r8   r9   r†   	  s    z3sorted_outrows.<locals>.<lambda>.<locals>.<genexpr>)Útuple)Úrowr8   r8   r9   Ú<lambda>	  s    z sorted_outrows.<locals>.<lambda>)Úkey)r©   )Úoutrowsr8   r8   r9   Úsorted_outrows÷   s    r´   c             C   sÞ   g }x~| D ]v}t |ƒdkr*tjdj|ƒƒ t|ƒ}|d }|j||ƒ}||d< ||krrt|ƒ\}	}
|	|d< |
|d< |jt|ƒƒ q
W x2|D ]*}t|ƒ\}	}
|jt	||ƒ|	t
|
ƒfƒ qŠW x |D ]}|j|| ddfƒ q¾W |S )z_
    :param installed: A map from archive RECORD path to installation RECORD
        path.
    rP   z,RECORD line has more than three elements: {}r   r/   é   rS   )rA   ÚloggerÚwarningrª   ÚlistÚpoprO   r§   r¯   r:   rN   )Zold_csv_rowsÚ	installedÚchangedÚ	generatedÚlib_dirZinstalled_rowsr°   Zold_pathÚnew_pathrK   rE   rF   r8   r8   r9   Úget_csv_rows_for_installed  s(    


r¿   FTc       *   *      s’  |st | |||||	d�}t| ˆ
ƒr,|d ‰n|d ‰g ‰g ‰ˆ
jtjjƒtjj }i ‰tƒ ‰ g }|r²tƒ �4}tj	ƒ �  tj
dƒ tj|ddd� W dQ R X W dQ R X tj|jƒ ƒ d1‡ ‡‡‡
fd	d
„	‰d2‡‡‡‡	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�rdt}|}tjjˆ
||ƒ}|| }|||d||d� �qJW �q(W td|d ƒ‰dˆ_dhˆ_dˆ_‡‡	fdd„}|ˆ_dˆ_ˆjddƒ}|�r�dtjk�rd| }|jˆj|ƒƒ tjjddƒdk�rFdt j!dd… |f }|jˆj|ƒƒ dt j!dd… |f }|jˆj|ƒƒ dd „ ˆD ƒ}x|D ]}ˆ|= �q€W ˆjd!dƒ}|�rdtjk�rÆd"| }|jˆj|ƒƒ d#t j!dd… |f }|jˆj|ƒƒ d$d „ ˆD ƒ}x|D ]}ˆ|= �q W t"ˆƒdk�rbˆj#d%d „ ˆj$ƒ D ƒƒ}|j|ƒ |
�rbt%|ƒ}|dk	�rbtj&|ƒ 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,|"d.ƒ�`}$t,|#d/ƒ�J}%t-j.|$ƒ}&t/|&ˆˆ |ˆd0�}'t-j0|%ƒ}(xt1|'ƒD ]})|(j2|)ƒ �qZW W dQ R X W dQ R X t)j*|#|"ƒ dS )3zInstall a wheel)ÚuserÚhomeÚrootÚisolatedÚprefixÚpurelibÚplatlibÚignoreT)ÚforceÚquietNFc                s.   t | ˆƒ}t |ˆƒ}|ˆ|< |r*ˆ j|ƒ dS )z6Map archive RECORD paths to installation RECORD paths.N)r:   r¤   )Úsrcfiler«   ÚmodifiedÚoldpathÚnewpath)r»   rº   r½   rx   r8   r9   Úrecord_installedb  s
    

z*move_wheel_files.<locals>.record_installedc                sð  t |ƒ �xàt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ˆ sêtd| d djˆƒ ƒ‚ˆj
|ƒ qpW xî|D ]æ}|�r||ƒ�rqþtjj||ƒ}tjj|||ƒ}t |	ƒ tjj|ƒ�rRtj|ƒ tj||ƒ tj|ƒ}ttdƒ�rˆtj||j|jfƒ tj|tjƒ�rÆtj|ƒ}|jtjB tjB tjB }tj||ƒ d	}|�rØ||ƒ}ˆ|||ƒ qþW qW d S )
Nr/   r   z.datarS   z
.dist-infoz!Multiple .dist-info directories: z, ÚutimeF)r   r1   ÚwalkrA   Úlstripr2   r5   r^   r]   Úendswithr§   r   re   rV   ÚAssertionErrorr‡   ÚunlinkÚ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Údestdirr‚   Ú
destsubdirrF   rÊ   r«   ÚstÚpermissionsr»   )Ú	data_dirsÚinfo_dirrÎ   Úreqr8   r9   Úclobberj  sN    








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.exeé   z
-script.pyé
   z.pyaéüÿÿÿiöÿÿÿrõ   )rw   rÒ   )rV   Ú	matchname)r“   r”   r8   r9   Úis_entrypoint_wrapper¸  s    z/move_wheel_files.<locals>.is_entrypoint_wrapperr›   )rå   ræ   rS   c                s<   | j d krtd| ˆf ƒ‚ˆ j| j| j jdƒd | j dœ S )Nz­Invalid 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ñ   r8   r9   Ú_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/   rP   c             S   s   g | ]}t jd |ƒr|‘qS )zpip(\d(\.\d)?)?$)Úreru   )r„   Úkr8   r8   r9   r˜   /  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  ru   )r„   r  r8   r8   r9   r˜   <  s    c             S   s   g | ]}d | ‘qS )z%s = %sr8   )r„   Úkvr8   r8   r9   r˜   D  s    c             S   s   g | ]}d | ‘qS )z%s = %sr8   )r„   r  r8   r8   r9   r˜   P  s    r”   Ú	INSTALLERzINSTALLER.piprb   s   pip
ÚRECORDz
RECORD.pipÚrzw+)rº   r»   r¼   r½   )F)NN)3r   r}   rM   r1   r2   r5   r¡   r   ÚwarningsÚcatch_warningsÚfilterwarningsÚ
compileallÚcompile_dirr¶   ÚdebugÚgetvaluerÓ   r^   r•   rs   rp   r   rò   ÚvariantsÚset_moder   rý   r¹   r¥   ÚextendÚmakerŒ   rT   ÚversionrA   Úmake_multipler¨   r­   r·   r@   rk   rÕ   Úmover§   rZ   ÚcsvÚreaderr¿   Úwriterr´   Úwriterow)*rV   rñ   rx   rÀ   rÁ   rÂ   Ú	pycompileÚschemerÃ   rÄ   Zwarn_script_locationrâ   r¼   Ústdoutrò   Úep_filer÷   Údatadirrå   ræ   Úsubdirrã   r   Ú
pip_scriptÚspecÚpip_epr  Úeasy_install_scriptÚeasy_install_epZgenerated_console_scriptsÚmsgÚ	installerÚtemp_installerÚinstaller_fileÚrecordÚtemp_recordÚ	record_inÚ
record_outr  r³   r  r°   r8   )r»   r“   rï   r”   rð   rº   r½   rÿ   rÎ   rñ   rx   r9   Úmove_wheel_files0  sÄ    




$F


#








$r0  c             C   sn   yTdd„ t jd| ƒD ƒd }|jdƒ}tƒ j|ƒ}|d jƒ }ttt|j	dƒƒƒ}|S  t
k
rh   dS X dS )z…
    Return the Wheel-Version of an extracted wheel, if possible.

    Otherwise, return None if we couldn't parse / extract it.
    c             S   s   g | ]}|‘qS r8   r8   )r„   Údr8   r8   r9   r˜   v  s    z!wheel_version.<locals>.<listcomp>Nr   rr   zWheel-Versionrø   )r   Úfind_on_pathÚget_metadatar   Úparsestrrˆ   r¯   ÚmapÚintr]   Ú	Exception)Ú
source_dirÚdistÚ
wheel_datar  r8   r8   r9   Úwheel_versionn  s    
r;  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_COMPATIBLEr^   r5  rN   r¶   r·   )r  rV   r8   r8   r9   Úcheck_compatibility‚  s    
r=  c             C   s
   dj | ƒS )z�
    Format three tags in the form "<python_tag>-<abi_tag>-<platform_tag>".

    :param file_tag: A 3-tuple of tags (python_tag, abi_tag, platform_tag).
    r[   )r^   )Zfile_tagr8   r8   r9   Ú
format_tag   s    r>  c               @   sB   e Zd ZdZejdejƒZdd„ Zdd„ Z	ddd	„Z
dd
d„ZdS )ÚWheelzA wheel filez�^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))
        ((-(?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
ƒj	dƒˆ _‡ 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.rV   rq   r[   ÚverÚbuildÚpyverrø   ÚabiÚplatc                s.   h | ]&}ˆ j D ]}ˆ jD ]}|||f’qqqS r8   )ÚabisÚplats)r„   r®   ÚyÚz)Úselfr8   r9   ú	<setcomp>Ì  s   z!Wheel.__init__.<locals>.<setcomp>N)Úwheel_file_reru   r   r�   rv   r4   rV   r  Z	build_tagr]   Ú
pyversionsrE  rF  Ú	file_tags)rI  r�   Ú
wheel_infor8   )rI  r9   Ú__init__·  s    

zWheel.__init__c             C   s   t dd„ | jD ƒƒS )zF
        Return the wheel's tags as a sorted list of strings.
        c             s   s   | ]}t |ƒV  qd S )N)r>  )r„   Útagr8   r8   r9   r†   Ö  s    z0Wheel.get_formatted_file_tags.<locals>.<genexpr>)r©   rM  )rI  r8   r8   r9   Úget_formatted_file_tagsÑ  s    zWheel.get_formatted_file_tagsNc                s4   ˆ dkrt jƒ ‰ ‡ fdd„| jD ƒ}|r0t|ƒ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 r8   )Úindex)r„   Úc)Útagsr8   r9   r˜   â  s    z+Wheel.support_index_min.<locals>.<listcomp>)r	   Úget_supportedrM  Úmin)rI  rT  Úindexesr8   )rT  r9   Úsupport_index_minØ  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	   rU  Úboolr¡   ÚintersectionrM  )rI  rT  r8   r8   r9   Ú	supportedå  s    zWheel.supported)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r  ÚcompileÚVERBOSErK  rO  rQ  rX  r[  r8   r8   r8   r9   r?  ª  s   
r?  z([a-z0-9_.]+)-([a-z0-9_.!+-]+)c             C   s   t |j| ƒƒS )zjDetermine whether the string looks like an egg_info.

    :param s: The string to parse. E.g. foo-2.1
    )rY  Úsearch)r‚   Ú_egg_info_rer8   r8   r9   Ú_contains_egg_infoí  s    rd  c             C   s    | j r
dS | jr&|s"tjd| jƒ dS |s.dS | js<| j r@dS d|jt| jƒƒkrftjd| jƒ dS | j	rz| j	j
 rzdS | j	}|jƒ \}}|rœt|ƒrœdS dS )aZ  
    Return whether to build an InstallRequirement object using the
    ephemeral cache.

    :param cache_available: whether a cache directory is available for the
        autobuilding=True case.

    :return: True or False to build the requirement with ephem_cache=True
        or False, respectively; or None not to build the requirement.
    Nz(Skipping %s, due to already being wheel.FÚbinaryzCSkipping bdist_wheel for %s, due to binaries being disabled for it.T)Ú
constraintÚis_wheelr¶   ÚinforV   Úeditabler8  Zget_allowed_formatsr   ÚlinkÚis_artifactÚsplitextrd  )rñ   Úformat_controlÚautobuildingÚcache_availablerj  ÚbaseÚextr8   r8   r9   Úshould_use_ephemeral_cacheö  s0    
rr  c             C   s^   t | ƒ}dj|ƒ}|s |d7 }n:tjƒ tjkr8|d7 }n"|jdƒsJ|d7 }|dj|tƒ7 }|S )z1
    Format command information for logging.
    zCommand arguments: {}
zCommand output: Nonez'Command output: [use --verbose to show]r~   zCommand output:
{}{})r   rª   r¶   ÚgetEffectiveLevelÚloggingÚDEBUGrÒ   r   )Úcommand_argsÚcommand_outputÚcommand_descÚtextr8   r8   r9   Úformat_command_result,  s    



rz  c             C   sx   t | ƒ} | s4dj|jƒ}|t||ƒ7 }tj|ƒ dS t| ƒdkrfdj|j| ƒ}|t||ƒ7 }tj|ƒ tjj	|| d ƒS )zH
    Return the path to the wheel in the temporary build directory.
    z1Legacy build of wheel for {!r} created no files.
Nr/   zZLegacy build of wheel for {!r} created more than one file.
Filenames (choosing first): {}
r   )
r©   rª   rV   rz  r¶   r·   rA   r1   r2   r^   )ÚnamesÚtemp_dirrñ   rv  rw  r(  r8   r8   r9   Úget_legacy_build_wheel_pathC  s    


r}  c               @   s\   e Zd ZdZddd„Zddd„Zddd	„Zd
d„ Zddd„Zddd„Z	dd„ Z
ddd„ZdS )ÚWheelBuilderz#Build wheels from a RequirementSet.NFc             C   s8   || _ || _|| _|j| _|p g | _|p*g | _|| _d S )N)ÚfinderÚpreparerÚwheel_cacheÚwheel_download_dirÚ
_wheel_dirÚbuild_optionsÚglobal_optionsÚno_clean)rI  r  r€  r�  r„  r…  r†  r8   r8   r9   rO  f  s    


zWheelBuilder.__init__c             C   s"   |j � | j|||d�S Q R X dS )ziBuild one wheel.

        :return: The filename of the built wheel, or None if the build failed.
        )Ú
python_tagN)Z	build_envÚ_build_one_inside_env)rI  rñ   Ú
output_dirr‡  r8   r8   r9   Ú
_build_onez  s    zWheelBuilder._build_onec             C   sÀ   t dd��¬}|jr| j}n| j}|||j|d�}|d k	r¨tjj|ƒ}tjj||ƒ}y@t|ƒ\}	}
t	j
||ƒ tjd|j||
|	jƒ ƒ tjd|ƒ |S  tk
r¦   Y nX | j|ƒ d S Q R X d S )Nr{   )Úkind)r‡  z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %s)r   Z
use_pep517Ú_build_one_pep517Ú_build_one_legacyr2   r1   r£   r^   rH   rÕ   r  r¶   rh  rV   Ú	hexdigestr7  Ú
_clean_one)rI  rñ   r‰  r‡  r|  ZbuilderÚ
wheel_pathÚ
wheel_nameZ	dest_pathZ
wheel_hashrE   r8   r8   r9   rˆ  „  s(    

z"WheelBuilder._build_one_inside_envc             C   s   t |jdd�}|t| jƒ S )NT)Zunbuffered_output)r   Zsetup_py_pathr¸   r…  )rI  rñ   Úbase_cmdr8   r8   r9   Ú_base_setup_args�  s    zWheelBuilder._base_setup_argsc             C   s¾   |j dk	st‚| jr*tjd|jf ƒ dS ybd|jf |_tjd|ƒ |jj	||j d�}|rŠt
||ƒ}tjtjj||ƒtjj||ƒƒ |}W n" tk
r®   tjd|jƒ dS X tjj||ƒS )z•Build one InstallRequirement using the PEP 517 build process.

        Returns path to wheel if successfully built. Otherwise, returns None.
        NzGCannot build wheel for %s using PEP 517 when --build-options is presentzBuilding wheel for %s (PEP 517)zDestination directory: %s)Úmetadata_directoryzFailed building wheel for %s)r”  rÓ   r„  r¶   ÚerrorrV   Úspin_messager  Zpep517_backendZbuild_wheelr`   r1   Úrenamer2   r^   r7  )rI  rñ   Útempdr‡  r‘  Únew_namer8   r8   r9   rŒ  ¦  s*    

zWheelBuilder._build_one_pep517c             C   sÀ   | j |ƒ}d|jf }t|ƒ�˜}tjd|ƒ |dd|g | j }|dk	rT|d|g7 }yt||j|d�}W n, tk
r”   |j	dƒ tj
d	|jƒ dS X tj|ƒ}	t|	||||d
�}
|
S Q R X dS )z–Build one InstallRequirement using the "legacy" build process.

        Returns path to wheel if successfully built. Otherwise, returns None.
        z Building wheel for %s (setup.py)zDestination directory: %sÚbdist_wheelz-dNz--python-tag)ÚcwdÚspinnerr•  zFailed building wheel for %s)r{  r|  rñ   rv  rw  )r“  rV   r   r¶   r  r„  r   Úsetup_py_dirr7  Úfinishr•  r1   rs   r}  )rI  rñ   r˜  r‡  Ú	base_argsr–  rœ  Ú
wheel_argsÚoutputr{  r�  r8   r8   r9   r�  È  s,    



zWheelBuilder._build_one_legacyc             C   s^   | j |ƒ}tjd|jƒ |ddg }yt||jd� dS  tk
rX   tjd|jƒ dS X d S )NzRunning setup.py clean for %sÚcleanz--all)r›  Tz Failed cleaning build dir for %sF)r“  r¶   rh  rV   r   r8  r7  r•  )rI  rñ   rŸ  Ú
clean_argsr8   r8   r9   r�  é  s    
zWheelBuilder._clean_onec             C   sR  g }| j j}t| jp| jjƒ}x4|D ],}t||||d�}|dkrBq$|j||fƒ q$W |s\g S tdd„ |D ƒƒrˆ| jp~|o~| jj}	|	sˆt	‚t
jddjdd„ |D ƒƒƒ | j}
tƒ ��R g g  }}�x>|D �]4\}}d}|�rNtj}|rò|
j|jƒ}n|
j|jƒ}yt|ƒ W n@ tk
�rJ } z"t
jd	|j|ƒ |j|ƒ wÆW Y dd}~X nX n| j}| j|||d
�}|�rò|j|ƒ |�rü|j�r¦tjjtjj|jtƒƒ �r¦t	dƒ‚|jƒ  |j| jj ƒ|_t!t"|ƒƒ|_|jj#�sÚt	‚t$|j|jdd|d� qÆ|j|ƒ qÆW W dQ R X |�r,t
jddjdd„ |D ƒƒƒ |�rNt
jddjdd„ |D ƒƒƒ |S )zÙBuild 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.
        )rm  rn  ro  Nc             s   s   | ]\}}| V  qd S )Nr8   )r„   rq   Úephem_cacher8   r8   r9   r†     s    z%WheelBuilder.build.<locals>.<genexpr>z*Building wheels for collected packages: %sz, c             S   s   g | ]\}}|j ‘qS r8   )rV   )r„   rñ   rq   r8   r8   r9   r˜   !  s    z&WheelBuilder.build.<locals>.<listcomp>z Building wheel for %s failed: %s)r‡  zbad source dir - missing markerF)ÚsessionzSuccessfully built %sr�   c             S   s   g | ]
}|j ‘qS r8   )rV   )r„   rñ   r8   r8   r9   r˜   ]  s    zFailed to build %sc             S   s   g | ]
}|j ‘qS r8   )rV   )r„   rñ   r8   r8   r9   r˜   b  s    )%r  rm  rY  rƒ  r�  Ú	cache_dirrr  r§   ÚanyrÓ   r¶   rh  r^   r   r	   Úimplementation_tagZget_ephem_path_for_linkrj  Zget_path_for_linkr   ÚOSErrorr·   rV   rŠ  r8  r1   r2   r‡   r   Úremove_temporary_sourceÚbuild_locationr€  Ú	build_dirr   r   rg  r
   )rI  Úrequirementsr¥  rn  Úbuildsetrm  ro  rñ   r¤  Zhave_directory_for_buildÚ_cacheÚbuild_successÚbuild_failureZephemr‡  r‰  ÚeÚ
wheel_filer8   r8   r9   rA  õ  s‚    






zWheelBuilder.build)NNF)N)N)N)N)F)r\  r]  r^  r_  rO  rŠ  rˆ  r“  rŒ  r�  r�  rA  r8   r8   r8   r9   r~  c  s     



	
"
!r~  )r/   r   é   )r´  é   )rµ  )FNNTNFNT)tr_  Ú
__future__r   rŸ   r  r  r>   rt  Úos.pathr1   r  rÕ   r×   rT   r  Úbase64r   Úemail.parserr   Úpip._vendorr   Úpip._vendor.distlib.scriptsr   Úpip._vendor.packaging.utilsr   Zpip._vendor.sixr   Zpip._internalr	   Zpip._internal.downloadr
   Zpip._internal.exceptionsr   r   r   Zpip._internal.locationsr   Zpip._internal.models.linkr   Zpip._internal.utils.loggingr   Z pip._internal.utils.marker_filesr   Zpip._internal.utils.miscr   r   r   r   r   r   r   Z$pip._internal.utils.setuptools_buildr   Zpip._internal.utils.temp_dirr   Zpip._internal.utils.typingr   Zpip._internal.utils.uir   Útypingr   r   r   r    r!   r"   r#   r$   r%   r&   Ú"pip._vendor.packaging.requirementsr'   Zpip._internal.req.req_installr(   r)   Zpip._internal.indexr*   r+   Z pip._internal.operations.preparer,   Zpip._internal.cacher-   Zpip._internal.pep425tagsr.   rN   ZInstalledCSVRowr<  Ú	getLoggerr\  r¶   r:   rH   rO   rZ   r`   rp   r`  ra  rt   r}   r•   r­   r´   r¿   r0  r;  r=  r>  Úobjectr?  ÚIrd  rr  rz  r}  r~  r8   r8   r8   r9   Ú<module>   s”   $0


	
 =(       
  5
D6 