3
zYði—µ  ã               @   s,  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mZ d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZ d dlmZmZ  d dl!m"Z" d dl#Z$d dl%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dlImJZJ d dlKmLZL d dlMmNZN d dlOmPZP d dlQmRZR d dlSmTZT d dl#mUZUmVZV ejWeXƒZYejZj[j\ƒ Z]dd„ Z^dd„ Z_G dd„ de`ƒZad d!„ Zbd$d"d#„ZcdS )%é    )Úabsolute_importN)Ú	sysconfig)Úchange_root)Ú
FeedParser)Úpkg_resourcesÚsix)Ú
specifiers)ÚMarker)ÚInvalidRequirementÚRequirement)Úcanonicalize_name)ÚVersionÚparse)Úconfigparser)Ú
native_strÚ
get_stdlibÚWINDOWS)Úis_urlÚurl_to_pathÚpath_to_urlÚis_archive_file)ÚInstallationErrorÚUninstallationError)Úbin_pyÚrunning_under_virtualenvÚPIP_DELETE_MARKER_FILENAMEÚbin_user)Údisplay_pathÚrmtreeÚask_path_existsÚ
backup_dirÚis_installable_dirÚdist_in_usersiteÚdist_in_site_packagesÚegg_link_pathÚcall_subprocessÚread_text_fileÚFakeFileÚ_make_build_dirÚ
ensure_dirÚget_installed_versionÚnormalize_pathÚdist_is_local)ÚHashes)ÚRemovedInPip10Warning)Ú
indent_log)ÚSETUPTOOLS_SHIM)Úopen_spinner)ÚUninstallPathSet)Úvcs)Úmove_wheel_filesÚWheelc             C   s6   t jd| ƒ}d }|r*|jdƒ}|jdƒ}n| }||fS )Nz^(.+)(\[[^\]]+\])$é   é   )ÚreÚmatchÚgroup)ÚpathÚmÚextrasÚpath_no_extras© r?   ú2/tmp/pip-build-ue6tjl93/pip/pip/req/req_install.pyÚ_strip_extras9   s    
rA   c             C   s   t dd„ | D ƒƒS )Nc             s   s   | ]}t j|ƒV  qd S )N)r   Ú
safe_extra)Ú.0Úextrar?   r?   r@   ú	<genexpr>F   s    z_safe_extras.<locals>.<genexpr>)Úset)r=   r?   r?   r@   Ú_safe_extrasE   s    rG   c               @   sŒ  e Zd ZdQdd„ZedRdd„ƒZedSdd	„ƒZd
d„ Zdd„ Zdd„ Z	e
dd„ ƒZe
dd„ ƒZdd„ Zdd„ Zdd„ Ze
dd„ ƒZe
dd„ ƒZe
dd„ ƒZd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zejd(ƒZe
d)d*„ ƒZd+d,„ ZdTd-d.„ZdUd/d0„Zd1d2„ Zd3d4„ Zd5d6„ Z d7d8„ Z!dVd9d:„Z"g ddfd;d<„Z#d=d>„ Z$d?d@„ Z%dAdB„ Z&f dfdCdD„Z'dEdF„ Z(e
dGdH„ ƒZ)dWdIdJ„Z*dKdL„ Z+e
dMdN„ ƒZ,dXdOdP„Z-dS )YÚInstallRequirementNFTc                sJ  f | _ tˆ tjƒr�ytˆ ƒ‰ W nd tk
r‚   tjjˆ kr@d}n.dˆ krft	‡ fdd„t
D ƒƒ rfd}ntjƒ }tdˆ |f ƒ‚Y nX tˆ j ƒ| _ ˆ | _|| _|| _|| _|| _|| _| | _| _|| _|	d k	rÖ|	| _nˆ oÞˆ j| _d | _d | _d | _d | _d | _|| _d | _ d | _!d| _"d| _#d | _$|�r.|ni | _%|| _&d| _'|
| _(d S )Nz%It looks like a path. Does it exist ?ú=c             3   s   | ]}|ˆ kV  qd S )Nr?   )rC   Úop)Úreqr?   r@   rE   V   s    z.InstallRequirement.__init__.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s'
%sF))r=   Ú
isinstancer   Ústring_typesr   r
   Úosr;   ÚsepÚanyÚ	operatorsÚ	tracebackÚ
