B
    =)H[š«  ã               @   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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 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( d dl)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZH d dlImJZJ d dlKmLZL d dlMmNZN d dlOmPZP d dlQmRZRmSZS e TeU¡ZVejWjX Y¡ ZZdd„ Z[G dd „ d e\ƒZ]d!d"„ Z^d#d$„ Z_d%d&„ Z`dS )'é    )Úabsolute_importN)Úchange_root)Ú
FeedParser)Úpkg_resourcesÚpytomlÚsix)Ú
specifiers)ÚMarker)ÚInvalidRequirementÚRequirement)Úcanonicalize_name)Úparse)ÚVersion)ÚRequirementParseErrorÚparse_requirements)Úwheel)ÚBuildEnvironment)Ú
native_str)Úis_archive_fileÚis_urlÚpath_to_urlÚurl_to_path)ÚInstallationErrorÚUninstallationError)ÚPIP_DELETE_MARKER_FILENAMEÚrunning_under_virtualenv)ÚUninstallPathSet)ÚRemovedInPip11Warning)ÚHashes)Ú
indent_log)Ú_make_build_dirÚask_path_existsÚ
backup_dirÚcall_subprocessÚdisplay_pathÚdist_in_site_packagesÚdist_in_usersiteÚ
ensure_dirÚget_installed_versionÚis_installable_dirÚread_text_fileÚrmtree)ÚSETUPTOOLS_SHIM)ÚTempDirectory)Úopen_spinner)Úvcs)ÚWheelÚmove_wheel_filesc             C   s6   t  d| ¡}d }|r*| d¡}| d¡}n| }||fS )Nz^(.+)(\[[^\]]+\])$é   é   )ÚreÚmatchÚgroup)ÚpathÚmÚextrasÚpath_no_extras© r;   ú^C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_internal\req\req_install.pyÚ_strip_extras6   s    
r=   c            
   @   s˜  e Zd ZdZdUdd„ZedVdd	„ƒZedWd
d„ƒZedXd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ed$d%„ ƒZd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Ze d0¡Zed1d2„ ƒZd3d4„ ZdYd5d6„Z dZd7d8„Z!d9d:„ Z"d;d<„ Z#d[d=d>„Z$d\d?d@„Z%dAdB„ Z&dCdD„ Z'dEdF„ Z(d]dGdH„Z)dIdJ„ Z*edKdL„ ƒZ+d^dMdN„Z,dOdP„ Z-edQdR„ ƒZ.d_dSdT„Z/dS )`ÚInstallRequirementzÆ
    Represents something that may be installed later on, may have information
    about where to fetch the relavant requirement and also contains logic for
    installing the said requirement.
    NFTr;   c             C   sL  |d kst |tƒst|ƒ‚|| _|| _|| _|d k	rLtj tj 	|¡¡| _
