o
    ~îj4‡  ã                   @  s†  d Z ddlm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 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mZ ddlmZmZmZmZmZm Z m!Z!m"Z"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/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZDmEZE ddlFmGZG ddlHmIZImJZJmKZKmLZL ddlMmNZN ddlOmPZP dd lQmRZR dd!lSmTZT erödd"lUmVZV e?eWƒZXd\d0d1„ZYd]d4d5„ZZd^d<d=„Z[e	G d>d?„ d?ƒƒZ\		d_d`dFdG„Z]	d_dadHdI„Z^		d_dbdKdL„Z_	MdcdddOdP„Z`dedTdU„ZadfdXdY„ZbG dZd[„ d[ƒZcdS )gz(Prepares a distribution for installationé    )ÚannotationsN)ÚIterable)Ú	dataclass)ÚPath)ÚTYPE_CHECKING)ÚInvalidRequirementÚRequirement)Úcanonicalize_name)ÚBuildEnvironmentInstallerÚBuildIsolationMode)Ú)make_distribution_for_install_requirement)ÚInstalledDistribution)	ÚDirectoryUrlHashUnsupportedÚHashMismatchÚHashUnpinnedÚInstallationErrorÚMetadataInconsistentÚMetadataInvalidÚNetworkConnectionErrorÚSidecarMetadataInconsistentÚVcsHashUnsupported)ÚPackageFinder)ÚBaseDistributionÚget_metadata_distribution)Úcheck_pypi_direct_references)ÚArchiveInfoÚ	DirectUrl)ÚLinkÚjoin_within_directory)ÚWheel)Ú
Downloader)ÚHTTPRangeRequestUnsupportedÚdist_from_wheel_url)Ú
PipSession)ÚBuildTracker)ÚInstallRequirement)Ú	getLogger)Údirect_url_for_editableÚdirect_url_from_link)ÚHashesÚMissingHashes)Ú
indent_log)Údisplay_pathÚ	hash_fileÚhide_urlÚredact_auth_from_requirement)Úget_requirement)ÚTempDirectory)Úunpack_file)Úvcs)ÚBarTypeÚreqr%   Úbuild_trackerr$   Úbuild_env_installerr
   Úbuild_isolationr   Úcheck_build_depsÚboolÚallow_editablesÚreturnr   c                 C  s`   t | ƒ}|j}|dur,| | |¡� | ||||¡ W d  ƒ | ¡ S 1 s'w   Y  | ¡ S )z(Prepare a distribution for installation.N)r   Úbuild_tracker_idÚtrackÚprepare_distribution_metadatar   )r5   r6   r7   r8   r9   r;   Úabstract_distÚ
tracker_id© rB   új/raid/bulk_storage/M2HATS/real-image-venv/lib/python3.10/site-packages/pip/_internal/operations/prepare.pyÚ_get_prepared_distributionF   s   	ÿ
ÿürD   ÚdistributionÚNonec                 C  s,   | j }|du rtd| › d�ƒ‚t||ƒ dS )z3Apply source-dependent checks to prepared metadata.NzCannot prepare z: the source link is missing.)Úsource_linkr   r   )r5   rE   rG   rB   rB   rC   Ú"_check_linked_requirement_metadataY   s   rH   Úlinkr   ÚlocationÚstrÚ	verbosityÚintc                 C  s2   t  | j¡}|d usJ ‚|j|t| jƒ|d� d S )N)ÚurlrL   )r3   Úget_backend_for_schemeÚschemeÚunpackr.   rN   )rI   rJ   rL   Úvcs_backendrB   rB   rC   Úunpack_vcs_linkd   s   rS   c                   @  s,   e Zd ZU ded< dZded< d
dd	„ZdS )ÚFilerK   ÚpathNú
str | NoneÚcontent_typer<   rF   c                 C  s<   | j d u rzt | j¡d | _ W d S  ty   Y d S w d S )Nr   )rW   Ú	mimetypesÚ
guess_typerU   ÚOSError)ÚselfrB   rB   rC   Ú__post_init__o   s   
ÿûzFile.__post_init__)r<   rF   )Ú__name__Ú
__module__Ú__qualname__Ú__annotations__rW   r\   rB   rB   rB   rC   rT   j   s   
 rT   Údownloadr    Údownload_dirrV   ÚhashesúHashes | Nonec                 C  sV   t ddd�}d }|rt| ||ƒ}|r|}d }n|| |jƒ\}}|r&| |¡ t||ƒS )NrQ   T©ÚkindÚglobally_managed)r1   Ú_check_download_dirrU   Úcheck_against_pathrT   )rI   ra   rb   rc   Útemp_dirÚalready_downloaded_pathÚ	from_pathrW   rB   rB   rC   Úget_http_urly   s   

rm   c                 C  s<   d}|r
t | ||ƒ}|r|}n| j}|r| |¡ t|dƒS )z'Get file and optionally check its hash.N)rh   Ú	file_pathri   rT   )rI   rb   rc   rk   rl   rB   rB   rC   Úget_file_url‘   s   

ro   úFile | Nonec                 C  sd   | j rt| ||d� dS |  ¡ rJ ‚| jrt| ||d�}nt| |||d�}| js0t|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.
    )rL   N©rc   )
Úis_vcsrS   Úis_existing_dirÚis_filero   rm   Úis_wheelr2   rU   rW   )rI   rJ   ra   rL   rb   rc   ÚfilerB   rB   rC   Ú
unpack_url©   s   ü	rw   TÚwarn_on_hash_mismatchc                 C  sp   t || jƒ}tj |¡sdS t d|¡ |r6z| |¡ W |S  ty5   |r-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   ÚfilenameÚosrU   ÚexistsÚloggerÚinfori   r   ÚwarningÚunlink)rI   rb   rc   rx   Údownload_pathrB   rB   rC   rh   Ô   s$   		øþ
ùrh   ÚdistÚsourceúfrozenset[Requirement]c                 C  s`   t ƒ }| ¡ D ]$}z| t| ¡ ƒ¡ W q ty+ } zt| d|› d|› �ƒ‚d}~ww t|ƒS )z«Return the canonicalized ``Requires-Dist`` entries of ``dist``.

    ``source`` describes which metadata file ``dist`` was parsed from, for
    use in error messages.
    zRequires-Dist in z: N)ÚsetÚiter_raw_dependenciesÚaddr0   Ústripr   r   Ú	frozenset)r5   r�   r‚   Ú	canonicalÚrawÚerB   rB   rC   Ú_canonical_requiresò   s   €ÿrŒ   Úsidecar_distÚ