format_excr   rG   rK   Ú
comes_fromÚ
constraintÚ
source_dirÚeditableÚ_wheel_cacheÚlinkÚoriginal_linkÚas_eggÚmarkersÚmarkerÚ_egg_info_pathÚsatisfied_byÚconflicts_withÚ_temp_build_dirÚ_ideal_build_dirÚupdateÚinstall_succeededÚuninstalledÚnothing_to_uninstallÚuse_user_siteÚ
target_dirÚoptionsÚ	pycompileÚpreparedÚisolated)ÚselfrK   rT   rV   rW   rY   r[   rc   rj   r\   rl   ri   Úwheel_cacherU   Úadd_msgr?   )rK   r@   Ú__init__K   sN     zInstallRequirement.__init__c             C   sp   ddl m} t||ƒ\}	}
}|
jdƒr0t|
ƒ}nd }| |	||d||
ƒ|||rP|ni |d�	}|d k	rlt|ƒ|_|S )Nr   )ÚLinkzfile:T)rV   rW   rY   rU   rl   ri   rn   )Ú	pip.indexrq   Úparse_editableÚ
startswithr   rG   r=   )ÚclsÚeditable_reqrT   Údefault_vcsrl   ri   rn   rU   rq   ÚnameÚurlÚextras_overriderV   Úresr?   r?   r@   Úfrom_editable‰   s     



z InstallRequirement.from_editablec          
   C   sÄ  ddl m} t|ƒrd}nd}||krR|j|dƒ\}}	|	jƒ }	|	sHd}	qVt|	ƒ}	nd}	|jƒ }d}
tjjtjj	|ƒƒ}d}d}t|ƒr�||ƒ}n€t
|ƒ\}}tjj|ƒràtjj|ks¾|jdƒràt|ƒsÒtd| ƒ‚|t|ƒƒ}n0t|ƒ�rtjj|ƒ�stjd	|ƒ |t|ƒƒ}|�r||jd
k�rPtjd|jƒ�rP|ttjjtjj	|jƒƒƒƒ}|j�rtt|jƒ}d|j|jf }
n|j}
n|}
|�rŠ|ni }| |
|||	||||d�}|�rÀtt d| ƒj!ƒ|_!|S )zŒCreates an InstallRequirement from a name, which might be a
        requirement, directory containing 'setup.py', filename, or URL.
        r   )rq   z; ú;r6   NÚ.z;Directory %r is not installable. File 'setup.py' not found.zARequirement %r looks like a filename, but the file does not existÚfilez\.\./z%s==%s)rY   r\   rl   ri   rn   rU   Úplaceholder)"rr   rq   r   ÚsplitÚstripr	   rN   r;   ÚnormpathÚabspathrA   ÚisdirrO   rt   r!   r   r   r   ÚisfileÚloggerÚwarningÚschemer8   Úsearchry   Úis_wheelr5   Úfilenamerx   ÚversionÚegg_fragmentrG   r   r=   )ru   rx   rT   rl   ri   rn   rU   rq   Ú
marker_sepr\   rK   r;   rY   r=   ÚpÚwheelr{   r?   r?   r@   Ú	from_line£   sb    





zInstallRequirement.from_linec             C   s’   | j r(t| j ƒ}| jr:|d| jj 7 }n| jr6| jjnd }| jd k	rX|dt| jjƒ 7 }| jrŽt| jt	j
ƒrt| j}n
| jjƒ }|rŽ|d| 7 }|S )Nz from %sz in %sz
 (from %s))rK   ÚstrrY   ry   r_   r   ÚlocationrT   rL   r   rM   Ú	from_path)rm   ÚsrT   r?   r?   r@   Ú__str__ó   s    


zInstallRequirement.__str__c             C   s   d| j jt| ƒ| jf S )Nz<%s object: %s editable=%r>)Ú	__class__Ú__name__r“   rW   )rm   r?   r?   r@   Ú__repr__  s    zInstallRequirement.__repr__c             C   s^   | j dkr|j| |ƒ| _ | jdk	rZ| rZ| j }| jj| j | jƒ| _ || j krZtjd| j ƒ dS )a  Ensure that if a link can be found for this, that it is found.

        Note that self.link may still be None - if Upgrade is False and the
        requirement is already installed.

        If require_hashes is True, don't use the wheel cache, because cached
        wheels, always built locally, have different hashes than the files
        downloaded from the index server and thus throw false hash mismatches.
        Furthermore, cached wheels at present have undeterministic contents due
        to file modification times.
        NzUsing cached wheel link: %s)rY   Úfind_requirementrX   Úcached_wheelrx   r‡   Údebug)rm   ÚfinderÚupgradeÚrequire_hashesÚold_linkr?   r?   r@   Úpopulate_link	  s    

z InstallRequirement.populate_linkc             C   s   | j jS )N)rK   Ú	specifier)rm   r?   r?   r@   r£     s    zInstallRequirement.specifierc             C   s$   | j }t|ƒdko"tt|ƒƒjdkS )z„Return whether I am pinned to an exact version.

        For example, some-package==1.2 is pinned; some-package>1.2 is not.
        r6   ú==ú===)r¤   r¥   )r£   ÚlenÚnextÚiterÚoperator)rm   r   r?   r?   r@   Ú	is_pinned!  s    zInstallRequirement.is_pinnedc             C   sR   | j d krd S t| j ƒ}| jrNt| jtjƒr4| j}n