nd | _
|| _|
| _|d k	rt| | _| _n(ddlm} |o’|jo’||jƒ | _| _|r¨|| _n |rÀdd„ |jD ƒ| _ntƒ | _|d k	rØ|| _n|oà|j| _d | _d | _d | _tdd�| _d | _|| _d | _d | _|	�r$|	ni | _d| _ d| _!|| _"t#dd	�| _$d S )
Nr   )ÚLinkc             S   s   h | ]}t  |¡’qS r;   )r   Ú
safe_extra)Ú.0Úextrar;   r;   r<   ú	<setcomp>a   s   z.InstallRequirement.__init__.<locals>.<setcomp>z	req-build)ÚkindFT)Úno_clean)%Ú
isinstancer   ÚAssertionErrorÚreqÚ
comes_fromÚ
constraintÚosr7   ÚnormpathÚabspathÚ
source_dirÚeditableÚ_wheel_cacheÚlinkÚoriginal_linkÚpip._internal.indexr?   Úurlr9   ÚsetÚmarkersÚmarkerÚ_egg_info_pathÚsatisfied_byÚconflicts_withr-   Ú_temp_build_dirÚ_ideal_build_dirÚupdateÚinstall_succeededÚuninstalled_pathsetÚoptionsÚpreparedÚ	is_directÚisolatedr   Ú	build_env)ÚselfrH   rI   rN   rO   rQ   r]   rV   rc   r`   Úwheel_cacherJ   r9   r?   r;   r;   r<   Ú__init__I   sF    zInstallRequirement.__init__c             C   sš   ddl m} t|ƒ\}}	}
|	 d¡r.t|	ƒ}nd }|d k	rjyt|ƒ}W qn tk
rf   td| ƒ‚Y qnX nd }| |||d||	ƒ|||rŠ|ni ||
p”dd�
S )Nr   )r?   zfile:zInvalid requirement: '%s'Tr;   )rN   rO   rQ   rJ   rc   r`   rf   r9   )rS   r?   Úparse_editableÚ
startswithr   r   r
   r   )ÚclsÚeditable_reqrI   rc   r`   rf   rJ   r?   ÚnamerT   Úextras_overriderN   rH   r;   r;   r<   Úfrom_editable„   s(    


z InstallRequirement.from_editablec             C   sP   yt |ƒ}W n  tk
r,   td| ƒ‚Y nX |jr@td| ƒ‚| ||||d�S )NzInvalid requirement: '%s'zADirect url requirement (like %s) are not allowed for dependencies)rc   rf   )r   r
   r   rT   )rj   rH   rI   rc   rf   r;   r;   r<   Úfrom_req¡   s    zInstallRequirement.from_reqc                sl  ddl m} t|ƒrd}nd}||krR| |d¡\}}	|	 ¡ }	|	sHd}	qVt|	ƒ}	nd}	| ¡ }d‰ tj tj 	|¡¡}
d}d}t|ƒr�||ƒ}nœt
|
ƒ\}}tj |¡oÔtjj|kpÔtjjdk	rÌtjj|kpÔ| d¡}|rüt|ƒsîtd| ƒ‚|t|ƒƒ}n0t|ƒ�r,tj |¡�s t d	|¡ |t|ƒƒ}|�r˜|jd
k�rlt d|j¡�rl|ttj tj 	|j¡¡ƒƒ}|j�r�t|jƒ}d|j|jf ‰ n|j‰ n|‰ |�r¶t d| !¡  ƒj"}nd}ˆ dk	�rHyt ˆ ƒ‰ W nv t#k
�rF   tjjˆ k�rd}|t$ˆ ƒ7 }n0dˆ k�r*t%‡ fdd„t&D ƒƒ�s*d}nt' (¡ }tdˆ |f ƒ‚Y nX | ˆ |||	||�r^|ni |||d�	S )zŒCreates an InstallRequirement from a name, which might be a
        requirement, directory containing 'setup.py', filename, or URL.
        r   )r?   z; ú;r2   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Úplaceholderr;   zIt looks like a path.ú=c             3   s   | ]}|ˆ kV  qd S )Nr;   )rA   Úop)rH   r;   r<   ú	<genexpr>  s    z/InstallRequirement.from_line.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s'
%s)rQ   rV   rc   r`   rf   rJ   r9   ))rS   r?   r   ÚsplitÚstripr	   rK   r7   rL   rM   r=   ÚisdirÚsepÚaltsepri   r)   r   r   r   ÚisfileÚloggerÚwarningÚschemer4   ÚsearchrT   Úis_wheelr0   Úfilenamerl   ÚversionÚegg_fragmentr   Úlowerr9   r
   Údeduce_helpful_msgÚanyÚ	operatorsÚ	tracebackÚ
