B
    =)H[ˆ<  ã               @   sZ  d 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mZ ddl	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mZ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$ ddl%m&Z& ddl'm(Z( e )e*¡Z+dd„ Z,dd„ Z-G dd„ de.ƒZ/G dd„ de/ƒZ0G dd„ de/ƒZ1G dd„ de/ƒZ2G dd„ de.ƒZ3dS )z)Prepares a distribution for installation
é    N)Úcopy)Úpkg_resourcesÚrequests)ÚNoOpBuildEnvironment)Ú
expanduser)Ú
is_dir_urlÚis_file_urlÚ
is_vcs_urlÚ
unpack_urlÚurl_to_path)ÚDirectoryUrlHashUnsupportedÚHashUnpinnedÚInstallationErrorÚPreviousBuildDirErrorÚVcsHashUnsupported)ÚFormatControl)ÚInstallRequirement)ÚMissingHashes)Ú
indent_log)Úcall_subprocessÚdisplay_pathÚnormalize_path)Úopen_spinner)Úvcsc             C   s0   | j rt| ƒS | jr$| jjr$t| ƒS t| ƒS dS )zãFactory to make an abstract dist object.

    Preconditions: Either an editable req with a source_dir, or satisfied_by or
    a wheel link, or a non-editable req with a source_dir.

    :return: A concrete DistAbstraction.
    N)ÚeditableÚIsSDistÚlinkÚis_wheelÚIsWheel)Úreq© r    úaC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_internal\operations\prepare.pyÚmake_abstract_dist"   s
    r"   c          	      sr   t ˆ ƒ‰ ttƒ tdgƒƒˆ _‡ fdd„|D ƒ}tjdddddd	|gt|ƒ }td
ƒ�}t|d|d� W d Q R X d S )Nz:all:c                s"   g | ]}ˆ j t |¡d d�j‘qS )F)Úupgrade)Úfind_requirementr   Ú	from_lineÚurl)Ú.0Úr)Úfinderr    r!   ú
<listcomp>9   s   z'_install_build_reqs.<locals>.<listcomp>z-mÚpipÚinstallz--ignore-installedz	--no-userz--prefixzInstalling build dependenciesF)Úshow_stdoutÚspinner)	r   r   ÚsetÚformat_controlÚsysÚ
executableÚlistr   r   )r)   ÚprefixÚbuild_requirementsÚurlsÚargsr.   r    )r)   r!   Ú_install_build_reqs2   s    