| jjƒ }|rN|d| 7 }|S )Nz->)rK   r“   rT   rL   r   rM   r•   )rm   r–   rT   r?   r?   r@   r•   +  s    


zInstallRequirement.from_pathc             C   s‚   | j d k	r| j S | jd kr<tjjtjddƒƒ| _ || _| j S | jrN| j	j
ƒ }n| j	}tjj|ƒsttjd|ƒ t|ƒ tjj||ƒS )Nz-buildzpip-zCreating directory %s)ra   rK   rN   r;   ÚrealpathÚtempfileÚmkdtemprb   rW   rx   ÚlowerÚexistsr‡   r�   r(   Újoin)rm   Ú	build_dirrx   r?   r?   r@   Úbuild_location8  s    

z!InstallRequirement.build_locationc             C   s¤   | j dk	rdS | jdk	st‚| js&t‚| js0t‚| j}d| _| j| jƒ}tjj|ƒrdt	dt
|ƒ ƒ‚tjd| t
|ƒt
|ƒƒ tj||ƒ || _d| _|| _ d| _dS )a�  Move self._temp_build_dir to self._ideal_build_dir/self.req.name

        For some requirements (e.g. a path to a directory), the name of the
        package is not available until we run egg_info, so the build_location
        will return a temporary directory and store the _ideal_build_dir.

        This is only called by self.egg_info_path to fix the temporary build
        directory.
        Nz<A package already exists in %s; please remove it to continuez,Moving package %s from %s to new location %s)rV   rK   ÚAssertionErrorra   rb   r²   rN   r;   r¯   r   r   r‡   r�   ÚshutilÚmover^   )rm   Úold_locationÚnew_locationr?   r?   r@   Ú_correct_build_locationS  s(    



z*InstallRequirement._correct_build_locationc             C   s    | j d krd S ttj| j jƒƒS )N)rK   r   r   Ú	safe_namerx   )rm   r?   r?   r@   rx   s  s    
zInstallRequirement.namec             C   s   t jj| j| jr| jjpdƒS )NÚ )rN   r;   r°   rV   rY   Úsubdirectory_fragment)rm   r?   r?   r@   Úsetup_py_diry  s    zInstallRequirement.setup_py_dirc             C   sŽ   | j std|  ƒ‚ydd l}W n: tk
rX   tdƒd kr@d}ntjƒ }td| ƒ‚Y nX tj	j
| jdƒ}tjrŠt|tjƒrŠ|jtjƒ ƒ}|S )NzNo source dir for %sr   Ú
setuptoolszPlease install setuptools.zWCould not import setuptools which is required to install from a source distribution.
%szsetup.py)rV   r³   r½   ÚImportErrorr*   rR   rS   r   rN   r;   r°   r¼   r   ÚPY2rL   Ú	text_typeÚencodeÚsysÚgetfilesystemencoding)rm   r½   ro   Úsetup_pyr?   r?   r@   rÄ     s    zInstallRequirement.setup_pyc             C   sZ  | j s
t‚| jr$tjd| j| jƒ ntjd| j| jƒ tƒ �x t| j }t	j
d|g}| jrd|dg7 }|dg }| jrzg }n tjj| jdƒ}t|ƒ ddg}t|| | jdd	d
� W d Q R X | j�stt| jƒ d ƒtƒrÞd}nd}tdj| jƒ d || jƒ d gƒƒ| _| jƒ  nDt| jƒ d ƒ}t| jjƒ|k�rVtjd| j| j|| jƒ t|ƒ| _d S )Nz2Running setup.py (path:%s) egg_info for package %sz7Running setup.py (path:%s) egg_info for package from %sz-cz--no-user-cfgÚegg_infozpip-egg-infoz
--egg-baseFzpython setup.py egg_info)ÚcwdÚshow_stdoutÚcommand_descr   z==z===rº   ÚNamezuRunning setup.py (path:%s) egg_info for package %s produced metadata for project name %s. Fix your #egg=%s fragments.)rV   r³   rx   r‡   r�   rÄ   rY   r/   r0   rÂ   Ú
executablerl   rW   rN   r;   r°   r¼   r)   r%   rK   rL   Úparse_versionÚpkg_infor   r   r¸   r   rˆ   )rm   ÚscriptÚbase_cmdÚegg_info_cmdÚegg_base_optionÚegg_info_dirrJ   Úmetadata_namer?   r?   r@   Úrun_egg_info—  sP    