format_exc)rj   rl   rI   rc   r`   rf   rJ   r?   Ú
marker_seprV   r7   rQ   r9   ÚpÚlooks_like_dirr   Úadd_msgr;   )rH   r<   Ú	from_line®   s„    





"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 ¡ }|rŽ|d| 7 }|S )Nz from %sz in %sz
 (from %s))rH   ÚstrrQ   rT   rY   r$   ÚlocationrI   rF   r   Ústring_typesÚ	from_path)re   ÚsrI   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�   rO   )re   r;   r;   r<   Ú__repr__"  s    zInstallRequirement.__repr__c             C   s\   | j dkr| | |¡| _ | jdk	rX|sX| j }| j | j | j¡| _ || j krXt 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)rQ   Úfind_requirementrP   Úgetrl   r}   Údebug)re   ÚfinderÚupgradeÚrequire_hashesÚold_linkr;   r;   r<   Úpopulate_link&  s    

z InstallRequirement.populate_linkc             C   s   | j jS )N)rH   Ú	specifier)re   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.
        r2   >   ú===ú==)r¡   ÚlenÚnextÚiterÚoperator)re   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 ¡ }|rN|d| 7 }|S )Nz->)rH   r�   rI   rF   r   r’   r“   )re   r”   rI   r;   r;   r<   r“   H  s    


zInstallRequirement.from_pathc             C   sˆ   |d k	st ‚| jjd k	r | jjS | jd krB| j ¡  || _| jjS | jrT| j ¡ }n| j}t	j 
|¡szt d|¡ t|ƒ t	j ||¡S )NzCreating directory %s)rG   r[   r7   rH   Úcreater\   rO   rl   r…   rK   Úexistsr}   r›   r    Újoin)re   Ú	build_dirrl   r;   r;   r<   Úbuild_locationU  s    

z!InstallRequirement.build_locationc             C   s¾   | j dk	rdS | jdk	st‚| jjs(t‚| jjs4t‚| jj}d| j_|  | j¡}tj |¡rlt	dt
|ƒ ƒ‚t d| t
|ƒt
|ƒ¡ t ||¡ || j_d| _tj tj |¡¡| _ 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)rN   rH   rG   r[   r7   r\   r­   rK   rª   r   r$   r}   r›   ÚshutilÚmoverL   rM   rX   )re   Úold_locationÚnew_locationr;   r;   r<   Ú_correct_build_locationp  s(    

z*InstallRequirement._correct_build_locationc             C   s    | j d krd S tt | j j¡ƒS )N)rH   r   r   Ú	safe_namerl   )re   r;   r;   r<   rl   ‘  s    
zInstallRequirement.namec             C   s   t j | j| jr| jjpd¡S )NÚ )rK   r7   r«   rN   rQ   Úsubdirectory_fragment)re   r;   r;   r<   Úsetup_py_dir—  s    zInstallRequirement.setup_py_dirc             C   sF   | j std|  ƒ‚tj | jd¡}tjrBt|tj	ƒrB| 
t ¡ ¡}|S )NzNo source dir for %szsetup.py)rN   rG   rK   r7   r«   r¶   r   ÚPY2rF   Ú	text_typeÚencodeÚsysÚgetfilesystemencoding)re   Úsetup_pyr;   r;   r<   r¼   �  s
    zInstallRequirement.setup_pyc             C   sF   | j std|  ƒ‚tj | jd¡}tjrBt|tj	ƒrB| 
t ¡ ¡}|S )NzNo source dir for %szpyproject.toml)rN   rG   rK   r7   r«   r¶   r   r·   rF   r¸   r¹   rº   r»   )re   Úpp_tomlr;   r;   r<   Úpyproject_toml©  s
    z!InstallRequirement.pyproject_tomlc          	   C   sZ   t j | j¡rNt| jƒ�}t |¡}W dQ R X | di ¡}| dddg¡dfS ddgdfS )a�  Get a list of the packages required to build the project, if any,
        and a flag indicating whether pyproject.toml is present, indicating
        that the build should be isolated.

        Build requirements can be specified in a pyproject.toml, as described
        in PEP 518. If this file exists but doesn't specify build
        requirements, pip will default to installing setuptools and wheel.
        Nzbuild-systemÚrequiresÚ
setuptoolsr   TF)rK   r7   r|   r¾   Úopenr   Úloadrš   )re   Úfr½   Ú	build_sysr;   r;   r<   Úget_pep_518_infoµ  s    	z#InstallRequirement.get_pep_518_infoc          
   C   sl  | j s
t‚| jr$t d| j| j¡ nt d| j| j¡ tƒ �Š t| j }t	j
d|g}| jrd|dg7 }|dg }| jrzg }n tj | jd¡}t|ƒ ddg}| j� t|| | jdd	d
� W d Q R X W d Q R X | j�s$tt|  ¡ d ƒtƒrðd}nd}td |  ¡ d ||  ¡ d g¡ƒ| _|  ¡  nDt|  ¡ d ƒ}t| jjƒ|k�rht 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.)rN   rG   rl   r}   r›   r¼   rQ   r   r,   rº   Ú
executablerc   rO   rK   r7   r«   r¶   r'   rd   r#   rH   rF   Úparse_versionÚpkg_infor   r   r²   r   r~   )re   ÚscriptÚbase_cmdÚegg_info_cmdÚegg_base_optionÚegg_info_dirru   Úmetadata_namer;   r;   r<   Úrun_egg_infoÅ  sR    





zInstallRequirement.run_egg_infoc             C   sV   | j d k	r&| j  |¡sd S | j  |¡S | js0t‚|  |¡}tj |¡sJd S t	|ƒ}|S )N)
rY   Úhas_metadataÚget_metadatarN   rG   Úegg_info_pathrK   r7   rª   r*   )re   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d¡}t |¡}| j�rg }x¾t |¡D ]°\‰ }}x t	j
D ]}||kr^| |¡ q^W xjt|ƒD ]^}tj tj ˆ |dd¡¡sºtj tj ˆ |dd¡¡rÆ| |¡ q‚|dksÖ|dkr‚| |¡ q‚W | ‡ 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 ||d ¡| _ tj | j |¡S )Nzpip-egg-infoÚbinÚpythonÚScriptsz
Python.exeÚtestÚtestsc                s   g | ]}t j ˆ |¡‘qS r;   )rK   r7   r«   )rA   Údir)Úrootr;   r<   ú
<listcomp>,  s   z4InstallRequirement.egg_info_path.<locals>.<listcomp>c             S   s   g | ]}|  d ¡r|‘qS )z	.egg-info)Úendswith)rA   rÃ   r;   r;   r<   rá   .  s    z$No files/directories in %s (from %s)r2   c             S   s(   |   tjj¡tjjr"|   tjj¡p$d S )Nr   )ÚcountrK   r7   rz   r{   )Úxr;   r;   r<   Ú<lambda><  s   z2InstallRequirement.egg_info_path.<locals>.<lambda>)Úkeyr   )rX   rO   rN   rK   r7   r«   r¶   ÚlistdirÚwalkr/   ÚdirnamesÚremoveÚlistÚlexistsrª   Úextendr   rG   r¤   Úsort)re   r‚   ÚbaseÚ	filenamesÚdirsÚfilesrß   r;   )rà   r<   r×     sB    
z InstallRequirement.egg_info_pathc             C   s@   t ƒ }|  d¡}|s*t dt|  d¡ƒ¡ | |p4d¡ | ¡ S )NzPKG-INFOzNo PKG-INFO file found in %sr´   )r   rÙ   r}   r~   r$   r×   ÚfeedÚclose)re   rŒ   rØ   r;   r;   r<   rÍ   B  s    
zInstallRequirement.pkg_infoz	\[(.*?)\]c             C   s
   t | jƒS )N)r(   rl   )re   r;   r;   r<   Úinstalled_versionO  s    z$InstallRequirement.installed_versionc             C   sT   | j s
t‚|  ¡ d }| jjr:|| jjkr:t d| |¡ nt dt| j ƒ|| ¡ d S )Nrƒ   z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)	rN   rG   rÍ   rH   r¡   r}   r~   r›   r$   )re   rƒ   r;   r;   r<   Úassert_source_matches_versionS  s    
z0InstallRequirement.assert_source_matches_versionc             C   sÊ   | j st 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 	dd¡\}}t
 |¡}|r°|| j jƒ}|r¢| | j¡ qÆ| | j¡ ndsÆtd| j |f ƒ‚d S )Nz>Cannot update repository at %s; repository location is unknownrr   ú+zbad url: %rr2   r   z+Unexpected version control type (in %s): %s)rQ   r}   r›   rN   rO   rG   r   rT   r]   rw   r/   Úget_backendÚobtainÚexport)re   rù   Úvc_typerT   ÚbackendÚvcs_backendr;   r;   r<   Úupdate_editabled  s,    


z"InstallRequirement.update_editablec             C   sB   |   |¡st d| j¡ dS | jp&| j}t |¡}| ||¡ |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#Skipping %s as it is not installed.N)	Úcheck_if_existsr}   r~   rl   rY   rZ   r   Ú	from_distrê   )re   Úauto_confirmÚverboseÚuse_user_siteÚdistr_   r;   r;   r<   Ú	uninstall�  s    

zInstallRequirement.uninstallc             C   sæ  | j s
t‚d}d| j|  ¡ d f }tj ||¡}tj |¡rÈtdt	|ƒ dƒ}|dkr^d}nj|dkr‚t
 d	t	|ƒ¡ t |¡ nF|d
kr¶t|ƒ}t
 dt	|ƒt	|ƒ¡ t ||¡ n|dkrÈt d¡ |�râtj|dtjdd�}tj tj | j¡¡}xÐt |¡D ]Â\}	}
}d|
k�r"|
 d¡ xR|
D ]J}tj |	|¡}|  ||¡}t | jd | d ¡}d|_| |d¡ �q(W xL|D ]D}|tk�rŽ�q|tj |	|¡}|  ||¡}| || jd | ¡ �q|W �qW | ¡  t
  dt	|ƒ¡ d S )NTz	%s-%s.ziprƒ   z8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort )ÚiÚwÚbÚar  Fr  zDeleting %sr  zBacking up %s to %sr	  éÿÿÿÿ)Ú
allowZip64zpip-egg-infoú/i  ír´   zSaved %s)!rN   rG   rl   rÍ   rK   r7   r«   rª   r!   r$   r}   r~   rê   r"   r®   r¯   rº   ÚexitÚzipfileÚZipFileÚZIP_DEFLATEDÚnormcaserM   r¶   rè   Ú_clean_zip_nameÚZipInfoÚexternal_attrÚwritestrr   Úwriterô   Úinfo)re   r¬   Úcreate_archiveÚarchive_nameÚarchive_pathÚresponseÚ	dest_fileÚziprß   Údirpathré   rð   Údirnamerl   Úzipdirr‚   r;   r;   r<   Úarchive˜  sX    







"zInstallRequirement.archivec             C   sJ   |  |tjj ¡s"td||f ƒ‚|t|ƒd d … }| tjjd¡}|S )Nz$name %r doesn't start with prefix %rr2   r  )ri   rK   r7   rz   rG   r¤   Úreplace)re   rl   Úprefixr;   r;   r<   r  È  s
    z"InstallRequirement._clean_zip_namec                s0   |sd}ˆ j d k	r(t‡ fdd„|D ƒƒS dS d S )N)r´   c             3   s   | ]}ˆ j  d |i¡V  qdS )rB   N)rV   Úevaluate)rA   rB   )re   r;   r<   rv   ×  s   z3InstallRequirement.match_markers.<locals>.<genexpr>T)rV   r‡   )re   Úextras_requestedr;   )re   r<   Úmatch_markersÐ  s    


z InstallRequirement.match_markersc	                sr  |d k	r|ng }| j r*| j|||d� d S | jrnt | j¡}	t |	| j¡ | j| jˆ |||||d� d| _	d S t
|ƒ| j dg ¡ }t
|ƒ| j dg ¡ }| jrª|dg }tdd���²}
tj |
jd	¡}|  ||ˆ ||¡}d
| jf }t|ƒ�@}tƒ �. | j� t|| | jd|d� W d Q R X W d Q R X W d Q R X tj |¡�sRt d|¡ d S d| _	‡ fdd„}t|ƒ�H}x@|D ](}tj |¡}| d¡�rt||ƒ}P �qtW t d| ¡ d S W d Q R X g }t|ƒ�P}xH|D ]@}| ¡ }tj  |¡�rô|tjj!7 }| "tj #||ƒ|¡¡ �qÎW W d Q R X | $¡  t%|ƒ tj |d¡}t|dƒ�}| &d |¡d ¡ W d Q R X W d Q R X d S )N)r#  )rà   r#  ÚhomeÚwarn_script_locationr  Ú	pycompileTÚglobal_optionsÚinstall_optionsz--no-user-cfgÚrecord)rD   zinstall-record.txtzRunning setup.py install for %sF)rÇ   rÈ   ÚspinnerzRecord file %s not foundc                s&   ˆ d kst j | ¡s| S tˆ | ƒS d S )N)rK   r7   Úisabsr   )r7   )rà   r;   r<   Úprepend_root  s    z0InstallRequirement.install.<locals>.prepend_rootz	.egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr  Ú
)'rO   Úinstall_editabler�   r   Úwheel_versionrN   Úcheck_compatibilityrl   r1   r^   rë   r`   rš   rc   r-   rK   r7   r«   Úget_install_argsr.   r   rd   r#   r¶   rª   r}   r›   rÁ   r  râ   r~   rx   ry   rz   ÚappendÚrelpathrî   r'   r  )re   r+  r*  rà   r'  r#  r(  r  r)  rƒ   Útemp_dirÚrecord_filenameÚinstall_argsÚmsgr-  r/  rÃ   ÚlineÚ	directoryrÒ   Ú	new_linesr‚   Úinst_files_pathr;   )rà   r<   ÚinstallÜ  sz    