r8   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚDistAbstractionay  Abstracts out the wheel vs non-wheel Resolver.resolve() logic.

    The requirements for anything installable are as follows:
     - we must be able to determine the requirement name
       (or we can't correctly handle the non-upgrade case).
     - we must be able to generate a list of run-time dependencies
       without installing any additional packages (or we would
       have to either burn time by doing temporary isolated installs
       or alternatively violate pips 'don't start installing unless
       all requirements are available' rule - neither of which are
       desirable).
     - for packages with setup requirements, we must also be able
       to determine their requirements without installing additional
       packages (for the same reason as run-time dependencies)
     - we must be able to create a Distribution object exposing the
       above metadata.
    c             C   s
   || _ d S )N)r   )Úselfr   r    r    r!   Ú__init__Y   s    zDistAbstraction.__init__c             C   s   t | jƒ‚dS )z Return a setuptools Dist object.N)ÚNotImplementedErrorÚdist)r:   r)   r    r    r!   r=   \   s    zDistAbstraction.distc             C   s   t | jƒ‚dS )z3Ensure that we can get a Dist for this requirement.N)r<   r=   )r:   r)   r    r    r!   Úprep_for_dist`   s    zDistAbstraction.prep_for_distN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r;   r=   r>   r    r    r    r!   r9   F   s   r9   c               @   s   e Zd Zdd„ Zdd„ ZdS )r   c             C   s   t t | jj¡ƒd S )Nr   )r3   r   Úfind_distributionsr   Ú
source_dir)r:   r)   r    r    r!   r=   g   s    zIsWheel.distc             C   s   d S )Nr    )r:   r)   Úbuild_isolationr    r    r!   r>   k   s    zIsWheel.prep_for_distN)r?   r@   rA   r=   r>   r    r    r    r!   r   e   s   r   c               @   s   e Zd Zdd„ Zdd„ ZdS )r   c             C   s,   | j  ¡ }|r(| d¡r(| | d¡¡ |S )Nzdependency_links.txt)r   Úget_distÚhas_metadataÚadd_dependency_linksÚget_metadata_lines)r:   r)   r=   r    r    r!   r=   r   s
    
zIsSDist.distc       	   	   C   s¶   | j  ¡ \}}|o|}d}t|ƒtdd„ |D ƒƒ }|rddd„ }t d| j ||ƒ¡ t d||ƒ¡ |r�| j j� W d Q R X t|| j jj|ƒ ntdd	�| j _| j  	¡  | j  
¡  d S )
N)Ú
setuptoolsÚwheelc             s   s   | ]}t  |¡jV  qd S )N)r   ÚRequirementÚkey)r'   r(   r    r    r!   ú	<genexpr>ƒ   s   z(IsSDist.prep_for_dist.<locals>.<genexpr>c             S   s   d  ttt| ƒƒ¡S )Nz and )ÚjoinÚmapÚreprÚsorted)Úrsr    r    r!   Úformat_reqs‡   s    z*IsSDist.prep_for_dist.<locals>.format_reqsz=Missing build time requirements in pyproject.toml for %s: %s.zUThis version of pip does not implement PEP 517 so it cannot build a wheel without %s.F)Úno_clean)r   Úget_pep_518_infor/   ÚloggerÚwarningÚ	build_envr8   Úpathr   Úrun_egg_infoÚassert_source_matches_version)	r:   r)   rE   r5   ÚisolateÚshould_isolateÚminimum_requirementsÚmissing_requirementsrT   r    r    r!   r>   {   s,    



zIsSDist.prep_for_distN)r?   r@   rA   r=   r>   r    r    r    r!   r   p   s   	r   c               @   s   e Zd Zdd„ Zdd„ ZdS )Ú	Installedc             C   s   | j jS )N)r   Úsatisfied_by)r:   r)   r    r    r!   r=       s    zInstalled.distc             C   s   d S )Nr    )r:   r)   r    r    r!   r>   £   s    zInstalled.prep_for_distN)r?   r@   rA   r=   r>   r    r    r    r!   ra   ž   s   ra   c                   sD   e Zd ZdZ‡ fdd„Zedd„ ƒZdd„ Zdd	„ Zd
d„ Z	‡  Z
S )ÚRequirementPreparerzPrepares a Requirement
    c                sB   t t| ƒ ¡  || _|| _|| _|r,t|ƒ}|| _|| _|| _	d S )N)
Úsuperrc   r;   Úsrc_dirÚ	build_dirÚdownload_dirr   Úwheel_download_dirÚprogress_barrE   )r:   rf   rg   re   rh   ri   rE   )Ú	__class__r    r!   r;   «   s    zRequirementPreparer.__init__c             C   sD   | j r@t| j ƒ| _ tj | j ¡r$dS t d¡ tdt| j ƒ ƒ‚dS )NTz!Could not find download directoryz0Could not find or access download directory '%s'F)	rg   r   ÚosrZ   ÚexistsrW   Úcriticalr   r   )r:   r    r    r!   Ú_download_should_saveÇ   s    
z)RequirementPreparer._download_should_savec             C   sà  |j r0|j jdkr0t|j jƒ}t dt|ƒ¡ nt d|¡ tƒ ��’ | | j	¡ t
j t
j |jd¡¡r|td||jf ƒ‚| |||¡ |j s”t‚|j }|rÖt|ƒr®tƒ ‚nt|ƒrÄt|ƒrÄtƒ ‚|jsÖ|jsÖtƒ ‚|j| d�}|rò|sòtƒ }y\| j}	d}
|j j�r| j�r| j}	|j j�r0|	�r,d}
nd}
t|j |j|	|
||| j d	� W nH t!j"k
�r– } z&t #d
||¡ t$d|||j f ƒ‚W dd}~X Y nX t%|ƒ}| &|| j'¡ | j(�rÒ|j jt)j*k�rÒ| +| j¡ W dQ R X |S )zCPrepare a requirement that would be obtained from req.link
        ÚfilezProcessing %szCollecting %szsetup.pyzípip can't proceed with requirements '%s' due to a pre-existing build directory (%s). This is likely due to a previous installation that failed. pip is being responsible and not assuming it can delete this. Please delete it and try again.)Útrust_internetTF)ÚsessionÚhashesri   z4Could not install requirement %s because of error %szDCould not install requirement %s because of HTTP error %s for URL %sN),r   Úschemer   r&   rW   Úinfor   r   Úensure_has_source_dirrf   rk   rZ   rl   rO   rD   r   Úpopulate_linkÚAssertionErrorr	   r   r   r   r   Úoriginal_linkÚ	is_pinnedr   rr   r   rg   r   rh   r
   ri   r   Ú	HTTPErrorrm   r   r"   r>   rE   rn   r   Úall_schemesÚarchive)r:   r   rq   r)   Úupgrade_allowedÚrequire_hashesrZ   r   rr   rg   Úautodelete_unpackedÚexcÚabstract_distr    r    r!   Úprepare_linked_requirementÕ   sf    
	

"z.RequirementPreparer.prepare_linked_requirementc          	   C   sŒ   |j stdƒ‚t d|¡ tƒ �b |r2td| ƒ‚| | j¡ | | j	 ¡ t
|ƒ}| || j¡ | j	rt| | j¡ | |¡ W dQ R X |S )z(Prepare an editable requirement
        z-cannot prepare a non-editable req as editablezObtaining %szoThe editable requirement %s cannot be installed when requiring hashes, because there is no single file to hash.N)r   rw   rW   rt   r   r   ru   re   Úupdate_editablern   r"   r>   rE   r|   rg   Úcheck_if_exists)r:   r   r~   Úuse_user_siter)   r�   r    r    r!   Úprepare_editable_requirementK  s    z0RequirementPreparer.prepare_editable_requirementc          	   C   sf   |j stdƒ‚|dk	s&td|j f ƒ‚t d|||j j¡ tƒ � |rPt d¡ t|ƒ}W dQ R X |S )z1Prepare an already-installed requirement
        z(req should have been satisfied but isn'tNzAdid not get skip reason skipped but req.satisfied_by is set to %rzRequirement %s: %s (%s)z§Since it is already installed, we are trusting this package without checking its hash. To ensure a completely repeatable environment, install into an empty virtualenv.)rb   rw   rW   rt   Úversionr   Údebugra   )r:   r   r~   Úskip_reasonr�   r    r    r!   Úprepare_installed_requirementf  s    
z1RequirementPreparer.prepare_installed_requirement)r?   r@   rA   rB   r;   Úpropertyrn   r‚   r†   rŠ   Ú__classcell__r    r    )rj   r!   rc   §   s   vrc   )4rB   Ú	itertoolsÚloggingrk   r1   r   Úpip._vendorr   r   Úpip._internal.build_envr   Úpip._internal.compatr   Úpip._internal.downloadr   r   r	   r
   r   Úpip._internal.exceptionsr   r   r   r   r   Úpip._internal.indexr   Zpip._internal.req.req_installr   Úpip._internal.utils.hashesr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   r   Úpip._internal.utils.uir   Úpip._internal.vcsr   Ú	getLoggerr?   rW   r"   r8   Úobjectr9   r   r   ra   rc   r    r    r    r!   Ú<module>   s2   
.	