zInstallRequirement.run_egg_infoc             C   sV   | j d k	r&| j j|ƒsd S | j j|ƒS | js0t‚| j|ƒ}tjj|ƒsJd S t	|ƒ}|S )N)
r_   Úhas_metadataÚget_metadatarV   r³   Úegg_info_pathrN   r;   r¯   r&   )rm   rŒ   Údatar?   r?   r@   Úegg_info_dataÑ  s    


z InstallRequirement.egg_info_datac                s|  | j d k�rl| jr| j}ntjj| jdƒ}tj|ƒ}| j�rg }x¾tj|ƒD ]°\‰ }}x t	j
D ]}||kr^|j|ƒ q^W xjt|ƒD ]^}tjjtjjˆ |ddƒƒsºtjjtjjˆ |ddƒƒrÆ|j|ƒ q‚|dksÖ|dkr‚|j|ƒ q‚W |j‡ fdd	„|D ƒƒ qLW d
d	„ |D ƒ}|�s$td||f ƒ‚|�s:td||f ƒ‚t|ƒdk�rX|jdd„ d� tjj||d ƒ| _ tjj| j |ƒS )Nzpip-egg-infoÚbinÚpythonÚScriptsz
Python.exeÚtestÚtestsc                s   g | ]}t jjˆ |ƒ‘qS r?   )rN   r;   r°   )rC   Údir)Úrootr?   r@   ú
<listcomp>ý  s   z4InstallRequirement.egg_info_path.<locals>.<listcomp>c             S   s   g | ]}|j d ƒr|‘qS )z	.egg-info)Úendswith)rC   Úfr?   r?   r@   rà   ÿ  s    z$No files/directories in %s (from %s)r6   c             S   s(   | j tjjƒtjjr"| j tjjƒp$d S )Nr   )ÚcountrN   r;   rO   Úaltsep)Úxr?   r?   r@   Ú<lambda>  s   z2InstallRequirement.egg_info_path.<locals>.<lambda>)Úkeyr   )r^   rW   rV   rN   r;   r°   r¼   ÚlistdirÚwalkr3   ÚdirnamesÚremoveÚlistÚlexistsr¯   Úextendr   r³   r¦   Úsort)rm   rŒ   ÚbaseÚ	filenamesÚdirsÚfilesrÞ   r?   )rß   r@   rÖ   Ý  sB    
z InstallRequirement.egg_info_pathc             C   s@   t ƒ }| jdƒ}|s*tjdt| jdƒƒƒ |j|p4dƒ |jƒ S )NzPKG-INFOzNo PKG-INFO file found in %srº   )r   rØ   r‡   rˆ   r   rÖ   ÚfeedÚclose)rm   r�   r×   r?   r?   r@   rÌ     s    
zInstallRequirement.pkg_infoz	\[(.*?)\]c             C   s
   t | jƒS )N)r*   rx   )rm   r?   r?   r@   Úinstalled_version   s    z$InstallRequirement.installed_versionc             C   sV   | j s
t‚| jƒ d }| jjr<|| jjkr<tjd| | jƒ ntjdt	| j ƒ|| ƒ d S )Nr�   z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)
rV   r³   rÌ   rK   r£   r‡   rˆ   rö   r�   r   )rm   r�   r?   r?   r@   Úassert_source_matches_version$  s    

z0InstallRequirement.assert_source_matches_versionc             C   sÊ   | j stjd| jƒ d S | js"t‚| js,t‚| j jdkr<d S d| j jksXtd| j j ƒ‚| jsbd S | j jj	ddƒ\}}t
j|ƒ}|r°|| j jƒ}|r¢|j| jƒ qÆ|j| jƒ ndsÆtd| j |f ƒ‚d S )Nz>Cannot update repository at %s; repository location is unknownr   ú+zbad url: %rr6   r   z+Unexpected version control type (in %s): %s)rY   r‡   r�   rV   rW   r³   r‰   ry   rc   r�   r3   Úget_backendÚobtainÚexport)rm   rú   Úvc_typery   ÚbackendÚvcs_backendr?   r?   r@   Úupdate_editable5  s,    


