Current File : //lib/python3.9/site-packages/pip/_internal/operations/__pycache__/prepare.cpython-39.pyc
a

[��f]�@sRdZddlZddlZddlZddlZddlmZmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZmZmZmZmZddlmZdd	lmZdd
lmZddlmZddl m!Z!m"Z"dd
l#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=e�>e?�Z@e)e+eeAed�dd�ZBeeCdd�dd�ZDGdd�d�ZEd3ee"e	eCe	e/eEd �d!d"�ZFeCeCdd#�d$d%�ZGeCeCdd&�d'd(�ZHd4ee	eCe	e/eEd)�d*d+�ZId5eeCe"e	eCe	e/e	eEd,�d-d.�ZJeeCe	e/e	eCd)�d/d0�ZKGd1d2�d2�ZLdS)6z)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�returncCsFt|�}|�|��|�||�Wd�n1s40Y|��S)z(Prepare a distribution for installation.N)rZtrackZprepare_distribution_metadata�get_metadata_distribution)r&r'r(r)Z
abstract_dist�r,�D/usr/lib/python3.9/site-packages/pip/_internal/operations/prepare.py�_get_prepared_distribution1s*r.)�link�locationr*cCs0t�|j�}|dusJ�|j|t|j�d�dS)N)�url)r%Zget_backend_for_scheme�scheme�unpackr r1)r/r0Zvcs_backendr,r,r-�unpack_vcs_link>sr4c@s"eZdZeeedd�dd�ZdS)�FileN)�path�content_typer*cCs*||_|dur t�|�d|_n||_dS)Nr)r6�	mimetypesZ
guess_typer7)�selfr6r7r,r,r-�__init__Esz
File.__init__)�__name__�
__module__�__qualname__�strrr:r,r,r,r-r5Dsr5)r/�download�download_dir�hashesr*cCsVtddd�}d}|r t|||�}|r.|}d}n|||j�\}}|rL|�|�t||�S)Nr3T��kindZglobally_managed)r#�_check_download_dirr6�check_against_pathr5)r/r?r@rA�temp_dir�already_downloaded_path�	from_pathr7r,r,r-�get_http_urlMs
rI)�src�destr*c
CsNzt||�Wn:tjyH}z t�dt|�||�WYd}~n
d}~00dS)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�warningr>)rJrK�er,r,r-�_copy2_ignoring_special_fileses�rQ)�source�targetr*cs^tj�|�}tj�|��tj�|��tttttd����fdd�}tj�||dt	d�dS)N)�d�namesr*cs6g}|�kr|ddg7}tj�|��kr2|�g7}|S)Nz.toxz.nox)�osr6�abspath)rTrUZskipped�rRZtarget_basenameZtarget_dirnamer,r-�ignore~s
z!_copy_source_tree.<locals>.ignoreT)rY�symlinks�
copy_function)
rVr6rW�basename�dirnamer>rrL�copytreerQ)rRrSZtarget_abspathrYr,rXr-�_copy_source_treeys"�r_)r/r@rAr*cCs<d}|rt|||�}|r|}n|j}|r2|�|�t|d�S)z'Get file and optionally check its hash.N)rD�	file_pathrEr5)r/r@rArGrHr,r,r-�get_file_url�s
ra)r/r0r?r@rAr*cCs�|jrt||�dS|��r@tj�|�r0t|�t|j|�dS|j	rVt
|||d�}nt||||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)rA)�is_vcsr4�is_existing_dirrVr6�isdirr"r_r`�is_filerarI�is_wheelr$r7)r/r0r?r@rA�filer,r,r-�
unpack_url�s&

�	rhcCsntj�||j�}tj�|�s dSt�d|�|rjz|�|�Wn*tyht�	d|�t�
|�YdS0|S)z�Check download_dir for previously downloaded file with correct hash
    If a correct file is found return its path else None
    NzFile was already downloaded %sz;Previously-downloaded file %s has bad hash. Re-downloading.)rVr6�join�filename�existsrN�inforEr
