o ai]@sdZddlZddlZddlZddlZddlmZmZmZm Z ddl m Z ddl m Z ddlmZddlmZmZmZmZmZmZmZddlmZdd lmZdd lmZdd lmZdd 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;ddle?Z@de)de+dedeAdef ddZBded eCddfd!d"ZDGd#d$d$ZE  d:ded%e"d&e eCd'e e/deEf d(d)ZFd*eCd+eCddfd,d-ZGd.eCd/eCddfd0d1ZH d:ded&e eCd'e e/deEfd2d3ZI  d:ded eCd%e"d&e eCd'e e/de eEf d4d5ZJded&eCd'e e/de eCfd6d7ZKGd8d9d9ZLdS);z)Prepares a distribution for installation N)DictIterableListOptional)canonicalize_name))make_distribution_for_install_requirement)InstalledDistribution)DirectoryUrlHashUnsupported HashMismatch HashUnpinnedInstallationErrorNetworkConnectionErrorPreviousBuildDirErrorVcsHashUnsupported) PackageFinder)BaseDistribution)Link)Wheel)BatchDownloader Downloader)HTTPRangeRequestUnsupporteddist_from_wheel_url) PipSession)InstallRequirement)RequirementTracker) copy2_fixed)Hashes MissingHashes) indent_log) display_pathhide_urlis_installable_dirrmtree) TempDirectory) unpack_file)vcsreq req_trackerfinderbuild_isolationreturncCsLt|}|||||Wd|S1swY|S)z(Prepare a distribution for installation.N)rtrackprepare_distribution_metadataget_metadata_distribution)r&r'r(r) abstract_distr//builddir/build/BUILDROOT/alt-python310-pip-21.3.1-5.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/operations/prepare.py_get_prepared_distribution1s  r1linklocationcCs0t|j}|dus J|j|t|jddS)N)url)r%get_backend_for_schemeschemeunpackr r4)r2r3 vcs_backendr/r/r0unpack_vcs_link>s  r9c@s&eZdZdedeeddfddZdS)Filepath content_typer*NcCs,||_|durt|d|_dS||_dS)Nr)r; mimetypes guess_typer<)selfr;r<r/r/r0__init__Es z File.__init__)__name__ __module__ __qualname__strrr@r/r/r/r0r:Dsr:download download_dirhashescCsVtddd}d}|rt|||}|r|}d}n|||j\}}|r&||t||S)Nr7Tkindglobally_managed)r#_check_download_dirr;check_against_pathr:)r2rErFrGtemp_diralready_downloaded_path from_pathr<r/r/r0 get_http_urlMs    rPsrcdestc CsNzt||WdStjy&}ztdt|||WYd}~dSd}~ww)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)rshutilSpecialFileErrorloggerwarningrD)rQrRer/r/r0_copy2_ignoring_special_filesesrXsourcetargetcsbtj|}tj|tj|dtdttdttffdd }tj||dt ddS)Ndnamesr*cs6g}|kr |ddg7}tj|kr|g7}|S)Nz.toxz.nox)osr;abspath)r[r\skippedrYtarget_basenametarget_dirnamer/r0ignore~s   z!_copy_source_tree..ignoreT)rcsymlinks copy_function) r]r;r^basenamedirnamerDrrScopytreerX)rYrZtarget_abspathrcr/r`r0_copy_source_treeys   & rjcCs<d}|r t|||}|r|}n|j}|r||t|dS)z'Get file and optionally check its hash.N)rK file_pathrLr:)r2rFrGrNrOr/r/r0 get_file_urls   rlcCs|jr t||dS|r tj|rt|t|j|dS|j r+t |||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)rG)is_vcsr9is_existing_dirr]r;isdirr"rjrkis_filerlrPis_wheelr$r<)r2r3rErFrGfiler/r/r0 unpack_urls&    rscCsptj||j}tj|sdStd||r6z||W|Sty5t d|t |YdSw|S)zCheck 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.) r]r;joinfilenameexistsrUinforLr rVunlink)r2rFrG download_pathr/r/r0rKs"     rKcsPeZdZdZdedeedededededed e d ed ed ed eddffdd Z de ddfddZ de deddfddZ de defddZdedeefddZ d/dee deddfdd Z d/de dedefd!d"Z d/d#ee deddfd$d%Zde dedefd&d'Zde ddfd(d)Zde defd*d+Zde d,edefd-d.ZZS)0RequirementPreparerzPrepares a Requirement build_dirrFsrc_dirr)r'session progress_barr(require_hashes use_user_site lazy_wheel in_tree_buildr*Nc stt||_||_||_||_t|||_t|||_ ||_ ||_ ||_ | |_ | |_| |_| |_i|_d|_dS)N)r)superr@r|r{r'_sessionr _downloadr_batch_downloadr(rFr)rruse_lazy_wheelr _downloaded_previous_requirement_header) r?r{rFr|r)r'r}r~r(rrrr __class__r/r0r@s    zRequirementPreparer.__init__r&cCs|jjr|jsd}tt|jj}n d}t|jp|}||f|jkr-||f|_t |||jrNt t d|jj WddS1sGwYdSdS)z3Provide context for the requirement being prepared.z Processing %sz Collecting %szUsing cached %sN) r2rporiginal_link_is_in_wheel_cacherDrrkr&rrUrwrru)r?r&message informationr/r/r0_log_preparing_link3s  "z'RequirementPreparer._log_preparing_linkparallel_buildscCsj|jjrdS|jdus J|jr|jr|jj|_dS|j|jd|dt|jr3t d ||jdS)z1Ensure source_dir of a linked InstallRequirement.NT) autodeleterzpip 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.) r2rq source_dirrnrrkensure_has_source_dirr{r!rformat)r?r&rr/r/r0_ensure_link_req_src_dirDs"   z,RequirementPreparer._ensure_link_req_src_dircCsX|js |jddS|jjrt|jrt|jdur#|js#t |jddp+t S)NT)trust_internetF) rrGr2rmrrnr original_link is_pinnedr r)r?r&r/r/r0_get_linked_req_hashesis  z*RequirementPreparer._get_linked_req_hashesr2cCs|jsdS|jrtddS|js|jstd|dSt|j}t|j }t d||j |j ddd}zt|||jWStyPtd|YdSw) 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)rrrUdebugrprqrrurnamerwversionr4splitrrr)r?r2wheelrr4r/r/r0 _fetch_metadata_using_lazy_wheels2      z4RequirementPreparer._fetch_metadata_using_lazy_wheelFpartially_downloaded_reqsc Cstdddj}i}|D] }|jsJ|||j<q |||}|D]\}\}} td||||}||_q"|D]}|||q9dS)z>Download any requirements which were only fetched by metadata.r7TrHzDownloading link %s to %sN) r#r;r2rkeysrUrlocal_file_path_prepare_linked_requirement) r?rrrMlinks_to_fully_downloadr&batch_downloadr2filepath_r/r/r0_complete_partial_requirementss   z2RequirementPreparer._complete_partial_requirementscCs|jsJ|j}||tFd}|jdur(|jr(||}t|j|j|}|dur4||j|jj<n| |}|durId|_ |WdS| ||WdS1sYwYdS)z3Prepare a requirement to be obtained from req.link.NT) r2rrrFrqrrKrr4rneeds_more_preparationr)r?r&rr2rkrG wheel_distr/r/r0prepare_linked_requirements"     $z.RequirementPreparer.prepare_linked_requirementreqscCsdd|D}|D]&}|jdur/|jjr/||}t|j|j|}|dur/||j|jj<d|_q g}|D]}|jr?||q4| ||q4|j ||ddS)z,Prepare linked requirements more, if needed.cSsg|]}|jr|qSr/)r).0r&r/r/r0 szHRequirementPreparer.prepare_linked_requirements_more..NF)r) rFr2rqrrKrr4rappendrr)r?rrr&rGrkrr/r/r0 prepare_linked_requirements_mores$   z4RequirementPreparer.prepare_linked_requirements_morec Cs|jsJ|j}|||||}|r|jrd}n<|j|jvrFz t||j|j |j |}Wn(t yE}z t d |||d}~ww|j|j}|rS||t|dd}|r_|j|_t||j|j|j}|S)NzDCould not install requirement {} because of HTTP error {} for URL {})r<)r2rrrnrr4rrsrrrFr r rrLr:r;rr1r'r(r)) r?r&rr2rG local_fileexcrkdistr/r/r0rs>        z/RequirementPreparer._prepare_linked_requirementcCs|jdusJ|jdusJ|j}|js|r#|jr#||jdS|r/td|dS|jdur6dSt j |j|j }t j |sXt|j|t|}td|dSdS)NzENot copying link to destination directory since it is a directory: %szSaved %s)rFr2rmrneditablearchiverUrrr]r;rtrurvrScopyrrw)r?r&r2download_locationryr/r/r0save_linked_requirement*s(   z+RequirementPreparer.save_linked_requirementcCs|jsJdtd|t-|jrtd|||j| t ||j |j |j }||jWd|S1s@wY|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)rrUrwrrr rrr|update_editabler1r'r(r)check_if_existsr)r?r&rr/r/r0prepare_editable_requirementDs*   z0RequirementPreparer.prepare_editable_requirement skip_reasoncCs|jsJd|dusJd|jtd|||jjt|jr)tdt| WdS1s9wYdS)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)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_byrrUrwrrrrrr-)r?r&rr/r/r0prepare_installed_requirementbs   $z1RequirementPreparer.prepare_installed_requirement)F)rArBrC__doc__rDrboolrrrr@rrrrrrrrrrrrrrrr __classcell__r/r/rr0rzs     2 %  " !   ( rz)NN)Mrloggingr=r]rStypingrrrrpip._vendor.packaging.utilsrpip._internal.distributionsr%pip._internal.distributions.installedrpip._internal.exceptionsr r r r r rr"pip._internal.index.package_finderrpip._internal.metadatarpip._internal.models.linkrpip._internal.models.wheelrpip._internal.network.downloadrr pip._internal.network.lazy_wheelrrpip._internal.network.sessionrpip._internal.req.req_installrpip._internal.req.req_trackerrpip._internal.utils.filesystemrpip._internal.utils.hashesrrpip._internal.utils.loggingrpip._internal.utils.miscrr r!r"pip._internal.utils.temp_dirr#pip._internal.utils.unpackingr$pip._internal.vcsr% getLoggerrArUrr1rDr9r:rPrXrjrlrsrKrzr/r/r/r0s   $                  6