z"InstallRequirement.update_editablec                sx  | j ƒ std| jf ƒ‚| jp"| j}t|jƒ}t|ƒsTtj	d|j
|tjƒ d| _dS |tƒ krxtj	d|j
|ƒ d| _dS t|ƒ}t|ƒ}djtj|jƒƒ}|jo¬tjj|jƒ}t|jddƒ}|oØ|jjdƒoØ|jj|ƒ �rÊ|j|jƒ |jd	ƒ�r2xÐ|jd	ƒjƒ D ](}	tjj tjj!|j|	ƒƒ}
|j|
ƒ �qW n”|jd
ƒ�r|jdƒ�rV|jdƒ‰ ng ‰ xj‡ fdd„|jd
ƒjƒ D ƒD ]J}tjj!|j|ƒ}
|j|
ƒ |j|
d ƒ |j|
d ƒ |j|
d ƒ �qxW �nH|�ròt"j#dj| jƒt$ƒ |j|ƒ �n |jjdƒ�rH|j|jƒ tjj%|jƒd }tjj!tjj&|jƒdƒ}|j'|d| ƒ nÊ|�r€|jjdƒ�r€x´t(j)j*|ƒD ]}
|j|
ƒ �qjW n’|�rt+|dƒ�}tjj,|j-ƒ j.ƒ ƒ}W dQ R X ||jk�sÒt/d|| j|jf ƒ‚|j|ƒ tjj!tjj&|ƒdƒ}|j'||jƒ ntj0d||jƒ |jdƒ�r†|j1dƒ�r†xZ|j2dƒD ]L}t3|ƒ�rJt4}nt5}|jtjj!||ƒƒ t6�r6|jtjj!||ƒd ƒ �q6W |jdƒ�rdt7j8�r i }ndd#i}t9j:f |Ž}|j;t<|j=dƒƒƒ |j>dƒ�rdxŽ|j?dƒD ]€\}}t3|ƒ�røt4}nt5}|jtjj!||ƒƒ t6�rà|jtjj!||ƒd  ƒ |jtjj!||ƒd! ƒ |jtjj!||ƒd" ƒ �qàW |j@|ƒ || _AdS )$a¥  
        Uninstall the distribution currently satisfying this requirement.

        Prompts before removing or modifying files unless
        ``auto_confirm`` is True.

        Refuses to delete or modify files outside of ``sys.prefix`` -
        thus uninstallation within a virtual environment can only
        modify that virtual environment, even if the virtualenv is
        linked to global site-packages.

        z.Cannot uninstall requirement %s, not installedz1Not uninstalling %s at %s, outside environment %sTNz<Not uninstalling %s at %s, as it is in the standard library.z{0}.egg-infor;   z	.egg-infozinstalled-files.txtztop_level.txtznamespace_packages.txtc                s   g | ]}|r|ˆ kr|‘qS r?   r?   )rC   r�   )Ú
