a
    ˆÀàg¼W  ã                   @   sr  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 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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$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/ e+�rþddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlmEZE e�rÆe8de1eFe4eF ge4eF f eGdœdd�ZHn8e8de1eFeFgdf e1eFe4eF ge4eF f eGeGd œdd�ZHe IeJ¡ZKd!d"„ ZLd#d$„ ZMG d%d&„ d&eNƒZOd5d'd(„ZPd)d*„ ZQd+d,„ ZRd6d-d.„ZSd7d/d0„ZTd1d2„ ZUG d3d4„ d4eNƒZVdS )8z)Prepares a distribution for installation
é    N)Úcanonicalize_name)ÚPY2)Ú)make_distribution_for_install_requirement)ÚInstalledDistribution)ÚDirectoryUrlHashUnsupportedÚHashMismatchÚHashUnpinnedÚInstallationErrorÚNetworkConnectionErrorÚPreviousBuildDirErrorÚVcsHashUnsupported)ÚWheel)ÚBatchDownloaderÚ
Downloader)ÚHTTPRangeRequestUnsupportedÚdist_from_wheel_url)Úcopy2_fixed)ÚMissingHashes)Ú
indent_log)Údisplay_pathÚhide_urlÚpath_to_displayÚrmtree)ÚTempDirectory)ÚMYPY_CHECK_RUNNING)Úunpack_file)Úvcs)ÚCallableÚDictÚIterableÚListÚOptionalÚTuple)Ú	TypedDict)ÚDistribution)ÚPackageFinder)ÚLink)Ú
PipSession)ÚInstallRequirement)ÚRequirementTracker)ÚHashesÚCopytreeKwargs©ÚignoreÚsymlinksF)Útotal)Úcopy_functionr-   Úignore_dangling_symlinksr.   c                 C   sF   t | ƒ}| | ¡� | ||¡ W d  ƒ n1 s40    Y  | ¡ S )z(Prepare a distribution for installation.N)r   ÚtrackZprepare_distribution_metadataÚget_pkg_resources_distribution)ÚreqÚreq_trackerÚfinderÚbuild_isolationZabstract_dist© r8   úY/var/www/sistema_ama/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.pyÚ_get_prepared_distributionN   s    *r:   c                 C   s0   t  | j¡}|d usJ ‚|j|t| jƒd� d S )N)Úurl)r   Úget_backend_for_schemeÚschemeÚunpackr   r;   )ÚlinkÚlocationÚvcs_backendr8   r8   r9   Úunpack_vcs_link\   s    rB   c                   @   s   e Zd Zdd„ ZdS )ÚFilec                 C   s*   || _ |d u r t |¡d | _n|| _d S )Nr   )ÚpathÚ	mimetypesÚ
guess_typeÚcontent_type)ÚselfrD   rG   r8   r8   r9   Ú__init__e   s    zFile.__init__N)Ú__name__Ú
__module__Ú__qualname__rI   r8   r8   r8   r9   rC   c   s   rC   c                 C   sV   t ddd�}d }|r t| ||ƒ}|r.|}d }n|| |jƒ\}}|rL| |¡ t||ƒS )Nr>   T©ÚkindÚglobally_managed)r   Ú_check_download_dirrD   Úcheck_against_pathrC   )r?   ÚdownloadÚdownload_dirÚhashesÚtemp_dirÚalready_downloaded_pathÚ	from_pathrG   r8   r8   r9   Úget_http_urln   s    ÿ
rX   c              
   C   sV   zt | |ƒ W nB tjyP } z(t dt|ƒt| ƒt|ƒ¡ W Y d}~n
d}~0 0 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Ústrr   )ÚsrcÚdestÚer8   r8   r9   Ú_copy2_ignoring_special_files‰   s    üra   c                    sd   t j |¡}t j |¡‰t j |¡‰‡ ‡‡fdd„}t|dd�}tsLt|d< tj	ˆ |fi |¤Ž d S )Nc                    s6   g }| ˆ kr|ddg7 }t j | ¡ˆkr2|ˆg7 }|S )Nz.toxz.nox)ÚosrD   Úabspath)ÚdÚnamesZskipped©ÚsourceZtarget_basenameZtarget_dirnamer8   r9   r-   ¤   s    
z!_copy_source_tree.<locals>.ignoreTr,   r0   )
rb   rD   rc   ÚbasenameÚdirnameÚdictr   ra   rY   Úcopytree)rg   ÚtargetZtarget_abspathr-   Úkwargsr8   rf   r9   Ú_copy_source_treež   s    rn   c                 C   s<   d}|rt | ||ƒ}|r|}n| j}|r2| |¡ t|dƒS )z,Get file and optionally check its hash.
    N)rP   Ú	file_pathrQ   rC   )r?   rS   rT   rV   rW   r8   r8   r9   Úget_file_url¾   s    	ÿ
