o
    Ëý°jQ^  ã                   @   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	 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 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.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= e >e?¡Z@de)de+dedeAdef
dd„ZBded eCd!eDddfd"d#„ZEG d$d%„ d%ƒZF		d;ded&e"d'e	eC d(e	e/ deFf
d)d*„ZGd+eCd,eCddfd-d.„ZHd/eCd0eCddfd1d2„ZI	d;ded'e	eC d(e	e/ deFfd3d4„ZJ		d;ded eCd&e"d!eDd'e	eC d(e	e/ de	eF fd5d6„ZKded'eCd(e	e/ de	eC fd7d8„ZLG d9d:„ d:ƒZMdS )<z)Prepares a distribution for installation
é    N)ÚDictÚIterableÚListÚOptional)Úcanonicalize_name)Ú)make_distribution_for_install_requirement)ÚInstalledDistribution)ÚDirectoryUrlHashUnsupportedÚHashMismatchÚHashUnpinnedÚInstallationErrorÚNetworkConnectionErrorÚPreviousBuildDirErrorÚVcsHashUnsupported)ÚPackageFinder)ÚBaseDistribution)ÚLink)ÚWheel)ÚBatchDownloaderÚ
Downloader)ÚHTTPRangeRequestUnsupportedÚdist_from_wheel_url)Ú
PipSession)ÚInstallRequirement)ÚRequirementTracker)Úcopy2_fixed)ÚHashesÚMissingHashes)Ú
indent_log)Údisplay_pathÚhide_urlÚis_installable_dirÚrmtree)ÚTempDirectory)Úunpack_file)ÚvcsÚreqÚreq_trackerÚfinderÚbuild_isolationÚreturnc                 C   sL   t | ƒ}| | ¡� | ||¡ W d  ƒ | ¡ S 1 sw   Y  | ¡ S )z(Prepare a distribution for installation.N)r   ÚtrackÚprepare_distribution_metadataÚget_metadata_distribution)r&   r'   r(   r)   Úabstract_dist© r/   ú“/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_internal/operations/prepare.pyÚ_get_prepared_distribution1   s   
ÿþr1   ÚlinkÚlocationÚ	verbosityc                 C   s2   t  | j¡}|d usJ ‚|j|t| jƒ|d� d S )N)Úurlr4   )r%   Úget_backend_for_schemeÚschemeÚunpackr    r5   )r2   r3   r4   Úvcs_backendr/   r/   r0   Úunpack_vcs_link>   s   r:   c                   @   s&   e Zd Zdedee ddfdd„ZdS )ÚFileÚpathÚcontent_typer*   Nc                 C   s,   || _ |d u rt |¡d | _d S || _d S )Nr   )r<   Ú	mimetypesÚ
guess_typer=   )Úselfr<   r=   r/   r/   r0   Ú__init__E   s   
zFile.__init__)Ú__name__Ú
__module__Ú__qualname__Ústrr   rA   r/   r/   r/   r0   r;   D   s    r;   ÚdownloadÚdownload_dirÚhashesc                 C   sV   t ddd�}d }|rt| ||ƒ}|r|}d }n|| |jƒ\}}|r&| |¡ t||ƒS )Nr8   T©ÚkindÚglobally_managed)r#   Ú_check_download_dirr<   Úcheck_against_pathr;   )r2   rF   rG   rH   Útemp_dirÚalready_downloaded_pathÚ	from_pathr=   r/   r/   r0   Úget_http_urlM   s   

rQ   ÚsrcÚdestc              
   C   sN   zt | |ƒ W dS  tjy& } zt dt|ƒ| |¡ W Y d}~dS d}~ww )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ÚwarningrE   )rR   rS   Úer/   r/   r0   Ú_copy2_ignoring_special_filese   s   ü€ûrY   ÚsourceÚtargetc                    sb   t j |¡}t j |¡‰t j |¡‰dtdtt dtt f‡ ‡‡fdd„}tjˆ ||dt	d� d S )NÚdÚnamesr*   c                    s6   g }| ˆ kr|ddg7 }t j | ¡ˆkr|ˆg7 }|S )Nz.toxz.nox)Úosr<   Úabspath)r\   r]   Úskipped©rZ   Útarget_basenameÚtarget_dirnamer/   r0   Úignore~   s   