wheel_distc           	      C  s  t |jƒ}t |jƒ}||krt| d||ƒ‚|j|jkr(t| dt|jƒt|jƒƒ‚t| |dƒ}t| |dƒ}||krSt| dd ttt|| ƒƒ¡d ttt|| ƒƒ¡ƒ‚|j	|j	krft| dt|j	ƒt|j	ƒƒ‚t
| ¡ ƒ}t
| ¡ ƒ}||kr‹t| dd t|| ƒ¡d t|| ƒ¡ƒ‚d	S )
ap  Check that a .metadata-based distribution matches the wheel's METADATA.

    Compare ``Name``, ``Version``, ``Requires-Dist``, ``Requires-Python``
    and ``Provides-Extra`` between the two and abort the install on any
    mismatch as PEP 658 requires the metadata files "MUST be identical".

    While the PEP doesn't mandate that consumers enforce the identical
    requirement, it's good nonetheless to check to prevent confusing
    behaviour when an index misbehaves.

    Also note for name and version, pip usually rejects wheels if they're
    inconsistent already. Checking them again here is purely defensive.
    ÚNameÚVersionzthe PEP 658 .metadata filezthe wheel's METADATAzRequires-Distz, zRequires-PythonzProvides-ExtraN)r	   Úraw_namer   ÚversionrK   rŒ   ÚjoinÚsortedÚmapÚrequires_pythonrˆ   Úiter_provided_extras)	r5   r�   rŽ   Úsidecar_nameÚ
wheel_nameÚsidecar_requiresÚwheel_requiresÚsidecar_extrasÚwheel_extrasrB   rB   rC   Ú_check_sidecar_matches_wheel  sN   

ü	ÿüüüÿrž   c                      s°   e Zd ZdZdG‡ fdd„ZdHd"d#„ZdId%d&„ZdJd(d)„ZdKd+d,„ZdKd-d.„Z	dLd1d2„Z
	3dMdNd6d7„Z	3dMdOd9d:„Z	3dMdPd<d=„ZdOd>d?„ZdHd@dA„ZdQdBdC„ZdRdEdF„Z‡  ZS )SÚRequirementPreparerzPrepares a RequirementÚ	build_dirrK   rb   rV   Úsrc_dirr8   r   Úbuild_isolation_installerr
   r9   r:   r6   r$   Úsessionr#   Úprogress_barr4   Úfinderr   Úrequire_hashesÚuse_user_siteÚ
