U
    +|ja  ã                   @   sØ  d Z ddlZddlZddlZddl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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"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. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? e @eA¡ZBdd„ ZCdd„ ZDG dd„ dƒZEd-dd „ZFd!d"„ ZGd#d$„ ZHd.d%d&„ZId/d'd(„ZJd)d*„ ZKG d+d,„ d,ƒZLdS )0z)Prepares a distribution for installation
é    N)ÚDictÚIterableÚListÚOptionalÚTuple)Úcanonicalize_name)ÚDistribution)Ú)make_distribution_for_install_requirement)ÚInstalledDistribution)ÚDirectoryUrlHashUnsupportedÚHashMismatchÚHashUnpinnedÚInstallationErrorÚNetworkConnectionErrorÚPreviousBuildDirErrorÚVcsHashUnsupported)ÚPackageFinder)ÚLink)ÚWheel)ÚBatchDownloaderÚ
Downloader)ÚHTTPRangeRequestUnsupportedÚdist_from_wheel_url)Ú
PipSession)ÚInstallRequirement)ÚRequirementTracker)Ú
deprecated)Úcopy2_fixed)ÚHashesÚMissingHashes)Ú
indent_log)Údisplay_pathÚhide_urlÚrmtree)ÚTempDirectory)Úunpack_file)Úvcsc              	   C   s2   t | ƒ}| | ¡� | ||¡ W 5 Q R X | ¡ S )z(Prepare a distribution for installation.)r	   ÚtrackÚprepare_distribution_metadataÚget_pkg_resources_distribution)ÚreqÚreq_trackerÚfinderÚbuild_isolationÚabstract_dist© r/   úhC:\Users\snmko\Desktop\web_content\django_cbt\venv\Lib\site-packages\pip/_internal/operations/prepare.pyÚ_get_prepared_distribution2   s    r1   c                 C   s0   t  | j¡}|d k	st‚|j|t| jƒd� d S )N)Úurl)r&   Úget_backend_for_schemeÚschemeÚAssertionErrorÚunpackr"   r2   )ÚlinkÚlocationÚvcs_backendr/   r/   r0   Úunpack_vcs_link@   s    r:   c                   @   s   e Zd Zdd„ ZdS )ÚFilec                 C   s*   || _ |d kr t |¡d | _n|| _d S )Nr   )ÚpathÚ	mimetypesÚ
guess_typeÚcontent_type)Úselfr<   r?   r/   r/   r0   Ú__init__I   s    zFile.__init__N)Ú__name__Ú
__module__Ú__qualname__rA   r/   r/   r/   r0   r;   G   s   r;   c                 C   sV   t ddd�}d }|r t| ||ƒ}|r.|}d }n|| |jƒ\}}|rL| |¡ t||ƒS )Nr6   T©ÚkindÚglobally_managed)r$   Ú_check_download_dirr<   Úcheck_against_pathr;   )r7   ÚdownloadÚdownload_dirÚhashesÚtemp_dirÚalready_downloaded_pathÚ	from_pathr?   r/   r/   r0   Úget_http_urlR   s      ÿ
rP   c              
   C   sL   zt | |ƒ W n8 tjk
rF } zt dt|ƒ| |¡ W 5 d}~X Y nX dS )zÆCopying special files is not supported, but as a convenience to users
    we skip errors copying them. This supports tools that may create e.g.
    socket files in the project source directory.
    z>Ignoring special file error '%s' encountered copying %s to %s.N)r   ÚshutilÚSpecialFileErrorÚloggerÚwarningÚstr)ÚsrcÚdestÚer/   r/   r0   Ú_copy2_ignoring_special_filesm   s    ürY   c                    sL   t j |¡}t j |¡‰t j |¡‰‡ ‡‡fdd„}tjˆ ||dtd� d S )Nc                    s6   g }| ˆ kr|ddg7 }t j | ¡ˆkr2|ˆg7 }|S )Nz.toxz.nox)Úosr<   Úabspath)ÚdÚnamesÚskipped©ÚsourceÚtarget_basenameÚtarget_dirnamer/   r0   Úignoreˆ   s    