z!_copy_source_tree.<locals>.ignoreT)rd   ÚsymlinksÚcopy_function)
r^   r<   r_   ÚbasenameÚdirnamerE   r   rT   ÚcopytreerY   )rZ   r[   Útarget_abspathrd   r/   ra   r0   Ú_copy_source_treey   s   &
ûrk   c                 C   s<   d}|r
t | ||ƒ}|r|}n| j}|r| |¡ t|dƒS )z'Get file and optionally check its hash.N)rL   Ú	file_pathrM   r;   )r2   rG   rH   rO   rP   r/   r/   r0   Úget_file_url–   s   

rm   c                 C   s„   | j rt| ||d� dS |  ¡ r"tj |¡rt|ƒ t| j|ƒ dS | j	r-t
| ||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.
    )r4   N)rH   )Úis_vcsr:   Úis_existing_dirr^   r<   Úisdirr"   rk   rl   Úis_filerm   rQ   Úis_wheelr$   r=   )r2   r3   rF   r4   rG   rH   Úfiler/   r/   r0   Ú
unpack_url®   s&   
ü	rt   c                 C   sp   t j || j¡}t j |¡sdS t d|¡ |r6z| |¡ W |S  ty5   t 	d|¡ t  
|¡ Y dS w |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.)r^   r<   ÚjoinÚfilenameÚexistsrV   ÚinforM   r
   rW   Úunlink)r2   rG   rH   Údownload_pathr/   r/   r0   rL   å   s"   ùþ
úrL   c                       sT  e Zd ZdZdedee dededededed	e	d
ededede
deddf‡ fdd„Zdeddfdd„Zdededdfdd„Zdedefdd„Zdedee fdd„Z	d0dee deddfd d!„Z	d0dededefd"d#„Z	d0d$ee deddfd%d&„Zdededefd'd(„Zdeddfd)d*„Zdedefd+d,„Zded-edefd.d/„Z‡  ZS )1ÚRequirementPreparerzPrepares a RequirementÚ	build_dirrG   Úsrc_dirr)   r'   ÚsessionÚprogress_barr(   Úrequire_hashesÚuse_user_siteÚ
lazy_wheelr4   Úin_tree_buildr*   Nc                    sz   t ƒ  ¡  || _|| _|| _|| _t||ƒ| _t||ƒ| _	|| _
|| _|| _|	| _|
| _|| _|| _|| _i | _d| _d S )N)Ú r„   )ÚsuperrA   r}   r|   r'   Ú_sessionr   Ú	_downloadr   Ú_batch_downloadr(   rG   r)   r€   r�   Úuse_lazy_wheelr4   rƒ   Ú_downloadedÚ_previous_requirement_header)r@   r|   rG   r}   r)   r'   r~   r   r(   r€   r�   r‚   r4   rƒ   ©Ú	__class__r/   r0   rA     s"   

zRequirementPreparer.__init__r&   c                 C   s    |j jr|jsd}tt|j jƒƒ}n	d}t|jp|ƒ}||f| jkr-||f| _t 	||¡ |jrNt
ƒ � t 	d|j j¡ W d  ƒ dS 1 sGw   Y  dS dS )z3Provide context for the requirement being prepared.zProcessing %szCollecting %szUsing cached %sN)r2   rq   Úoriginal_link_is_in_wheel_cacherE   r   rl   r&   r‹   rV   rx   r   rv   )r@   r&   ÚmessageÚinformationr/   r/   r0   Ú_log_preparing_link8  s   
"ÿÿz'RequirementPreparer._log_preparing_linkÚparallel_buildsc                 C   sj   |j jrdS |jdu sJ ‚|j  ¡ r| jr|j j|_dS |j| jd|d� t|jƒr3t	d 
||j¡ƒ‚dS )z1Ensure source_dir of a linked InstallRequirement.NT)Ú
autodeleter’   zí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.)r2   rr   Ú
source_dirro   rƒ   rl   Úensure_has_source_dirr|   r!   r   Úformat)r@   r&   r’   r/   r/   r0   Ú_ensure_link_req_src_dirI  s"   
ý