lazy_wheelrL   rM   Úlegacy_resolverr;   r<   rF   c                  s€   t ƒ  ¡  || _|| _|| _|| _t||	ƒ| _|
| _|| _	|| _
|| _|| _|| _|| _|| _|| _|| _i | _d| _|| _d S )N)Ú rª   )ÚsuperÚ__init__r¡   r    r6   Ú_sessionr    Ú	_downloadr¥   rb   r8   r7   r9   r¦   r§   Úuse_lazy_wheelrL   r©   Ú_downloadedÚ_previous_requirement_headerr;   )r[   r    rb   r¡   r8   r¢   r9   r6   r£   r¤   r¥   r¦   r§   r¨   rL   r©   r;   ©Ú	__class__rB   rC   r¬   J  s&   

zRequirementPreparer.__init__r5   r%   c                 C  sè   |j jr|jsd}tt|j jƒƒ}nd}|jrt|jƒnt|ƒ}|jr?|jr?t	|jtƒr0|j}n|j 
¡ }|r?|d|› d�7 }||f| jkrQ||f| _t ||¡ |jrrtƒ � t d|j j¡ W d  ƒ dS 1 skw   Y  dS dS )z3Provide context for the requirement being prepared.zProcessing %szCollecting %sz (from ú)zUsing cached %sN)rI   rt   Úis_wheel_from_cacherK   r,   rn   r5   r/   Ú
comes_fromÚ
isinstancerl   r±   r|   r}   r+   ry   )r[   r5   ÚmessageÚinformationr¶   rB   rB   rC   Ú_log_preparing_link‹  s&   

"ÿÿz'RequirementPreparer._log_preparing_linkÚparallel_buildsc                 C  sP   |j jrdS |jdu sJ ‚|j  ¡ r|j j|_dS |j| jd|d� | ¡  dS )z1Ensure source_dir of a linked InstallRequirement.NT)Ú
autodeleter»   )rI   ru   Ú
source_dirrs   rn   Úensure_has_source_dirr    Úensure_pristine_source_checkout)r[   r5   r»   rB   rB   rC   Ú_ensure_link_req_src_dir¦  s   

ýz,RequirementPreparer._ensure_link_req_src_dirr)   c                 C  sX   | j s|j|j d�S |jjrtƒ ‚|j ¡ rtƒ ‚|js#|j	s#t
ƒ ‚|jdd�p+tƒ S )N)Útrust_internetF)r¦   rc   Úhas_hash_optionsrI   rr   r   rs   r   Ú	is_directÚ	is_pinnedr   r*   ©r[   r5   rB   rB   rC   Ú_get_linked_req_hashes½  s   
z*RequirementPreparer._get_linked_req_hashesúBaseDistribution | Nonec                 C  s>   | j r
t d¡ d S | jrt d¡ d S |  |¡p|  |j¡S )Nz9Metadata-only fetching is not used in the legacy resolverz?Metadata-only fetching is not used as hash checking is required)r©   r|   Údebugr¦   Ú$_fetch_metadata_using_link_data_attrÚ _fetch_metadata_using_lazy_wheelrI   rÅ   rB   rB   rC   Ú_fetch_metadata_onlyÞ  s   ÿÿÿ
þz(RequirementPreparer._fetch_metadata_onlyc                 C  s¾   |j  ¡ }|du rdS |jdusJ ‚t d|j|¡ t|| j| ¡ d�}t|j	dƒ�}| 
¡ }W d  ƒ n1 s9w   Y  t||j j|jjƒ}t|jƒt|jjƒkr]t|d|jj|jƒ‚|S )zGFetch metadata from the data-dist-info-metadata attribute, if possible.Nz/Obtaining dependency information for %s from %srq   Úrbr�   )rI   Úmetadata_linkr5   r|   Úverboserm   r®   Ú	as_hashesÚopenrU   Úreadr   ry   Únamer	   r‘   r   )r[   r5   rÍ   Úmetadata_fileÚfÚmetadata_contentsÚmetadata_distrB   rB   rC   rÉ   ñ  s6   
ýý
ÿýÿz8RequirementPreparer._fetch_metadata_using_link_data_attrrI   r   c                 C  sŠ   | j sdS |js|jst d|¡ dS t|jƒ}|j}t d||j	¡ |j
 dd¡d }zt||| jƒW S  tyD   t d|¡ Y dS w )z-Fetch metadata using lazy wheel, if possible.Nz=Lazy wheel is not used as %r does not point to a remote wheelz+Obtaining dependency information from %s %sú#é   r   z"%s does not support range requests)r¯   rt   ru   r|   rÈ   r   ry   rÒ   r}   r’   rN   Úsplitr"   r­   r!   )r[   rI   ÚwheelrÒ   rN   rB   rB   rC   rÊ     s,   þ
