a Ra]@sRdZddlZddlZddlZddlZddlmZmZmZm 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@e)e+eeAedddZBeeCddddZDGdddZEd3ee"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/d0ZKGd1d2d2ZLdS)6z)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)vcs)req req_trackerfinderbuild_isolationreturncCsFt|}|||||Wdn1s40Y|S)z(Prepare a distribution for installation.N)rZtrackZprepare_distribution_metadataget_metadata_distribution)r&r'r(r)Z abstract_distr,Q/opt/alt/python39/lib/python3.9/site-packages/pip/_internal/operations/prepare.py_get_prepared_distribution1s *r.)linklocationr*cCs$t|j}|j|t|jddS)N)url)r%Zget_backend_for_schemeschemeunpackr r1)r/r0Z vcs_backendr,r,r-unpack_vcs_link>s r4c@s"eZdZeeeddddZdS)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_dirhashesr*cCsVtddd}d}|r t|||}|r.|}d}n|||j\}}|rL||t||S)Nr3TkindZglobally_managed)r#_check_download_dirr6check_against_pathr5)r/r?r@rAtemp_diralready_downloaded_path from_pathr7r,r,r- get_http_urlMs   rI)srcdestr*c CsNzt||Wn:tjyH}z tdt|||WYd}~n d}~00dS)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)rshutilZSpecialFileErrorloggerwarningr>)rJrKer,r,r-_copy2_ignoring_special_filesesrP)sourcetargetr*cs^tj|}tj|tj|tttttdfdd }tj||dt ddS)N)dnamesr*cs6g}|kr|ddg7}tj|kr2|g7}|S)Nz.toxz.nox)osr6abspath)rSrTZskippedrQZtarget_basenameZtarget_dirnamer,r-ignore~s   z!_copy_source_tree..ignoreT)rXZsymlinksZ copy_function) rUr6rVbasenamedirnamer>rrLZcopytreerP)rQrRZtarget_abspathrXr,rWr-_copy_source_treeys   "r[)r/r@rAr*cCs<d}|rt|||}|r|}n|j}|r2||t|dS)z'Get file and optionally check its hash.N)rD file_pathrEr5)r/r@rArGrHr,r,r- get_file_urls  r])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_vcsr4is_existing_dirrUr6isdirr"r[r\is_filer]rIis_wheelr$r7)r/r0r?r@rAfiler,r,r- unpack_urls&     rdcCsntj||j}tj|s dStd||rjz||Wn*tyht d|t |YdS0|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.) rUr6joinfilenameexistsrMinforEr rNunlink)r/r@rA download_pathr,r,r-rDs    rDcseZdZdZeeeeeeeee eeeedd fdd Z e ddddZ e edd d d Z e edd d ZeeedddZd#ee eddddZd$e eed ddZd%ee eddddZe eed ddZe ddddZe edddZe eed d!d"ZZS)&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)rt)superr:rmrlr'_sessionr _downloadr_batch_downloadr(r@r)rprquse_lazy_wheelrs _downloaded_previous_requirement_header) r9rlr@rmr)r'rnror(rprqrrrs __class__r,r-r:s    zRequirementPreparer.__init__)r&r*cCs|jjr$|js$d}tt|jj}nd}t|jp2|}||f|jkrZ||f|_t |||jrt t d|jj Wdn1s0YdS)z3Provide context for the requirement being prepared.z Processing %sz Collecting %szUsing cached %sN) r/raZoriginal_link_is_in_wheel_cacher>rr\r&r{rMrhrrf)r9r&messageZ informationr,r,r-_log_preparing_link3s  z'RequirementPreparer._log_preparing_link)r&parallel_buildsr*cCs\|jjr dS|jr*|jr*|jj|_dS|j|jd|dt|jrXt d ||jdS)z1Ensure source_dir of a linked InstallRequirement.NT)Z 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.) r/rbr_rsr\ source_dirensure_has_source_dirrlr!rformat)r9r&rr,r,r-_ensure_link_req_src_dirDs   z,RequirementPreparer._ensure_link_req_src_dircCsX|js|jddS|jjr t|jr0t|jdurF|jsFt |jddpVt S)NT)Ztrust_internetF) rprAr/r^rr_r Z original_linkZ is_pinnedr r)r9r&r,r,r-_get_linked_req_hashesis  z*RequirementPreparer._get_linked_req_hashes)r/r*cCs|js dS|jrtddS|js*|js:td|dSt|j}t|j }t d||j |j ddd}zt|||jWStytd|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)ryrprMdebugrarbrrfrnamerhversionr1splitrrvr)r9r/Zwheelrr1r,r,r- _fetch_metadata_using_lazy_wheels0      z4RequirementPreparer._fetch_metadata_using_lazy_wheelF)partially_downloaded_reqsrr*c Cs~tdddj}i}|D]}|||j<q|||}|D](\}\}} td||||}||_q:|D]}|||qhdS)z>Download any requirements which were only fetched by metadata.r3TrBzDownloading link %s to %sN) r#r6r/rxkeysrMrlocal_file_path_prepare_linked_requirement) r9rrrFZlinks_to_fully_downloadr&Zbatch_downloadr/filepath_r,r,r-_complete_partial_requirementss z2RequirementPreparer._complete_partial_requirementscCs|j}||td}|jdurF|jrF||}t|j|j|}|dur^||j|jj<n*| |}|durd|_ |WdS| ||WdS1s0YdS)z3Prepare a requirement to be obtained from req.link.NT) r/rrr@rbrrDrzr1rneeds_more_preparationr)r9r&rr/r\rAZ wheel_distr,r,r-prepare_linked_requirements   z.RequirementPreparer.prepare_linked_requirement)reqsrr*cCsdd|D}|D]L}|jdur|jjr||}t|j|j|}|dur||j|jj<d|_qg}|D]"}|jr~||qh| ||qh|j ||ddS)z,Prepare linked requirements more, if needed.cSsg|]}|jr|qSr,)r).0r&r,r,r- zHRequirementPreparer.prepare_linked_requirements_more..NF)r) r@r/rbrrDrzr1rappendrr)r9rrr&rAr\rr,r,r- prepare_linked_requirements_mores"  z4RequirementPreparer.prepare_linked_requirements_morec Cs|j}|||||}|r0|jr0d}n|j|jvrzt||j|j |j |}Wqt y}zt d |||WYd}~qd}~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/rrr_rsr1rzrdrrwr@r r rrEr5r6rr.r'r(r)) r9r&rr/rAZ local_fileexcr\distr,r,r-rs:      z/RequirementPreparer._prepare_linked_requirementcCs|j}|js|r*|jr*||jdS|rBtd|dS|jdurPdSt j |j|j }t j |st|j|t|}td|dS)NzENot copying link to destination directory since it is a directory: %szSaved %s)r/r^r_Zeditablearchiver@rMrrrUr6rerfrgrLcopyrrh)r9r&r/Zdownload_locationrjr,r,r-save_linked_requirement*s"   z+RequirementPreparer.save_linked_requirementcCs~td|tX|jr(td|||j|t ||j |j |j }| |jWdn1sp0Y|S)z Prepare an editable requirement.z Obtaining %szoThe editable requirement {} cannot be installed when requiring hashes, because there is no single file to hash.N)rMrhrrpr rrrmZupdate_editabler.r'r(r)Zcheck_if_existsrq)r9r&rr,r,r-prepare_editable_requirementDs$  *z0RequirementPreparer.prepare_editable_requirement)r& skip_reasonr*cCsZtd|||jjt,|jr,tdt|WdS1sL0YdS)z)Prepare an already-installed requirement.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.N) rMrhZ satisfied_byrrrprrr+)r9r&rr,r,r-prepare_installed_requirementbs  z1RequirementPreparer.prepare_installed_requirement)F)F)F)r;r<r=__doc__r>rboolrrrr:rrrrrrrrrrrrrrrr __classcell__r,r,r|r-rksd2 %" " !   ( rk)NN)NN)NN)MrZloggingr8rUrLtypingrrrrZpip._vendor.packaging.utilsrZpip._internal.distributionsrZ%pip._internal.distributions.installedrZpip._internal.exceptionsr r r r 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;rMrr.r>r4r5rIrPr[r]rdrDrkr,r,r,r-s   $                  7