ûÿz,RequirementPreparer._ensure_link_req_src_dirc                 C   sX   | j s	|jdd�S |jjrtƒ ‚|j ¡ rtƒ ‚|jd u r#|js#t	ƒ ‚|jdd�p+t
ƒ S )NT)Útrust_internetF)r€   rH   r2   rn   r   ro   r	   Úoriginal_linkÚ	is_pinnedr   r   )r@   r&   r/   r/   r0   Ú_get_linked_req_hashesn  s   
z*RequirementPreparer._get_linked_req_hashesr2   c                 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yP   t d|¡ Y dS w )	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€   rV   Údebugrq   rr   r   rv   r   Únamerx   Úversionr5   Úsplitr   r†   r   )r@   r2   ÚwheelrŸ   r5   r/   r/   r0   Ú _fetch_metadata_using_lazy_wheelŽ  s2   
þ

ýþz4RequirementPreparer._fetch_metadata_using_lazy_wheelFÚpartially_downloaded_reqsc           
      C   sˆ   t ddd�j}i }|D ]}|jsJ ‚|||j< q|  | ¡ |¡}|D ]\}\}}	t d||¡ || }||_q"|D ]}|  ||¡ q9dS )z>Download any requirements which were only fetched by metadata.r8   TrI   zDownloading link %s to %sN)	r#   r<   r2   rˆ   ÚkeysrV   rž   Úlocal_file_pathÚ_prepare_linked_requirement)
r@   r¤   r’   rN   Úlinks_to_fully_downloadr&   Úbatch_downloadr2   ÚfilepathÚ_r/   r/   r0   Ú_complete_partial_requirements­  s    
þÿz2RequirementPreparer._complete_partial_requirementsc                 C   sÀ   |j sJ ‚|j }|  |¡ tƒ �F d}| jdur(|jr(|  |¡}t|j | j|ƒ}|dur4|| j|j j< n|  	|¡}|durId|_
|W  d  ƒ S |  ||¡W  d  ƒ S 1 sYw   Y  dS )z3Prepare a requirement to be obtained from req.link.NT)r2   r‘   r   rG   rr   r›   rL   rŠ   r5   r£   Úneeds_more_preparationr§   )r@   r&   r’   r2   rl   rH   Ú
wheel_distr/   r/   r0   Úprepare_linked_requirementÍ  s"   



ð
$íz.RequirementPreparer.prepare_linked_requirementÚreqsc                 C   sž   dd„ |D ƒ}|D ]&}| j dur/|jjr/|  |¡}t|j| j |ƒ}|dur/|| j|jj< d|_q	g }|D ]}|jr?| |¡ q4|  	||¡ q4| 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’   )rG   r2   rr   r›   rL   rŠ   r5   r­   Úappendr§   r¬   )r@   r°   r’   r&   rH   rl   r¤   r/   r/   r0   Ú prepare_linked_requirements_moreé  s$   
€
þz4RequirementPreparer.prepare_linked_requirements_morec           	   
   C   sÚ   |j sJ ‚|j }|  ||¡ |  |¡}| ¡ r| jrd }n>|j| jvrHzt||j| j	| j