z!_copy_source_tree.<locals>.ignoreT)rc   ÚsymlinksÚcopy_function)rZ   r<   r[   ÚbasenameÚdirnamerQ   ÚcopytreerY   )r`   ÚtargetÚtarget_abspathrc   r/   r_   r0   Ú_copy_source_tree‚   s    ûrk   c                 C   s<   d}|rt | ||ƒ}|r|}n| j}|r2| |¡ t|dƒS )z,Get file and optionally check its hash.
    N)rH   Ú	file_pathrI   r;   )r7   rK   rL   rN   rO   r/   r/   r0   Úget_file_url¡   s    	  ÿ
rm   c                 C   s�   | j rt| |ƒ dS |  ¡ rPtddddd� tj |¡r@t|ƒ t| j	|ƒ dS | j
rft| ||d�}nt| |||d�}| jsŒt|j||jƒ |S )a_  Unpack link into location, downloading if required.

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    NzòA future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
z21.3iƒ  )ÚreplacementÚgone_inÚissue)rL   )Úis_vcsr:   Úis_existing_dirr   rZ   r<   Úisdirr#   rk   rl   Úis_filerm   rP   Úis_wheelr%   r?   )r7   r8   rJ   rK   rL   Úfiler/   r/   r0   Ú
unpack_url¿   s2    
ø
ü	rw   c                 C   sp   t j || j¡}t j |¡s dS t d|¡ |rlz| |¡ W n, tk
rj   t 	d|¡ t  
|¡ Y dS X |S )z† Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None
    NzFile was already downloaded %sz;Previously-downloaded file %s has bad hash. Re-downloading.)rZ   r<   ÚjoinÚfilenameÚexistsrS   ÚinforI   r   rT   Úunlink)r7   rK   rL   Údownload_pathr/   r/   r0   rH   þ   s    ý
rH   c                       s~   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zddd„Z	ddd„Z
ddd„Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚRequirementPreparerzPrepares a Requirement
    c                    st   t ƒ  ¡  || _|| _|| _|| _t||ƒ| _t||ƒ| _	|| _
|| _|| _|	| _|
| _|| _|| _i | _d| _d S )N)Ú r   )ÚsuperrA   Úsrc_dirÚ	build_dirr+   Ú_sessionr   Ú	_downloadr   Ú_batch_downloadr,   rK   r-   Úrequire_hashesÚuse_user_siteÚuse_lazy_wheelÚin_tree_buildÚ_downloadedÚ_previous_requirement_header)r@   r‚   rK   r�   r-   r+   ÚsessionÚprogress_barr,   r†   r‡   Ú
lazy_wheelr‰   ©Ú	__class__r/   r0   rA     s     
zRequirementPreparer.__init__c              	   C   s†   |j jr$|js$d}tt|j jƒƒ}nd}t|jp2|ƒ}||f| jkrZ||f| _t 	||¡ |jr‚t
ƒ � t 	d|j j¡ W 5 Q R X dS )z3Provide context for the requirement being prepared.zProcessing %szCollecting %szUsing cached %sN)r7   rt   Úoriginal_link_is_in_wheel_cacherU   r!   rl   r*   r‹   rS   r{   r    ry   )r@   r*   ÚmessageÚinformationr/   r/   r0   Ú_log_preparing_linkO  s    
z'RequirementPreparer._log_preparing_linkc                 C   sx   |j jrdS |jdkst‚|j  ¡ r8| jr8|j j|_dS |j| jd|d� t	j
 t	j
 |jd¡¡rttd ||j¡ƒ‚dS )z1Ensure source_dir of a linked InstallRequirement.NT)Ú
autodeleteÚparallel_buildszsetup.pyzípip can't proceed with requirements '{}' due to apre-existing build directory ({}). 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.)r7   ru   Ú
source_dirr5   rr   r‰   rl   Úensure_has_source_dirr‚   rZ   r<   rz   rx   r   Úformat)r@   r*   r–   r/   r/   r0   Ú_ensure_link_req_src_dira  s$    
ý üÿz,RequirementPreparer._ensure_link_req_src_dirc                 C   sX   | j s|jdd�S |jjr tƒ ‚|j ¡ r0tƒ ‚|jd krF|jsFt	ƒ ‚|jdd�pVt
ƒ S )NT)Útrust_internetF)r†   rL   r7   rq   r   rr   r   Úoriginal_linkÚ	is_pinnedr   r   )r@   r*   r/   r/   r0   Ú_get_linked_req_hashes„  s    
z*RequirementPreparer._get_linked_req_hashesc                 C   s¨   | j s
dS | jrt d¡ dS |js*|js:t d|¡ dS t|jƒ}t|j	ƒ}t 
d||j¡ |j dd¡d }zt||| jƒW S  tk
r¢   t d|¡ Y dS X dS )	z-Fetch metadata using lazy wheel, if possible.Nz3Lazy wheel is not used as hash checking is requiredz>Lazy wheel is not used as %r does not points to a remote wheelz+Obtaining dependency information from %s %sú#é   r   z"%s does not support range requests)rˆ   r†   rS   Údebugrt   ru   r   ry   r   Únamer{   Úversionr2   Úsplitr   rƒ   r   )r@   r7   Úwheelr¢   r2   r/   r/   r0   Ú _fetch_metadata_using_lazy_wheel¥  s0    
ý

 þz4RequirementPreparer._fetch_metadata_using_lazy_wheelFc           
      C   sˆ   t ddd�j}i }|D ]}|js$t‚|||j< q|  | ¡ |¡}|D ](\}\}}	t d||¡ || }||_qD|D ]}|  	||¡ qrdS )z>Download any requirements which were only fetched by metadata.r6   TrE   zDownloading link %s to %sN)
r$   r<   r7   r5   r…   ÚkeysrS   r¡   Úlocal_file_pathÚ_prepare_linked_requirement)
r@   Úpartially_downloaded_reqsr–   rM   Úlinks_to_fully_downloadr*   Úbatch_downloadr7   ÚfilepathÚ_r/   r/   r0   Ú_complete_partial_requirementsÂ  s    	
þz2RequirementPreparer._complete_partial_requirementsc              
   C   s¶   |j s
t‚|j }|  |¡ tƒ �Œ d}| jdk	rP|jrP|  |¡}t|j | j|ƒ}|dk	rl|df| j|j j	< n(|  
|¡}|dk	r”d|_|W  5 Q R £ S |  ||¡W  5 Q R £ S Q R X dS )z3Prepare a requirement to be obtained from req.link.NT)r7   r5   r”   r    rK   ru   rž   rH   rŠ   r2   r¦   Úneeds_more_preparationr©   )r@   r*   r–   r7   rl   rL   Ú
wheel_distr/   r/   r0   Úprepare_linked_requirementã  s    



z.RequirementPreparer.prepare_linked_requirementc                 C   s¢   dd„ |D ƒ}|D ]P}| j dk	r|jjr|  |¡}t|j| j |ƒ}|dk	r|df| j|jj< d|_qg }|D ]"}|jr‚| |¡ ql|  	||¡ ql| j
||d� dS )z,Prepare linked requirements more, if needed.c                 S   s   g | ]}|j r|‘qS r/   )r°   )Ú.0r*   r/   r/   r0   Ú
<listcomp>  s      zHRequirementPreparer.prepare_linked_requirements_more.<locals>.<listcomp>NF)r–   )rK   r7   ru   rž   rH   rŠ   r2   r°   Úappendr©   r¯   )r@   Úreqsr–   r*   rL   rl   rª   r/   r/   r0   Ú prepare_linked_requirements_moreþ  s"    
 ÿz4RequirementPreparer.prepare_linked_requirements_morec           
   
   C   sä   |j s
t‚|j }|  ||¡ |  |¡}| ¡ r:| jr:d }n†|j| jkr˜zt||j	| j
| j|ƒ}W qÀ tk
r” } ztd |||¡ƒ‚W 5 d }~X Y qÀX n(| j|j \}}|r¶| |¡ t||ƒ}|rÌ|j|_t|| j| j| jƒ}	|	S )NzDCould not install requirement {} because of HTTP error {} for URL {})r7   r5   rš   rž   rr   r‰   r2   rŠ   rw   r—   r„   rK   r   r   r™   rI   r;   r<   r¨   r1   r+   r,   r-   )
r@   r*   r–   r7   rL   Ú
local_fileÚexcrl   r?   Údistr/   r/   r0   r©     sH    

   þ  ÿÿ

   ÿz/RequirementPreparer._prepare_linked_requirementc                 C   s°   | j d k	st‚|jd k	st‚|j}|js6| ¡ rF|jrF| | j ¡ d S | ¡ r^t d|¡ d S |j	d krld S t
j | j |j¡}t
j |¡s¬t |j	|¡ t|ƒ}t d|¡ d S )NzENot copying link to destination directory since it is a directory: %szSaved %s)rK   r5   r7   rq   rr   ÚeditableÚarchiverS   r¡   r¨   rZ   r<   rx   ry   rz   rQ   Úcopyr!   r{   )r@   r*   r7   Údownload_locationr}   r/   r/   r0   Úsave_linked_requirement?  s&    þ
z+RequirementPreparer.save_linked_requirementc              	   C   sx   |j stdƒ‚t d|¡ tƒ �N | jr6td |¡ƒ‚| | j	¡ | 
¡  t|| j| j| jƒ}| | j¡ W 5 Q R X |S )z(Prepare an editable requirement
        z-cannot prepare a non-editable req as editablezObtaining %szoThe editable requirement {} cannot be installed when requiring hashes, because there is no single file to hash.)r»   r5   rS   r{   r    r†   r   r™   r˜   r�   Úupdate_editabler1   r+   r,   r-   Úcheck_if_existsr‡   )r@   r*   rº   r/   r/   r0   Úprepare_editable_requirementY  s&    þÿ   ÿz0RequirementPreparer.prepare_editable_requirementc              
   C   st   |j stdƒ‚|dk	s&td |j ¡ƒ‚t d|||j j¡ tƒ �* | jrRt d¡ t	|ƒ 
¡ W  5 Q R £ S Q R X d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 {}z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.)Úsatisfied_byr5   r™   rS   r{   r£   r    r†   r¡   r
   r)   )r@   r*   Úskip_reasonr/   r/   r0   Úprepare_installed_requirementv  s$    
ÿÿ  þÿz1RequirementPreparer.prepare_installed_requirement)F)F)F)rB   rC   rD   Ú__doc__rA   r”   rš   rž   r¦   r¯   r²   r·   r©   r¿   rÂ   rÅ   Ú__classcell__r/   r/   r�   r0   r~     s   3#!  ý
!

%r~   )NN)NN)NN)MrÆ   Úloggingr=   rZ   rQ   Útypingr   r   r   r   r   Úpip._vendor.packaging.utilsr   Úpip._vendor.pkg_resourcesr   Úpip._internal.distributionsr	   Ú%pip._internal.distributions.installedr
   Úpip._internal.exceptionsr   r   r   r   r   r   r   Ú"pip._internal.index.package_finderr   Úpip._internal.models.linkr   Úpip._internal.models.wheelr   Úpip._internal.network.downloadr   r   Ú pip._internal.network.lazy_wheelr   r   Úpip._internal.network.sessionr   Zpip._internal.req.req_installr   Úpip._internal.req.req_trackerr   Úpip._internal.utils.deprecationr   Úpip._internal.utils.filesystemr   Úpip._internal.utils.hashesr   r   Úpip._internal.utils.loggingr    Úpip._internal.utils.miscr!   r"   r#   Úpip._internal.utils.temp_dirr$   Úpip._internal.utils.unpackingr%   Úpip._internal.vcsr&   Ú	getLoggerrB   rS   r1   r:   r;   rP   rY   rk   rm   rw   rH   r~   r/   r/   r/   r0   Ú<module>   sV   $	
  ü
!  ý
"  û
?