U ʗReY @sDdZddlZddlZddlZddlZddlmZmZmZm Z ddl m Z ddl m Z ddlmZddlmZmZmZmZmZmZmZddlmZdd lmZdd lmZdd lmZdd l m!Z!dd l"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3ddl4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:ddl;mZ>ddl?m@Z@eAeBZCe-e+eeDeDedddZEeeFeGddddZHGdd d ZId.ee$e eFe e2eId!d"d#ZJd/ee eFe e2eId$d%d&ZKd0eeFe$eGe eFe e2e eId'd(d)ZLeeFe e2e eFd$d*d+ZMGd,d-d-ZNdS)1z)Prepares a distribution for installation N)DictIterableListOptional)canonicalize_name))make_distribution_for_install_requirement)InstalledDistribution)DirectoryUrlHashUnsupported HashMismatch HashUnpinnedInstallationErrorNetworkConnectionErrorPreviousBuildDirErrorVcsHashUnsupported) PackageFinder)BaseDistribution) ArchiveInfo)Link)Wheel)BatchDownloader Downloader)HTTPRangeRequestUnsupporteddist_from_wheel_url) PipSession) BuildTracker)InstallRequirement)direct_url_for_editabledirect_url_from_link)Hashes MissingHashes) indent_log) display_path hash_filehide_urlis_installable_dir) TempDirectory) unpack_file)vcs)req build_trackerfinderbuild_isolationcheck_build_depsreturnc Cs4t|}||||||W5QRX|S)z(Prepare a distribution for installation.)rtrackprepare_distribution_metadataget_metadata_distribution)r(r)r*r+r, abstract_distr2/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_internal/operations/prepare.py_get_prepared_distribution:s r4)linklocation verbosityr-cCs2t|j}|dk st|j|t|j|ddS)N)urlr7)r'get_backend_for_schemeschemeAssertionErrorunpackr#r8)r5r6r7 vcs_backendr2r2r3unpack_vcs_linkJs  r>c@s"eZdZeeeddddZdS)FileN)path content_typer-cCs*||_|dkr t|d|_n||_dS)Nr)r@ mimetypes guess_typerA)selfr@rAr2r2r3__init__Qsz File.__init__)__name__ __module__ __qualname__strrrEr2r2r2r3r?Psr?)r5download download_dirhashesr-cCsVtddd}d}|r t|||}|r.|}d}n|||j\}}|rL||t||S)Nr<Tkindglobally_managed)r%_check_download_dirr@check_against_pathr?)r5rJrKrLtemp_diralready_downloaded_path from_pathrAr2r2r3 get_http_urlYs   rU)r5rKrLr-cCs<d}|rt|||}|r|}n|j}|r2||t|dS)z'Get file and optionally check its hash.N)rP file_pathrQr?)r5rKrLrSrTr2r2r3 get_file_urlqs  rW)r5r6rJr7rKrLr-cCsd|jrt|||ddS|r$t|jr:t|||d}nt||||d}|js`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. )r7N)rL) is_vcsr>is_existing_dirr;is_filerWrUis_wheelr&r@rA)r5r6rJr7rKrLfiler2r2r3 unpack_urls  r]cCsptj||j}tj|s dStd||rlz||Wn,tk rjt d|t |YdSX|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.) osr@joinfilenameexistsloggerinforQr warningunlink)r5rKrL download_pathr2r2r3rPs   rPcseZdZdZeeeeeeeeee eeee ddfdd Z e ddddZ e edd d d Ze edd d ZeeedddZd#ee eddddZd$e eed ddZd%ee eddddZe eed ddZe ddddZe edddZe eed d!d"ZZS)&RequirementPreparerzPrepares a RequirementN) build_dirrKsrc_dirr+r,r)session progress_barr*require_hashes use_user_site lazy_wheelr7r-cszt||_||_||_||_t|||_t|||_ | |_ ||_ ||_ ||_ | |_| |_| |_| |_i|_d|_dS)N)ro)superrErirhr)_sessionr _downloadr_batch_downloadr*rKr+r,rlrmuse_lazy_wheelr7 _downloaded_previous_requirement_header)rDrhrKrir+r,r)rjrkr*rlrmrnr7 __class__r2r3rEs"   zRequirementPreparer.__init__)r(r-c Cs|jjr$|js$d}tt|jj}nd}t|jp2|}||f|jkrZ||f|_t |||jrt t d|jj W5QRXdS)z3Provide context for the requirement being prepared.z Processing %sz Collecting %szUsing cached %sN) r5rZoriginal_link_is_in_wheel_cacherIr!rVr(rvrbrcr r`)rDr(message informationr2r2r3_log_preparing_links  z'RequirementPreparer._log_preparing_link)r(parallel_buildsr-cCsd|jjr dS|jdkst|jr2|jj|_dS|j|jd|dt|jr`t d ||jdS)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.) r5r[ source_dirr;rYrVensure_has_source_dirrhr$rformat)rDr(r}r2r2r3_ensure_link_req_src_dirs$   z,RequirementPreparer._ensure_link_req_src_dircCsX|js|jddS|jjr t|jr0t|jdkrF|jsFt |jddpVt S)NT)trust_internetF) rlrLr5rXrrYr original_link is_pinnedr r)rDr(r2r2r3_get_linked_req_hashes=s  z*RequirementPreparer._get_linked_req_hashes)r5r-cCs|js dS|jrtddS|js*|js:td|dSt|j}t|j }t d||j |j ddd}zt|||jWStk rtd|YdSXdS) 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)rtrlrbdebugrZr[rr`rnamercversionr8splitrrqr)rDr5wheelrr8r2r2r3 _fetch_metadata_using_lazy_wheel]s0     z4RequirementPreparer._fetch_metadata_using_lazy_wheelF)partially_downloaded_reqsr}r-c Cstdddj}i}|D]}|js$t|||j<q|||}|D](\}\}} td||||}||_qD|D]}| ||qrdS)z>Download any requirements which were only fetched by metadata.r<TrMzDownloading link %s to %sN) r%r@r5r;rskeysrbrlocal_file_path_prepare_linked_requirement) rDrr}rRlinks_to_fully_downloadr(batch_downloadr5filepath_r2r2r3_complete_partial_requirements|s  z2RequirementPreparer._complete_partial_requirementsc Cs|js t|j}||td}|jdk rP|jrP||}t|j|j|}|dk rh||j|jj <n(| |}|dk rd|_ |W5QRS| ||W5QRSQRXdS)z3Prepare a requirement to be obtained from req.link.NT) r5r;r|r rKr[rrPrur8rneeds_more_preparationr)rDr(r}r5rVrL wheel_distr2r2r3prepare_linked_requirements    z.RequirementPreparer.prepare_linked_requirement)reqsr}r-cCsdd|D}|D]L}|jdk r|jjr||}t|j|j|}|dk r||j|jj<d|_qg}|D]"}|jr~||qh| ||qh|j ||ddS)z,Prepare linked requirements more, if needed.cSsg|]}|jr|qSr2)r).0r(r2r2r3 szHRequirementPreparer.prepare_linked_requirements_more..NF)r}) rKr5r[rrPrur8rappendrr)rDrr}r(rLrVrr2r2r3 prepare_linked_requirements_mores"  z4RequirementPreparer.prepare_linked_requirements_morec CsN|js t|j}|||||}|r4d}n|j|jkrzt||j|j |j |j |}Wqt k r}zt d|||W5d}~XYqXn&|j|j}|r||t|dd}|jdkr$|jrtt||j|_t|jjtr$|jjjs$|r$t|jd}d||jj_|r2|j|_t||j|j|j|j } | S)NzDCould not install requirement {} because of HTTP error {} for URL {})rArzsha256=)!r5r;rrrYr8rur]rrrr7rKr r rrQr? download_infoeditabler isinstancercrhashr"r@ hexdigestrr4r)r*r+r,) rDr(r}r5rL local_fileexcrVrdistr2r2r3rsb          z/RequirementPreparer._prepare_linked_requirementcCs|jdk st|jdk st|j}|js6|rF|jrF||jdS|r^td|dS|j dkrldSt j |j|j }t j |st|j |t|}td|dS)NzENot copying link to destination directory since it is a directory: %szSaved %s)rKr;r5rXrYrarchiverbrrr^r@r_r`rashutilcopyr!rc)rDr(r5download_locationrfr2r2r3save_linked_requirements&   z+RequirementPreparer.save_linked_requirementc Cs|jstdtd|th|jr6td|||j | |j sTtt |j |_t||j|j|j|j}||jW5QRX|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.)rr;rbrcr rlr rrriupdate_editablerrunpacked_source_directoryrr4r)r*r+r,check_if_existsrm)rDr(rr2r2r3prepare_editable_requirement/s,    z0RequirementPreparer.prepare_editable_requirement)r( skip_reasonr-c Cst|jstd|dk s&td|jtd|||jjt*|jrRtdt | W5QRSQRXdS)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_byr;rrbrcrr rlrrr0)rDr(rr2r2r3prepare_installed_requirementPs$ z1RequirementPreparer.prepare_installed_requirement)F)F)F)rFrGrH__doc__rIrboolrrrintrErr|rrrrrrrrrrrrrr __classcell__r2r2rwr3rgsn6 %" " !   ? #rg)NN)NN)NN)OrloggingrBr^rtypingrrrrpip._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.direct_urlrpip._internal.models.linkrpip._internal.models.wheelrpip._internal.network.downloadrr pip._internal.network.lazy_wheelrrpip._internal.network.sessionr,pip._internal.operations.build.build_trackerrZpip._internal.req.req_installr&pip._internal.utils.direct_url_helpersrrpip._internal.utils.hashesrrpip._internal.utils.loggingr pip._internal.utils.miscr!r"r#r$pip._internal.utils.temp_dirr%pip._internal.utils.unpackingr&pip._internal.vcsr' getLoggerrFrbrr4rIrr>r?rUrWr]rPrgr2r2r2r3s   $                  ,