namespacesr?   r@   rà   ˜  s    z0InstallRequirement.uninstall.<locals>.<listcomp>z.pyz.pycz.pyozÖUninstalling a distutils installed project ({0}) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.z.eggr6   zeasy-install.pthz./z
.dist-infoÚrz;Egg-link %s does not match installed location of %s (at %s)z)Not sure how to uninstall: %s - Check: %sÚscriptsz.batzentry_points.txtÚ
delimitersrI   Úconsole_scriptsz.exez.exe.manifestz
-script.py)rI   )BÚcheck_if_existsr   rx   r_   r`   r+   r”   r,   r‡   Úinforç   rÂ   Úprefixrf   r   r2   r$   Úformatr   Úto_filenameÚproject_namerÅ   rN   r;   r¯   ÚgetattrÚ	_providerrá   ÚaddrÔ   rÕ   Ú
splitlinesrƒ   r°   ÚwarningsÚwarnr.   r�   ÚdirnameÚadd_pthÚpipr‘   Úuninstallation_pathsÚopenÚnormcaseÚreadliner‚   r³   r�   Úmetadata_isdirÚmetadata_listdirr"   r   r   r   r   r¿   r   ÚSafeConfigParserÚreadfpr'   Úget_metadata_linesÚhas_sectionÚitemsrë   re   )rm   Úauto_confirmÚdistÚ	dist_pathÚpaths_to_removeÚdevelop_egg_linkÚdevelop_egg_link_egg_infoÚegg_info_existsÚdistutils_egg_infoÚinstalled_filer;   Útop_level_pkgÚeasy_install_eggÚeasy_install_pthÚfhÚlink_pointerrÍ   Úbin_dirri   Úconfigrx   Úvaluer?   )r   r@   Ú	uninstallR  sÒ    








zInstallRequirement.uninstallc             C   s$   | j r| j jƒ  ntjd| jƒ d S )Nz'Can't rollback %s, nothing uninstalled.)re   Úrollbackr‡   Úerrorrx   )rm   r?   r?   r@   Úrollback_uninstallõ  s    z%InstallRequirement.rollback_uninstallc             C   s*   | j r| j jƒ  n| js&tjd| jƒ d S )Nz%Can't commit %s, nothing uninstalled.)re   Úcommitrf   r‡   r2  rx   )rm   r?   r?   r@   Úcommit_uninstallý  s
    z#InstallRequirement.commit_uninstallc             C   sæ  | j s
t‚d}d| j| jƒ d f }tjj||ƒ}tjj|ƒrÈtdt	|ƒ dƒ}|dkr^d	}nj|dkr‚t
jd
t	|ƒƒ tj|ƒ nF|dkr¶t|ƒ}t
jdt	|ƒt	|ƒƒ tj||ƒ n|dkrÈtjdƒ |�râtj|dtjdd�}tjjtjj| jƒƒ}xÐtj|ƒD ]Â\}	}
}d|
k�r"|
jdƒ xR|
D ]J}tjj|	|ƒ}| j||ƒ}tj| jd | d ƒ}d|_|j|dƒ �q(W xL|D ]D}|tk�rŽ�q|tjj|	|ƒ}| j||ƒ}|j|| jd | ƒ �q|W �qW |jƒ  t
j dt	|ƒƒ d S )NTz	%s-%s.zipr�   z8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort ÚiÚwÚbÚaFzDeleting %szBacking up %s to %sr6   )Ú
allowZip64zpip-egg-infoú/ií  é   rº   zSaved %s)r6  r7  r8  r9  éÿÿÿÿi  í)!rV   r³   rx   rÌ   rN   r;   r°   r¯   r   r   r‡   rˆ   rë   r    r´   rµ   rÂ   ÚexitÚzipfileÚZipFileÚZIP_DEFLATEDr  r„   r¼   ré   Ú_clean_zip_nameÚZipInfoÚexternal_attrÚwritestrr   Úwriterõ   r  )rm   r±   Úcreate_archiveÚarchive_nameÚarchive_pathÚresponseÚ	dest_fileÚziprÞ   Údirpathrê   rñ   r  rx   ÚzipdirrŒ   r?   r?   r@   Úarchive  sX    







"zInstallRequirement.archivec             C   sJ   |j |tjj ƒs"td||f ƒ‚|t|ƒd d … }|jtjjdƒ}|S )Nz$name %r doesn't start with prefix %rr6   r;  )rt   rN   r;   rO   r³   r¦   Úreplace)rm   rx   r  r?   r?   r@   rB  5  s
    z"InstallRequirement._clean_zip_namec                s0   |sd}ˆ j d k	r(t‡ fdd„|D ƒƒS dS d S )Nrº   c             3   s   | ]}ˆ j jd |iƒV  qdS )rD   N)r\   Úevaluate)rC   rD   )rm   r?   r@   rE   D  s   z3InstallRequirement.match_markers.<locals>.<genexpr>T)rº   )r\   rP   )rm   Úextras_requestedr?   )rm   r@   Úmatch_markers=  s    


z InstallRequirement.match_markersc          ,      s^  | j r| j|||d� d S | jrZtjj| jƒ}tjj|| jƒ | j	| jˆ |d� d| _
d S || jjdg ƒ7 }|| jjdg ƒ7 }| jr’t|ƒdg }tjddƒ}tjj|d	ƒ}�zˆ| j||ˆ |ƒ}d
| jf }	t|	ƒ�.}
tƒ � t|| | jd|
d� W d Q R X W d Q R X tjj|ƒ�s&tjd|ƒ d S d| _
| j�r8d S ‡ fdd„}t|ƒ�H}x@|D ](}tjj|ƒ}|jdƒ�rT||ƒ}P �qTW tj d| ƒ d S W d Q R X g }t|ƒ�P}xH|D ]@}|j!ƒ }tjj"|ƒ�rÔ|tjj#7 }|j$tjj%||ƒ|ƒƒ �q®W W d Q R X tjj|dƒ}t|dƒ�}|j&dj|ƒd ƒ W d Q R X W d tjj|ƒ�rPtj'|ƒ t(|ƒ X d S )N)r  )rß   r  TÚglobal_optionsÚinstall_optionsz--no-user-cfgz-recordzpip-zinstall-record.txtzRunning setup.py install for %sF)rÆ   rÇ   ÚspinnerzRecord file %s not foundc                s(   ˆ d kst jj| ƒ r| S tˆ | ƒS d S )N)rN   r;   Úisabsr   )r;   )rß   r?   r@   Úprepend_rootz  s    z0InstallRequirement.install.<locals>.prepend_rootz	.egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr7  Ú
))rW   Úinstall_editabler‹   r  r‘   Úwheel_versionrV   Úcheck_compatibilityrx   r4   rd   ri   Úgetrl   rì   r¬   r­   rN   r;   r°   Úget_install_argsr1   r/   r%   r¼   r¯   r‡   r�   r[   r  r  rá   rˆ   r‚   r…   rO   ÚappendÚrelpathrF  rë   r   )rm   rU  rT  rß   r  r�   Útemp_locationÚrecord_filenameÚinstall_argsÚmsgrV  rX  râ   ÚlineÚ	directoryrÑ   Ú	new_linesrŒ   Úinst_files_pathr?   )rß   r@   ÚinstallI  sv    




"
zInstallRequirement.installc             C   s   | j dkr| j|ƒ| _ | j S )aA  Ensure that a source_dir is set.

        This will create a temporary build dir if the name of the requirement
        isn't known yet.

        :param parent_dir: The ideal pip parent_dir for the source_dir.
            Generally src_dir for editables and build_dir for sdists.
        :return: self.source_dir
        N)rV   r²   )rm   Ú
parent_dirr?   r?   r@   Úensure_has_source_dir¡  s    

z(InstallRequirement.ensure_has_source_dirc             C   sÄ   t jdg}|jdƒ |jt| j ƒ |t|ƒdd|g 7 }| jsJ|dg7 }|d k	r^|d|g7 }|d k	rr|d|g7 }| jr„|dg7 }n
|d	g7 }tƒ rÀd
t	j
ƒ  }|dtjjt jdd|| jƒg7 }|S )Nz-uz-cri  z--recordz#--single-version-externally-managedz--rootz--prefixz	--compilez--no-compilerÚ   z--install-headersÚincludeÚsite)rÂ   rÊ   r_  r0   rÄ   rì   r[   rj   r   r   Úget_python_versionrN   r;   r°   r  rx   )rm   rT  rb  rß   r  rc  Ú
py_ver_strr?   r?   r@   r^  ¯  s(    



z#InstallRequirement.get_install_argsc             C   sd   | j r6tjjtjj| j tƒƒr6tjd| j ƒ t| j ƒ d| _ | j	rZtjj| j	ƒrZt| j	ƒ d| _	dS )zVRemove the source files from this requirement, if they are marked
        for deletionzRemoving source in %sN)
rV   rN   r;   r¯   r°   r   r‡   r�   r   ra   )rm   r?   r?   r@   Úremove_temporary_sourceË  s    

z*InstallRequirement.remove_temporary_sourcec             C   s�   t jd| jƒ | jr"t|ƒdg }|r>dj|ƒg}t|ƒ| }tƒ �< ttj	dt
| j gt|ƒ ddg t|ƒ | jdd� W d Q R X d	| _d S )
NzRunning setup.py develop for %sz--no-user-cfgz--prefix={0}z-cÚdevelopz	--no-depsF)rÆ   rÇ   T)r‡   r  rx   rl   rì   r  r/   r%   rÂ   rÊ   r0   rÄ   r¼   rd   )rm   rU  rT  r  Úprefix_paramr?   r?   r@   rZ  ×  s     z#InstallRequirement.install_editablec             C   sÒ   | j dkrdS yFtt| j ƒƒ}d|_tjt|ƒƒ| _| jrR| jrR| j| _d| _dS W nx tj	k
rj   dS  tj
k
rÌ   tj| j jƒ}| jrÂt|ƒrž|| _qÈtƒ rÈt|ƒrÈtd|j|jf ƒ‚n|| _Y nX dS )zªFind an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.
        NFTzVWill not install to the user site because it will lack sys.path precedence to %s in %s)rK   r   r“   r]   r   Úget_distributionr_   rW   r`   ÚDistributionNotFoundÚVersionConflictrx   rg   r"   r   r#   r   r
  r”   )rm   Ú	no_markerÚexisting_distr?   r?   r@   r  ó  s2    

