o
    hQ^                     @   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/   \/var/www/html/olx_land/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 )zCopying 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 )zCheck 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   zpip 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)zSince 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