&



$zInstallRequirement.installc             C   s   | j dkr|  |¡| _ | 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)rN   r­   )re   Ú
parent_dirr;   r;   r<   Úensure_has_source_dir7  s    

z(InstallRequirement.ensure_has_source_dirc          	   C   s¼   t jdg}| d¡ | t| j ¡ |t|ƒdd|g 7 }|dg7 }|d k	rX|d|g7 }|d k	rl|d|g7 }|r||dg7 }n
|d	g7 }tƒ r¸d
t ¡  }|dt	j
 t jdd|| j¡g7 }|S )Nz-uz-cr?  z--recordz#--single-version-externally-managedz--rootz--prefixz	--compilez--no-compilerÛ   z--install-headersÚincludeÚsite)rº   rË   r5  r,   r¼   rë   r   Ú	sysconfigÚget_python_versionrK   r7   r«   r#  rl   )re   r*  r8  rà   r#  r)  r9  Ú
py_ver_strr;   r;   r<   r4  E  s&    



z#InstallRequirement.get_install_argsc             C   sT   | j r6tj tj | j t¡¡r6t d| j ¡ t| j ƒ d| _ | j	 
¡  | j 
¡  dS )zVRemove the source files from this requirement, if they are marked
        for deletionzRemoving source in %sN)rN   rK   r7   rª   r«   r   r}   r›   r+   r[   Úcleanuprd   )re   r;   r;   r<   Úremove_temporary_source`  s    

z*InstallRequirement.remove_temporary_sourcec          
   C   s¢   t  d| j¡ | jr"t|ƒdg }|r>d |¡g}t|ƒ| }tƒ �N | j�< tt	j
dt| j gt|ƒ ddg t|ƒ | jdd� W d Q R X W d Q R X d	| _d S )
NzRunning setup.py develop for %sz--no-user-cfgz--prefix={}z-cÚdevelopz	--no-depsF)rÇ   rÈ   T)r}   r  rl   rc   rë   Úformatr   rd   r#   rº   rË   r,   r¼   r¶   r^   )re   r+  r*  r#  Úprefix_paramr;   r;   r<   r1  k  s     z#InstallRequirement.install_editablec             C   sÐ   | j dkrdS yFtt| j ƒƒ}d|_t t|ƒ¡| _| jrR| jrR| j| _d| _dS W nv tj	k
rj   dS  tj
k
rÊ   t | 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)rH   r   r�   rW   r   Úget_distributionrY   rO   rZ   ÚDistributionNotFoundÚVersionConflictrl   r&   r   r%   r   Úproject_namer‘   )re   r  Ú	no_markerÚexisting_distr;   r;   r<   rÿ   ‰  s2    

z"InstallRequirement.check_if_existsc             C   s   | j o| j jS )N)rQ   r�   )re   r;   r;   r<   r�   ²  s    zInstallRequirement.is_wheelc             C   s&   t | j| j||||||| j|d�
 d S )N)Úuserr'  rà   r#  r)  rc   r(  )r1   rl   rH   rc   )re   Úwheeldirrà   r'  r#  r(  r  r)  r;   r;   r<   r1   ¶  s    
z#InstallRequirement.move_wheel_filesc             C   s\   |   d¡ tjj¡}tj |¡}t ||¡}tj tj 	|¡¡d }tj
tj |¡||d�S )zAReturn a pkg_resources.Distribution built from self.egg_info_pathr´   r   )rO  Úmetadata)r×   ÚrstriprK   r7   rz   r  r   ÚPathMetadataÚsplitextÚbasenameÚDistribution)re   rÆ   Úbase_dirrT  Ú	dist_namer;   r;   r<   Úget_distÄ  s    
zInstallRequirement.get_distc             C   s   t | 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)Úboolr`   rš   )re   r;   r;   r<   Úhas_hash_optionsÐ  s    z#InstallRequirement.has_hash_optionsc             C   sJ   | j  di ¡ ¡ }|r| jn| j}|rB|jrB| |jg ¡ |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]  )
r`   rš   ÚcopyrQ   rR   ÚhashÚ
setdefaultÚ	hash_namer5  r   )re   Útrust_internetÚgood_hashesrQ   r;   r;   r<   r]  Ú  s
    
zInstallRequirement.hashes)
NFNTNFNNFr;   )NFNNF)NFN)NFNNF)T)FFF)N)NNNNTFT)r;   N)NNNTFT)T)0r—   Ú
__module__Ú__qualname__Ú__doc__rg   Úclassmethodrn   ro   r�   r•   r˜   r    Úpropertyr¡   r¨   r“   r­   r²   rl   r¶   r¼   r¾   rÅ   rÔ   rÙ   r×   rÍ   r4   ÚcompileÚ_requirements_section_rerõ   rö   rþ   r  r!  r  r&  r?  rA  r4  rH  r1  rÿ   r�   r1   r\  r_  r]  r;   r;   r;   r<   r>   B   sl      
8  _
!;6

 
0
  
Y
)  

r>   c             C   s*   t  d| ¡}|r&t dt¡ | d¡} | S )z2
        Strip req postfix ( -dev, 0.2, etc )
    z^(.*?)(?:-dev|-\d.*)$z<#egg cleanup for editable urls will be dropped in the futurer2   )r4   r€   ÚwarningsÚwarnr   r6   )rH   r5   r;   r;   r<   Ú_strip_postfixð  s    
ro  c       	      C   sF  ddl m} | }t|ƒ\}}tj |¡rRtj tj |d¡¡sJtd| ƒ‚t	|ƒ}| 
¡  d¡r�||ƒj}|r†||td| 
¡  ƒjfS ||dfS x,tD ]$}| 
¡  d| ¡r–d	||f }P q–W d
|krÒtd|  ƒ‚| d
d¡d  
¡ }t |¡�sd|  d dd„ tjD ƒ¡ d }t|ƒ‚||ƒj}|�s8t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   )r?   zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:rs   Nz%s:z%s+%sr÷   zb%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+r2   zFor --editable=%s only z, c             S   s   g | ]}|j d  ‘qS )z+URL)rl   )rA   rü   r;   r;   r<   rá   6  s    z"parse_editable.<locals>.<listcomp>z is currently supportedzZCould not detect requirement name for '%s', please specify one with #egg=your_package_name)rS   r?   r=   rK   r7   ry   rª   r«   r   r   r…   ri   r„   r   r9   r/   rw   rø   Úbackendsro  )	rk   r?   rT   Úurl_no_extrasr9   Úpackage_nameÚversion_controlrû   Úerror_messager;   r;   r<   rh      sF    



rh   c          	   C   s”   d}t j | ¡r„d}yFt| dƒ�2}tt| ¡ ƒƒ |dd|   d d d 7 }W d	Q R X W q� tk
r€   tj	d
|  dd� Y q�X n|d|  7 }|S )z„Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    r´   z It does exist.Úrz The argument you provided z(%s) appears to be az" requirements file. If that is thez# case, use the '-r' flag to installz" the packages specified within it.Nz2Cannot parse '%s' as requirements             filer2   )Úexc_infoz File '%s' does not exist.)
rK   r7   rª   rÁ   r¥   r   Úreadr   r}   r›   )rH   r:  Úfpr;   r;   r<   r†   C  s    r†   )aÚ
__future__r   ÚloggingrK   r4   r®   rº   rD  r‰   rm  r  Údistutils.utilr   Úemail.parserr   Úpip._vendorr   r   r   Úpip._vendor.packagingr   Zpip._vendor.packaging.markersr	   Z"pip._vendor.packaging.requirementsr
   r   Úpip._vendor.packaging.utilsr   Zpip._vendor.packaging.versionr   rÌ   r   Zpip._vendor.pkg_resourcesr   r   Úpip._internalr   Úpip._internal.build_envr   Úpip._internal.compatr   Úpip._internal.downloadr   r   r   r   Úpip._internal.exceptionsr   r   Úpip._internal.locationsr   r   Úpip._internal.req.req_uninstallr   Úpip._internal.utils.deprecationr   Úpip._internal.utils.hashesr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   Ú$pip._internal.utils.setuptools_buildr,   Úpip._internal.utils.temp_dirr-   Úpip._internal.utils.uir.   Úpip._internal.vcsr/   Úpip._internal.wheelr0   r1   Ú	getLoggerr—   r}   Ú	SpecifierÚ
_operatorsÚkeysrˆ   r=   Úobjectr>   ro  rh   r†   r;   r;   r;   r<   Ú<module>   sb   8
       5C