z"InstallRequirement.check_if_existsc             C   s   | j o| j jS )N)rY   r‹   )rm   r?   r?   r@   r‹     s    zInstallRequirement.is_wheelc             C   s*   t | j| j|| j| j||| j| jd�	 d S )N)ÚuserÚhomerß   r  rj   rl   )r4   rx   rK   rg   rh   rj   rl   )rm   Úwheeldirrß   r  r?   r?   r@   r4      s    
z#InstallRequirement.move_wheel_filesc             C   sX   | j dƒjdƒ}tjj|ƒ}tj||ƒ}tjjtjj|ƒƒd }tj	tjj|ƒ||d�S )zAReturn a pkg_resources.Distribution built from self.egg_info_pathrº   r;  r   )r
  Úmetadata)
rÖ   ÚrstriprN   r;   r  r   ÚPathMetadataÚsplitextÚbasenameÚDistribution)rm   rÅ   Úbase_dirr{  Ú	dist_namer?   r?   r@   Úget_dist+  s    
zInstallRequirement.get_distc             C   s   t | jjdi ƒƒS )z©Return whether any known-good hashes are specified as options.

        These activate --require-hashes mode; hashes specified as part of a
        URL do not.

        Úhashes)Úboolri   r]  )rm   r?   r?   r@   Úhas_hash_options6  s    z#InstallRequirement.has_hash_optionsc             C   sJ   | j jdi ƒjƒ }|r| jn| j}|rB|jrB|j|jg ƒj|jƒ t	|ƒS )a§  Return a hash-comparer that considers my option- and URL-based
        hashes to be known-good.

        Hashes in URLs--ones embedded in the requirements file, not ones
        downloaded from an index server--are almost peers with ones from
        flags. They satisfy --require-hashes (whether it was implicitly or
        explicitly activated) but do not activate it. md5 and sha224 are not
        allowed in flags, which should nudge people toward good algos. We
        always OR all hashes together, even ones from URLs.

        :param trust_internet: Whether to trust URL-based (#md5=...) hashes
            downloaded from the internet, as by populate_link()

        r„  )
