a
    e0hW                     @   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+rd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re8d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   trackprepare_distribution_metadataget_pkg_resources_distribution)reqreq_trackerfinderbuild_isolationabstract_dist r:   N/var/www/auris/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_backendr:   r:   r;   unpack_vcs_link\   s    rD   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)selfrF   rI   r:   r:   r;   __init__e   s    zFile.__init__N)__name__
__module____qualname__rK   r:   r:   r:   r;   rE   c   s   rE   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_dirrF   check_against_pathrE   )rA   downloaddownload_dirhashestemp_diralready_downloaded_path	from_pathrI   r:   r:   r;   get_http_urln   s    
rZ   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 )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warningstrr   )srcdester:   r:   r;   _copy2_ignoring_special_files   s    rc   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)osrF   abspath)dnamesskippedsourcetarget_basenametarget_dirnamer:   r;   r-      s    
z!_copy_source_tree.<locals>.ignoreTr,   r0   )
rd   rF   re   basenamedirnamedictr   rc   r[   copytree)rj   targettarget_abspathr-   kwargsr:   ri   r;   _copy_source_tree   s    rt   c                 C   s<   d}|rt | ||}|r|}n| j}|r2|| t|dS )z,Get file and optionally check its hash.
    N)rR   	file_pathrS   rE   )rA   rU   rV   rX   rY   r:   r:   r;   get_file_url   s    	
rv   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)rV   )is_vcsrD   is_existing_dirrd   rF   isdirr   rt   ru   is_filerv   rZ   is_wheelr   rI   )rA   rB   rT   rU   rV   filer:   r:   r;   
unpack_url   s&    
	r}   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.)rd   rF   joinfilenameexistsr]   inforS   r   r^   unlink)rA   rU   rV   download_pathr:   r:   r;   rR     s    
rR   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   rK   src_dir	build_dirr6   _sessionr   	_downloadr   _batch_downloadr7   rU   r8   require_hashesuse_user_siteuse_lazy_wheel_downloaded_previous_requirement_header)rJ   r   rU   r   r8   r6   sessionprogress_barr7   r   r   
lazy_wheel	__class__r:   r;   rK   *  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rt
   t	d|j j W d   n1 s0    Y  dS )z3Provide context for the requirement being prepared.zProcessing %szCollecting %szUsing cached %sN)rA   rz   original_link_is_in_wheel_cacher_   r   ru   r5   r   r]   r   r   r   )rJ   r5   messageinformationr:   r:   r;   _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)
autodeleteparallel_buildszsetup.pyzpip 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.)rA   r{   
source_dirensure_has_source_dirr   rd   rF   r   r~   r   format)rJ   r5   r   r:   r:   r;   _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   rV   rA   rw   r   rx   r   original_link	is_pinnedr   r   )rJ   r5   r:   r:   r;   _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]   debugrz   r{   r   r   r   namer   versionr=   splitr   r   r   )rJ   rA   wheelr   r=   r:   r:   r;    _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rd|_
|W  d   S | ||W  d   S 1 s0    Y  dS )z3Prepare a requirement to be obtained from req.link.NT)rA   r   r   rU   r{   r   rR   r   r=   r   needs_more_preparation_prepare_linked_requirement)rJ   r5   r   rA   ru   rV   
wheel_distr:   r:   r;   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 r:   )r   .0r5   r:   r:   r;   
<listcomp>      zHRequirementPreparer.prepare_linked_requirements_more.<locals>.<listcomp>c                 S   s   g | ]
}|j qS r:   )rA   r   r:   r:   r;   r     r   r@   TrO   N)r   rF   r   updater   r   )rJ   reqsr   linkstmpdirr5   r:   r:   r;    prepare_linked_requirements_more  s    z4RequirementPreparer.prepare_linked_requirements_morec           
   
   C   s   |j s
J |j }| || | |}|j| jvrzt||j| j| j|}W q t	y } zt
d|||W Y d }~qd }~0 0 n(| j|j \}}|r|| t||}|r|j|_t|| j| j| j}	|	S )NzDCould not install requirement {} because of HTTP error {} for URL {})rA   r   r   r=   r   r}   r   r   rU   r
   r	   r   rS   rE   rF   local_file_pathr<   r6   r7   r8   )
rJ   r5   r   rA   rV   
local_fileexcru   rI   distr:   r:   r;   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
|st|j| t|}td| d S )NzENot copying link to destination directory since it is a directory: %szSaved %s)rU   rA   rw   rx   editablearchiver]   r   r   rd   rF   r~   r   r   r[   copyr   r   )rJ   r5   rA   download_locationr   r:   r:   r;   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 s0    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   update_editablerU   r<   r6   r7   r8   check_if_existsr   )rJ   r5   r   r:   r:   r;   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)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   r]   r   r   r   r   r   r   r4   )rJ   r5   skip_reasonr:   r:   r;   prepare_installed_requirementG  s     

z1RequirementPreparer.prepare_installed_requirement)F)F)rL   rM   rN   __doc__rK   r   r   r   r   r   r   r   r   r   r   __classcell__r:   r:   r   r;   r   &  s   /!

"r   )NN)NN)NN)Wr   loggingrG   rd   r[   pip._vendor.packaging.utilsr   Zpip._vendor.sixr   pip._internal.distributionsr   %pip._internal.distributions.installedr   pip._internal.exceptionsr   r   r   r	   r
   r   r   pip._internal.models.wheelr   pip._internal.network.downloadr   r    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'   Zpip._internal.req.req_installr(   pip._internal.req.req_trackerr)   r*   r_   boolr+   	getLoggerrL   r]   r<   rD   objectrE   rZ   rc   rt   rv   r}   rR   r   r:   r:   r:   r;   <module>   s   $	 	
  
"  
"  
0