| j|ƒ}W n( tyG } z	td |||¡ƒ‚d }~ww | j|j }|rU| |¡ t|d d�}|ra|j|_t|| j| j| jƒ}|S )NzDCould not install requirement {} because of HTTP error {} for URL {})r=   )r2   r—   r›   ro   rƒ   r5   rŠ   rt   r”   r‡   r4   rG   r   r   r–   rM   r;   r<   r¦   r1   r'   r(   r)   )	r@   r&   r’   r2   rH   Ú
local_fileÚexcrl   Údistr/   r/   r0   r§     sH   

ú
þ€ÿ
üz/RequirementPreparer._prepare_linked_requirementc                 C   s´   | j d usJ ‚|jd usJ ‚|j}|js| ¡ r#|jr#| | j ¡ d S | ¡ r/t d|¡ d S |jd u r6d S t	j
 | j |j¡}t	j
 |¡sXt |j|¡ t|ƒ}t d|¡ d S d S )NzENot copying link to destination directory since it is a directory: %szSaved %s)rG   r2   rn   ro   ÚeditableÚarchiverV   rž   r¦   r^   r<   ru   rv   rw   rT   Úcopyr   rx   )r@   r&   r2   Údownload_locationrz   r/   r/   r0   Úsave_linked_requirement4  s(   ý
ýz+RequirementPreparer.save_linked_requirementc                 C   sŽ   |j sJ dƒ‚t d|¡ tƒ �- | jrtd |¡ƒ‚| | j¡ | 	¡  t
|| j| j| jƒ}| | j¡ W d  ƒ |S 1 s@w   Y  |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.N)r¸   rV   rx   r   r€   r   r–   r•   r}   Úupdate_editabler1   r'   r(   r)   Úcheck_if_existsr�   )r@   r&   r·   r/   r/   r0   Úprepare_editable_requirementN  s*   ýü
ïíz0RequirementPreparer.prepare_editable_requirementÚskip_reasonc                 C   s€   |j sJ dƒ‚|dusJ d |j ¡ƒ‚t d|||j j¡ tƒ � | jr)t d¡ t|ƒ 	¡ W  d  ƒ S 1 s9w   Y  dS )z)Prepare 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_byr–   rV   rx   r    r   r€   rž   r   r-   )r@   r&   rÀ   r/   r/   r0   Úprepare_installed_requirementl  s   
þÿÿ
$øz1RequirementPreparer.prepare_installed_requirement)F)rB   rC   rD   Ú__doc__rE   r   Úboolr   r   r   ÚintrA   r   r‘   r—   r   r›   r   r   r£   r   r¬   r¯   r´   r§   r¼   r¿   rÂ   Ú__classcell__r/   r/   rŒ   r0   r{   ÿ   s²    þýüûúùø	÷
öõôóòñ6ÿÿ
þ% þ
ý"ýþý
ü!ÿÿÿ
þÿÿÿ
þÿÿ
þ-þ
ýþýür{   )NN)NrÃ   Úloggingr>   r^   rT   Útypingr   r   r   r   Úpip._vendor.packaging.utilsr   Úpip._internal.distributionsr   Ú%pip._internal.distributions.installedr   Úpip._internal.exceptionsr	   r
   r   r   r   r   r   Ú"pip._internal.index.package_finderr   Úpip._internal.metadatar   Úpip._internal.models.linkr   Úpip._internal.models.wheelr   Úpip._internal.network.downloadr   r   Ú pip._internal.network.lazy_wheelr   r   Úpip._internal.network.sessionr   Úpip._internal.req.req_installr   Úpip._internal.req.req_trackerr   Úpip._internal.utils.filesystemr   Úpip._internal.utils.hashesr   r   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r    r!   r"   Úpip._internal.utils.temp_dirr#   Úpip._internal.utils.unpackingr$   Úpip._internal.vcsr%   Ú	getLoggerrB   rV   rÄ   r1   rE   rÅ   r:   r;   rQ   rY   rk   rm   rt   rL   r{   r/   r/   r/   r0   Ú<module>   s¸    $	
ÿþýü
ûüÿþýü
ûÿÿÿÿ
þúÿþýüûú
ù7ÿÿÿ
þ