rp   c                 C   s€   | j rt| |ƒ dS |  ¡ r@tj |¡r0t|ƒ t| j|ƒ dS | j	rVt
| ||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.
    N)rT   )Úis_vcsrB   Úis_existing_dirrb   rD   Úisdirr   rn   ro   Úis_filerp   rX   Úis_wheelr   rG   )r?   r@   rR   rS   rT   Úfiler8   r8   r9   Ú
unpack_urlÜ   s&    
ü	rw   c                 C   sn   t j || j¡}t j |¡s dS t d|¡ |rjz| |¡ W n* tyh   t 	d|¡ t  
|¡ Y dS 0 |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.)rb   rD   ÚjoinÚfilenameÚexistsr[   ÚinforQ   r   r\   Úunlink)r?   rS   rT   Údownload_pathr8   r8   r9   rP     s    ý
rP   c                       st   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„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚRequirementPreparerzPrepares a Requirement
    c                    sr   t t| ƒ ¡  || _|| _|| _|| _t||ƒ| _t	||ƒ| _
|| _|| _|| _|	| _|
| _|| _i | _d| _d S )N)Ú r   )Úsuperr~   rI   Úsrc_dirÚ	build_dirr5   Ú_sessionr   Ú	_downloadr   Ú_batch_downloadr6   rS   r7   Úrequire_hashesÚuse_user_siteÚuse_lazy_wheelÚ_downloadedÚ_previous_requirement_header)rH   r‚   rS   r�   r7   r5   ÚsessionÚprogress_barr6   r†   r‡   Ú
lazy_wheel©Ú	__class__r8   r9   rI   *  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 d  ƒ n1 sŒ0    Y  dS )z3Provide context for the requirement being prepared.zProcessing %szCollecting %szUsing cached %sN)r?   rt   Zoriginal_link_is_in_wheel_cacher]   r   ro   r4   rŠ   r[   r{   r   ry   )rH   r4   ÚmessageÚinformationr8   r8   r9   Ú_log_preparing_linkY  s    
z'RequirementPreparer._log_preparing_linkc                 C   sZ   |j jrdS |jdu sJ ‚|j| jd|d� tj tj |jd¡¡rVt	d 
||j¡ƒ‚dS )z1Ensure source_dir of a linked InstallRequirement.NT)Z
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.)r?   ru   Ú
source_dirÚensure_has_source_dirr‚   rb   rD   rz   rx   r   Úformat)rH   r4   r“   r8   r8   r9   Ú_ensure_link_req_src_dirk  s    ýüÿz,RequirementPreparer._ensure_link_req_src_dirc                 C   sX   | j s|jdd�S |jjr tƒ ‚|j ¡ r0tƒ ‚|jd u rF|jsFt	ƒ ‚|jdd�pVt
ƒ S )NT)Útrust_internetF)r†   rT   r?   rq   r   rr   r   Úoriginal_linkZ	is_pinnedr   r   )rH   r4   r8   r8   r9   Ú_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y    t d|¡ Y dS 0 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†   r[   Údebugrt   ru   r   ry   r   Únamer{   Úversionr;   Úsplitr   rƒ   r   )rH   r?   Úwheelrž   r;   r8   r8   r9   Ú _fetch_metadata_using_lazy_wheelª  s.    
ý

þz4RequirementPreparer._fetch_metadata_using_lazy_wheelFc                 C   sÄ   |j s
J ‚|j }|  |¡ tƒ �� d}| jdurP|jrP|  |¡}t|j | j|ƒ}|durl|df| j|j j< n*|  	|¡}|dur–d|_
|W  d  ƒ S |  ||¡W  d  ƒ S 1 s¶0    Y  dS )z3Prepare a requirement to be obtained from req.link.NT)r?   r’   r   rS   ru   rš   rP   r‰   r;   r¢   Úneeds_more_preparationÚ_prepare_linked_requirement)rH   r4   r“   r?   ro   rT   Z
wheel_distr8   r8   r9   Úprepare_linked_requirementÇ  s    