ýþz4RequirementPreparer._fetch_metadata_using_lazy_wheelFÚpartially_downloaded_reqsúIterable[InstallRequirement]c           
      C  s¬   t ddd�j}i }|D ]}|jsJ ‚|||j< q| j | ¡ |¡}|D ]%\}\}}	t d||¡ || }||_|| j	|jj
< |jsH| t|ƒ¡ q#|D ]}|  ||¡ qKdS )z>Download any requirements which were only fetched by metadata.rQ   Tre   zDownloading link %s to %sN)r1   rU   rI   r®   ÚbatchÚkeysr|   rÈ   Úlocal_file_pathr°   rN   ru   Úneeds_unpacked_archiver   Ú_prepare_linked_requirement)
r[   rÛ   r»   rj   Úlinks_to_fully_downloadr5   Úbatch_downloadrI   ÚfilepathÚ_rB   rB   rC   Ú_complete_partial_requirements7  s"   
€ÿz2RequirementPreparer._complete_partial_requirementsr   c                 C  sò   |j sJ ‚|  |¡ tƒ �b d}| jdur*|j jr*|  |¡}t|j | j||j d�}|dur6|| j|j j	< n,|  
|¡}|durbt||ƒ d|_| |¡ |jdu rYt|j |jƒ|_|W  d  ƒ S |  ||¡W  d  ƒ S 1 srw   Y  dS )z3Prepare a requirement to be obtained from req.link.N)rx   T)rI   rº   r+   rb   ru   rÆ   rh   rµ   r°   rN   rË   rH   Úneeds_more_preparationÚset_distÚdownload_infor(   r½   rá   )r[   r5   r»   rn   rc   rÖ   rB   rB   rC   Úprepare_linked_requirement`  s6   


ö



ÿÞ
%$Û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 rB   )rç   )Ú.0r5   rB   rB   rC   Ú
<listcomp>‘  s    zHRequirementPreparer.prepare_linked_requirements_more.<locals>.<listcomp>NF)r»   )rb   rI   ru   rÆ   rh   r°   rN   rç   Úappendrá   ræ   )r[   rë   r»   r5   rc   rn   rÛ   rB   rB   rC   Ú prepare_linked_requirements_more�  s$   
€
þz4RequirementPreparer.prepare_linked_requirements_morec           
   
   C  sú  |j sJ ‚|j }|  |¡}|rC|jrC|jd usJ ‚|jsJ ‚|js#J ‚|jjr7|jjjr7| |jjj¡r7d }nt	 
d¡ |j|_ |j }|  ||¡ | ¡ rPd }nB|j| jvrzt||j| j| j| j|ƒ}W n, ty~ } ztd|› d|› d|› �ƒ‚d }~ww | j|j }|rŒ| |¡ t|d d�}|jd u rÈ|jrœJ ‚t||jƒ|_|jjrÈ|jjjsÈ|rÈt|jƒd  ¡ }t|jjtd|id�|jj d	�|_|rÎ|j|_!t"|| j#| j$| j%| j&| j'ƒ}	t(||	ƒ |jrû|j)d urû|j)|	urû| *¡ d urût+||j)|	ƒ |	S )
NzyThe hashes of the source archive found in cache entry don't match, ignoring cached built wheel and re-downloading source.zCould not install requirement z because of HTTP error z	 for URL )rW   r   Úsha256rq   )rN   Úarchive_infoÚsubdirectory),rI   rÆ   rµ   ré   ru   rt   rñ   rc   Ú
has_one_ofr|   r~   Úcached_wheel_source_linkrÀ   rs   rN   r°   rw   r½   r®   rL   rb   r   r   ri   rT   Úeditabler(   r-   rU   Ú	hexdigestr   r   rò   rß   rD   r6   r7   r8   r9   r;   rH   Ú_distributionrÍ   rž   )
r[   r5   r»   rI   rc   Ú
local_fileÚexcrn   Úhashr�   rB   rB   rC   rá   «  sž   




ÿþý	ÿúÿÿÿ€ÿ


ÿþýýú
ÿ

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
ƒ}tj |¡sVt |j|¡ t|ƒ}t d|¡ d S d S )NzENot copying link to destination directory since it is a directory: %szSaved %s)rb   rI   rr   rs   rõ   Úarchiver|   rÈ   rß   r   ry   rz   rU   r{   ÚshutilÚcopyr,   r}   )r[   r5   rI   Údownload_locationr€   rB   rB   rC   Úsave_linked_requirement"  s(   ý
ýz+RequirementPreparer.save_linked_requirementc                 C  s®   |j sJ dƒ‚t d|¡ tƒ �= | jrtd|› d�ƒ‚| | j¡ | ¡  |j	s+J ‚t
|jƒ|_t|| j| j| j| j| jƒ}| | j¡ W d  ƒ |S 1 sPw   Y  |S )z Prepare an editable requirement.z-cannot prepare a non-editable req as editablezObtaining %szThe editable requirement zT cannot be installed when requiring hashes, because there is no single file to hash.N)rõ   r|   r}   r+   r¦   r   r¾   r¡   Úupdate_editabler½   r'   Úunpacked_source_directoryré   rD   r6   r7   r8   r9   r;   Úcheck_if_existsr§   )r[   r5   r�   rB   rB   rC   Úprepare_editable_requirement<  s0   
ÿ
ú	
ëé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'tNz?did 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|   r}   r’   r+   r¦   rÈ   r   r   )r[   r5   r  rB   rB   rC   Úprepare_installed_requirement^  s    
ÿÿÿÿ
$øz1RequirementPreparer.prepare_installed_requirement)"r    rK   rb   rV   r¡   rK   r8   r   r¢   r
   r9   r:   r6   r$   r£   r#   r¤   r4   r¥   r   r¦   r:   r§   r:   r¨   r:   rL   rM   r©   r:   r;   r:   r<   rF   )r5   r%   r<   rF   )r5   r%   r»   r:   r<   rF   )r5   r%   r<   r)   )r5   r%   r<   rÇ   )rI   r   r<   rÇ   )F)rÛ   rÜ   r»   r:   r<   rF   )r5   r%   r»   r:   r<   r   )rë   rÜ   r»   r:   r<   rF   )r5   r%   r<   r   )r5   r%   r  rK   r<   r   )r]   r^   r_   Ú__doc__r¬   rº   rÀ   rÆ   rË   rÉ   rÊ   ræ   rê   rï   rá   rÿ   r  r  Ú__classcell__rB   rB   r²   rC   rŸ   G  s&    
A


!

) ý*ÿ.ÿ

w
"rŸ   )r5   r%   r6   r$   r7   r
   r8   r   r9   r:   r;   r:   r<   r   )r5   r%   rE   r   r<   rF   )rI   r   rJ   rK   rL   rM   r<   rF   )NN)
rI   r   ra   r    rb   rV   rc   rd   r<   rT   )rI   r   rb   rV   rc   rd   r<   rT   )rI   r   rJ   rK   ra   r    rL   rM   rb   rV   rc   rd   r<   rp   )T)
rI   r   rb   rK   rc   rd   rx   r:   r<   rV   )r5   r%   r�   r   r‚   rK   r<   rƒ   )r5   r%   r�   r   rŽ   r   r<   rF   )dr  Ú
__future__r   rX   rz   rü   Úcollections.abcr   Údataclassesr   Úpathlibr   Útypingr   Ú"pip._vendor.packaging.requirementsr   r   Úpip._vendor.packaging.utilsr	   Úpip._internal.build_envr
   r   Úpip._internal.distributionsr   Ú%pip._internal.distributions.installedr   Úpip._internal.exceptionsr   r   r   r   r   r   r   r   r   Ú"pip._internal.index.package_finderr   Úpip._internal.metadatar   r   Ú(pip._internal.metadata.direct_referencesr   Úpip._internal.models.direct_urlr   r   Úpip._internal.models.linkr   r   Úpip._internal.models.wheelr   Úpip._internal.network.downloadr    Ú pip._internal.network.lazy_wheelr!   r"   Úpip._internal.network.sessionr#   Ú,pip._internal.operations.build.build_trackerr$   Úpip._internal.req.req_installr%   Úpip._internal.utils._logr&   Ú&pip._internal.utils.direct_url_helpersr'   r(   Úpip._internal.utils.hashesr)   r*   Úpip._internal.utils.loggingr+   Úpip._internal.utils.miscr,   r-   r.   r/   Úpip._internal.utils.packagingr0   Úpip._internal.utils.temp_dirr1   Úpip._internal.utils.unpackingr2   Úpip._internal.vcsr3   Úpip._internal.cli.progress_barsr4   r]   r|   rD   rH   rS   rT   rm   ro   rw   rh   rŒ   rž   rŸ   rB   rB   rB   rC   Ú<module>   sp    ,


üÿú/ü

A