rO�unlink)r/r@rA�
download_pathr,r,r-rD�s�
rDcseZdZdZeeeeeeeee	eeeedd�
�fdd�Z
edd�dd�Zeedd	�d
d�Z
eed�dd
�Zeeed�dd�Zd#eeedd�dd�Zd$eeed	�dd�Zd%eeedd�dd�Zeeed	�dd�Zedd�dd�Zeed�dd�Zeeed �d!d"�Z�ZS)&�RequirementPreparerzPrepares a RequirementN)
�	build_dirr@�src_dirr)r'�session�progress_barr(�require_hashes�
use_user_site�
lazy_wheel�
in_tree_buildr*c

stt���||_||_||_||_t||�|_t||�|_	||_
||_||_|	|_
|
|_||_||_i|_d|_dS)N)�rx)�superr:rqrpr'�_sessionr�	_downloadr�_batch_downloadr(r@r)rtru�use_lazy_wheelrw�_downloaded�_previous_requirement_header)
r9rpr@rqr)r'rrrsr(rtrurvrw��	__class__r,r-r:s 
zRequirementPreparer.__init__)r&r*cCs�|jjr$|js$d}tt|jj��}nd}t|jp2|�}||f|jkrZ||f|_t�	||�|jr�t
�� t�	d|jj�Wd�n1s�0YdS)z3Provide context for the requirement being prepared.z
Processing %sz
Collecting %szUsing cached %sN)r/reZoriginal_link_is_in_wheel_cacher>rr`r&rrNrlrrj)r9r&�messageZinformationr,r,r-�_log_preparing_link3s
z'RequirementPreparer._log_preparing_link)r&�parallel_buildsr*cCsj|jjrdS|jdusJ�|j��r8|jr8|jj|_dS|j|jd|d�t|j�rft	d�
||j���dS)z1Ensure source_dir of a linked InstallRequirement.NT)Z
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.)r/rf�
source_dirrcrwr`�ensure_has_source_dirrpr!r�format)r9r&r�r,r,r-�_ensure_link_req_src_dirDs"
�
��z,RequirementPreparer._ensure_link_req_src_dircCsX|js|jdd�S|jjr t��|j��r0t��|jdurF|jsFt	��|jdd�pVt
�S)NT)Ztrust_internetF)rtrAr/rbrrcr	Z
original_linkZ	is_pinnedrr)r9r&r,r,r-�_get_linked_req_hashesis
z*RequirementPreparer._get_linked_req_hashes)r/r*cCs�|js
dS|jrt�d�dS|js*|js:t�d|�dSt|j�}t|j	�}t�
d||j�|j�
dd�d}zt|||j�WSty�t�d|�YdS0dS)	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�#�rz"%s does not support range requests)r}rtrN�debugrerfrrjr�namerl�versionr1�splitrrzr)r9r/Zwheelr�r1r,r,r-� _fetch_metadata_using_lazy_wheel�s0
�

�z4RequirementPreparer._fetch_metadata_using_lazy_wheelF)�partially_downloaded_reqsr�r*c
Cs�tddd�j}i}|D]}|js$J�|||j<q|�|��|�}|D](\}\}}	t�d||�||}||_qD|D]}|�||�qrdS)z>Download any requirements which were only fetched by metadata.r3TrBzDownloading link %s to %sN)	r#r6r/r|�keysrNr��local_file_path�_prepare_linked_requirement)
r9r�r�rFZlinks_to_fully_downloadr&Zbatch_downloadr/�filepath�_r,r,r-�_complete_partial_requirements�s
�z2RequirementPreparer._complete_partial_requirementscCs�|js
J�|j}|�|�t���d}|jdurP|jrP|�|�}t|j|j|�}|durh||j|jj<n*|�	|�}|dur�d|_
|Wd�S|�||�Wd�S1s�0YdS)z3Prepare a requirement to be obtained from req.link.NT)r/r�rr@rfr�rDr~r1r��needs_more_preparationr�)r9r&r�r/r`rAZ
wheel_distr,r,r-�prepare_linked_requirement�s



z.RequirementPreparer.prepare_linked_requirement)�reqsr�r*cCs�dd�|D�}|D]L}|jdur|jjr|�|�}t|j|j|�}|dur||j|jj<d|_qg}|D]"}|jr~|�|�qh|�	||�qh|j
||d�dS)z,Prepare linked requirements more, if needed.cSsg|]}|jr|�qSr,)r�)�.0r&r,r,r-�
<listcomp>��zHRequirementPreparer.prepare_linked_requirements_more.<locals>.<listcomp>NF)r�)r@r/rfr�rDr~r1r��appendr�r�)r9r�r�r&rAr`r�r,r,r-� prepare_linked_requirements_more�s"
�z4RequirementPreparer.prepare_linked_requirements_morec	
Cs�|js
J�|j}|�||�|�|�}|��r:|jr:d}n�|j|jvr�zt||j|j	|j
|�}Wq�ty�}ztd�
|||���WYd}~q�d}~00n&|j|j}|r�|�|�t|dd�}|r�|j|_t||j|j|j�}|S)NzDCould not install requirement {} because of HTTP error {} for URL {})r7)r/r�r�rcrwr1r~rhr�r{r@r
rr�rEr5r6r�r.r'r(r))	r9r&r�r/rAZ
local_file�excr`�distr,r,r-r�s<

���
�z/RequirementPreparer._prepare_linked_requirementcCs�|jdusJ�|jdusJ�|j}|js6|��rF|jrF|�|j�dS|��r^t�d|�dS|jdurldSt	j
�|j|j�}t	j
�
|�s�t�|j|�t|�}t�d|�dS)NzENot copying link to destination directory since it is a directory: %szSaved %s)r@r/rbrc�editable�archiverNr�r�rVr6rirjrkrL�copyrrl)r9r&r/Zdownload_locationrnr,r,r-�save_linked_requirement*s&�
z+RequirementPreparer.save_linked_requirementcCs�|jsJd��t�d|�t��X|jr6td�|���|�|j�|�	�t
||j|j|j
�}|�|j�Wd�n1s~0Y|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�rNrlrrtrr�r�rqZupdate_editabler.r'r(r)Zcheck_if_existsru)r9r&r�r,r,r-�prepare_editable_requirementDs&���*z0RequirementPreparer.prepare_editable_requirement)r&�skip_reasonr*cCs�|jsJd��|dus&Jd�|j���t�d|||jj�t��,|jrRt�d�t|��	�Wd�S1sr0YdS)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 {}zRequirement %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.)
Zsatisfied_byr�rNrlr�rrtr�rr+)r9r&r�r,r,r-�prepare_installed_requirementbs
����z1RequirementPreparer.prepare_installed_requirement)F)F)F)r;r<r=�__doc__r>r�boolrrrr:rr�r�rr�rrr�rr�r�r�r�r�r�r��
__classcell__r,r,r�r-ro�sd�2�%"�"��!�����(� �ro)NN)NN)NN)Mr�Zloggingr8rVrL�typingrrrrZpip._vendor.packaging.utilsrZpip._internal.distributionsrZ%pip._internal.distributions.installedrZpip._internal.exceptionsr	r
rrr
rrZ"pip._internal.index.package_finderrZpip._internal.metadatarZpip._internal.models.linkrZpip._internal.models.wheelrZpip._internal.network.downloadrrZ pip._internal.network.lazy_wheelrrZpip._internal.network.sessionrZpip._internal.req.req_installrZpip._internal.req.req_trackerrZpip._internal.utils.filesystemrZpip._internal.utils.hashesrrZpip._internal.utils.loggingrZpip._internal.utils.miscrr r!r"Zpip._internal.utils.temp_dirr#Zpip._internal.utils.unpackingr$Zpip._internal.vcsr%Z	getLoggerr;rNr�r.r>r4r5rIrQr_rarhrDror,r,r,r-�<module>s�$	
�
������7