z.RequirementPreparer.prepare_linked_requirementc                 C   sX   dd„ |D ƒ}dd„ |D ƒ}t ddd�j}| j |  ||¡¡ |D ]}|  ||¡ qBdS )z-Prepare a linked requirement more, if needed.c                 S   s   g | ]}|j r|‘qS r8   )r£   ©Ú.0r4   r8   r8   r9   Ú
<listcomp>å  ó    zHRequirementPreparer.prepare_linked_requirements_more.<locals>.<listcomp>c                 S   s   g | ]
}|j ‘qS r8   )r?   r¦   r8   r8   r9   r¨   æ  r©   r>   TrM   N)r   rD   r‰   Úupdater…   r¤   )rH   Úreqsr“   ÚlinksZtmpdirr4   r8   r8   r9   Ú prepare_linked_requirements_moreâ  s    z4RequirementPreparer.prepare_linked_requirements_morec           
   
   C   sÒ   |j s
J ‚|j }|  ||¡ |  |¡}|j| jvr†zt||j| j| j|ƒ}W q® t	y‚ } zt
d |||¡ƒ‚W Y d }~q®d }~0 0 n(| j|j \}}|r¤| |¡ t||ƒ}|rº|j|_t|| j| j| jƒ}	|	S )NzDCould not install requirement {} because of HTTP error {} for URL {})r?   r—   rš   r;   r‰   rw   r”   r„   rS   r
   r	   r–   rQ   rC   rD   Úlocal_file_pathr:   r5   r6   r7   )
rH   r4   r“   r?   rT   Ú
local_fileÚexcro   rG   Údistr8   r8   r9   r¤   î  s4    


þÿÿ

ÿz/RequirementPreparer._prepare_linked_requirementc                 C   s°   | j d usJ ‚|jd usJ ‚|j}|js6| ¡ rF|jrF| | j ¡ d S | ¡ r^t d|¡ d S |jd u 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)rS   r?   rq   rr   ÚeditableÚarchiver[   r�   r®   rb   rD   rx   ry   rz   rY   Úcopyr   r{   )rH   r4   r?   Zdownload_locationr}   r8   r8   r9   Úsave_linked_requirement  s&    þ
z+RequirementPreparer.save_linked_requirementc                 C   s”   |j sJ dƒ‚t d|¡ tƒ �` | jr6td |¡ƒ‚| | j¡ | 	| j
du ¡ t|| j| j| jƒ}| | j¡ W d  ƒ n1 s†0    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²   r[   r{   r   r†   r	   r–   r•   r�   Zupdate_editablerS   r:   r5   r6   r7   Zcheck_if_existsr‡   )rH   r4   r±   r8   r8   r9   Úprepare_editable_requirement*  s     þÿÿ*z0RequirementPreparer.prepare_editable_requirementc                 C   s€   |j sJ dƒ‚|dus&J d |j ¡ƒ‚t d|||j j¡ tƒ �, | jrRt d¡ t|ƒ 	¡ W  d  ƒ S 1 sr0    Y  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_byr–   r[   r{   rŸ   r   r†   r�   r   r3   )rH   r4   Zskip_reasonr8   r8   r9   Úprepare_installed_requirementG  s     
ÿÿ
þÿz1RequirementPreparer.prepare_installed_requirement)F)F)rJ   rK   rL   Ú__doc__rI   r’   r—   rš   r¢   r¥   r­   r¤   rµ   r¶   r¸   Ú__classcell__r8   r8   rŽ   r9   r~   &  s   /!

"r~   )NN)NN)NN)Wr¹   ÚloggingrE   rb   rY   Úpip._vendor.packaging.utilsr   Úpip._vendor.sixr   Zpip._internal.distributionsr   Z%pip._internal.distributions.installedr   Úpip._internal.exceptionsr   r   r   r	   r
   r   r   Úpip._internal.models.wheelr   Zpip._internal.network.downloadr   r   Z pip._internal.network.lazy_wheelr   r   Úpip._internal.utils.filesystemr   Úpip._internal.utils.hashesr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   r   r   Úpip._internal.utils.temp_dirr   Úpip._internal.utils.typingr   Úpip._internal.utils.unpackingr   Úpip._internal.vcsr   Útypingr   r   r   r    r!   r"   Zmypy_extensionsr#   Zpip._vendor.pkg_resourcesr$   Ú"pip._internal.index.package_finderr%   Úpip._internal.models.linkr&   Úpip._internal.network.sessionr'   Úpip._internal.req.req_installr(   Úpip._internal.req.req_trackerr)   r*   r]   Úboolr+   Ú	getLoggerrJ   r[   r:   rB   ÚobjectrC   rX   ra   rn   rp   rw   rP   r~   r8   r8   r8   r9   Ú<module>   s€   $	 þú	üø
  ü
"  ý
"  û
0