ri   r]  ÚcopyrY   rZ   ÚhashÚ
setdefaultÚ	hash_namer_  r-   )rm   Útrust_internetÚgood_hashesrY   r?   r?   r@   r„  @  s
    
zInstallRequirement.hashes)NFNFTTNFNNF)NNFNNF)NFNNF)T)F)N)NN)T).r™   Ú
__module__Ú__qualname__rp   Úclassmethodr|   r’   r—   rš   r¢   Úpropertyr£   rª   r•   r²   r¸   rx   r¼   rÄ   rÓ   rØ   rÖ   rÌ   r8   ÚcompileÚ_requirements_section_rerö   r÷   rÿ   r0  r3  r5  rO  rB  rS  ri  rk  r^  rp  rZ  r  r‹   r4   rƒ  r†  r„  r?   r?   r?   r@   rH   I   sb      
;   M
 :6


 $0
W)

rH   c             C   s   t jd| ƒ}|r|jdƒ} | S )z2
        Strip req postfix ( -dev, 0.2, etc )
    z^(.*?)(?:-dev|-\d.*)$r6   )r8   rŠ   r:   )rK   r9   r?   r?   r@   Ú_strip_postfixV  s    
r“  c             C   s˜  ddl m} | }d}tjd|ƒ}|r:|jdƒ}|jdƒ}n|}tjj|ƒrttjjtjj	|dƒƒslt
d| ƒ‚t|ƒ}|jƒ jd	ƒr²||ƒj}|r¨||td
|jƒ  ƒjfS ||dfS x,tD ]$}|jƒ jd| ƒr¸d||f }P q¸W d|k�r|�r
tjdtƒ |d | }nt
d|  ƒ‚|jddƒd jƒ }	tj|	ƒ�s`d|  dj	dd„ tjD ƒƒ d }
t
|
ƒ‚||ƒj}|�sxt
dƒ‚|�sŠt
d|  ƒ‚t|ƒ|dfS )a   Parses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    r   )rq   Nz^(.+)(\[[^\]]+\])$r6   r7   zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:r€   z%s:z%s+%srø   zD--default-vcs has been deprecated and will be removed in the future.zb%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+zFor --editable=%s only z, c             S   s   g | ]}|j d  ‘qS )z+URL)rx   )rC   rý   r?   r?   r@   rà   ¦  s    z"parse_editable.<locals>.<listcomp>z is currently supportedz@Could not detect requirement name, please specify one with #egg=z@--editable=%s is not the right format; it must have #egg=Package)rr   rq   r8   r9   r:   rN   r;   r…   r¯   r°   r   r   r®   rt   rŽ   r   r=   r3   r  r  r.   r�   rù   Úbackendsr“  )rv   rw   rq   ry   r=   r<   Úurl_no_extrasÚpackage_nameÚversion_controlrü   Úerror_messager?   r?   r@   rs   b  s`    





rs   )N)dÚ
__future__r   ÚloggingrN   r8   r´   rÂ   r¬   rR   r  r?  Ú	distutilsr   Údistutils.utilr   Úemail.parserr   Úpip._vendorr   r   Zpip._vendor.packagingr   Úpip._vendor.packaging.markersr	   Ú"pip._vendor.packaging.requirementsr
   r   Úpip._vendor.packaging.utilsr   Zpip._vendor.packaging.versionr   r   rË   Zpip._vendor.six.movesr   Ú	pip.wheelr  Ú
pip.compatr   r   r   Úpip.downloadr   r   r   r   Úpip.exceptionsr   r   Úpip.locationsr   r   r   r   Ú	pip.utilsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   Úpip.utils.hashesr-   Zpip.utils.deprecationr.   Úpip.utils.loggingr/   Úpip.utils.setuptools_buildr0   Úpip.utils.uir1   Úpip.req.req_uninstallr2   Úpip.vcsr3   r4   r5   Ú	getLoggerr™   r‡   Ú	SpecifierÚ
_operatorsÚkeysrQ   rA   rG   ÚobjectrH   r“  rs   r?   r?   r?   r@   Ú<module>   s`   H
        