3 ig]@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_isolationreturnc Cs2t|}|j||j||WdQRX|jS)z(Prepare a distribution for installation.N)rtrackZprepare_distribution_metadataget_metadata_distribution)r&r'r(r) abstract_distr.?/tmp/pip-build-88gy_88q/pip/pip/_internal/operations/prepare.py_get_prepared_distribution1s r0)linklocationr*cCs0tj|j}|dk st|j|t|jddS)N)url)r%Zget_backend_for_schemeschemeAssertionErrorunpackr r3)r1r2 vcs_backendr.r.r/unpack_vcs_link>s  r8c@s"eZdZeeeddddZdS)FileN)path content_typer*cCs*||_|dkr tj|d|_n||_dS)Nr)r: mimetypes guess_typer;)selfr:r;r.r.r/__init__Esz File.__init__)__name__ __module__ __qualname__strrr?r.r.r.r/r9Dsr9)r1download download_dirhashesr*cCsVtddd}d}|r t|||}|r.|}d}n|||j\}}|rL|j|t||S)Nr6T)kindglobally_managed)r#_check_download_dirr:check_against_pathr9)r1rDrErFtemp_diralready_downloaded_path from_pathr;r.r.r/ get_http_urlMs   rN)srcdestr*cCsLyt||Wn8tjk rF}ztjdt|||WYdd}~XnXdS)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)rshutilSpecialFileErrorloggerwarningrC)rOrPer.r.r/_copy2_ignoring_special_filesesrV)sourcetargetr*cs^tjj|}tjj|tjj|tttttdfdd }tj||dt ddS)N)dnamesr*cs6g}|kr|ddg7}tjj|kr2|g7}|S)Nz.toxz.nox)osr:abspath)rYrZZskipped)rWtarget_basenametarget_dirnamer.r/ignore~s   z!_copy_source_tree..ignoreT)r_symlinks copy_function) r[r:r\basenamedirnamerCrrQcopytreerV)rWrXZtarget_abspathr_r.)rWr]r^r/_copy_source_treeys   "re)r1rErFr*cCs<d}|rt|||}|r|}n|j}|r2|j|t|dS)z'Get file and optionally check its hash.N)rI file_pathrJr9)r1rErFrLrMr.r.r/ get_file_urls  rg)r1r2rDrErFr*cCs|jrt||dS|jr@tjj|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)rF)is_vcsr8is_existing_dirr[r:isdirr"rerfis_filergrNis_wheelr$r;)r1r2rDrErFfiler.r.r/ unpack_urls$    rnc Csntjj||j}tjj|s dStjd||rjy|j|Wn*tk rhtj d|tj |dSX|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:joinfilenameexistsrSinforJr rTunlink)r1rErF download_pathr.r.r/rIs   rIcseZdZdZeeeeeeeee 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_dirrEsrc_dirr)r'session progress_barr(require_hashes use_user_site lazy_wheel in_tree_buildr*c sttj||_||_||_||_t|||_t|||_ ||_ ||_ ||_ | |_ | |_| |_| |_i|_d|_dS)N)r~r~)superr?rwrvr'_sessionr _downloadr_batch_downloadr(rEr)rzr{use_lazy_wheelr} _downloaded_previous_requirement_header) r>rvrErwr)r'rxryr(rzr{r|r}) __class__r.r/r?s    zRequirementPreparer.__init__)r&r*c Cs|jjr&|j r&d}tt|jj}nd}t|jp4|}||f|jkr\||f|_tj |||jrt tj d|jj WdQRXdS)z3Provide context for the requirement being prepared.z Processing %sz Collecting %szUsing cached %sN) r1rkZoriginal_link_is_in_wheel_cacherCrrfr&rrSrrrrp)r>r&messageZ informationr.r.r/_log_preparing_link3s  z'RequirementPreparer._log_preparing_link)r&parallel_buildsr*cCsj|jjr dS|jdkst|jjr8|jr8|jj|_dS|j|jd|dt |jrft dj ||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.) r1rl source_dirr5rir}rfensure_has_source_dirrvr!rformat)r>r&rr.r.r/_ensure_link_req_src_dirDs  z,RequirementPreparer._ensure_link_req_src_dircCsZ|js|jddS|jjr t|jjr0t|jdkrH|j rHt |jddpXt S)NT)trust_internetF) rzrFr1rhrrir original_link is_pinnedr r)r>r&r.r.r/_get_linked_req_hashesis  z*RequirementPreparer._get_linked_req_hashes)r1r*c Cs|js dS|jrtjddS|js,|j rLazy 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)rrzrSdebugrkrlrrprnamerrversionr3splitrrr)r>r1wheelrr3r.r.r/ _fetch_metadata_using_lazy_wheels,    z4RequirementPreparer._fetch_metadata_using_lazy_wheelF)partially_downloaded_reqsrr*c Cstdddj}i}x |D]}|js&t|||j<qW|j|j|}x0|D](\}\}} tjd||||}||_qJWx|D]}|j ||q|WdS)z>Download any requirements which were only fetched by metadata.r6T)rGrHzDownloading link %s to %sN) r#r:r1r5rkeysrSrlocal_file_path_prepare_linked_requirement) r>rrrKZlinks_to_fully_downloadr&Zbatch_downloadr1filepath_r.r.r/_complete_partial_requirementss    z2RequirementPreparer._complete_partial_requirementsc Cs|js t|j}|j|tpd}|jdk rP|jrP|j|}t|j|j|}|dk rh||j|jj <n|j |}|dk rd|_ |S|j ||SQRXdS)z3Prepare a requirement to be obtained from req.link.NT) r1r5rrrErlrrIrr3rneeds_more_preparationr)r>r&rr1rfrFZ wheel_distr.r.r/prepare_linked_requirements    z.RequirementPreparer.prepare_linked_requirement)reqsrr*cCsdd|D}xT|D]L}|jdk r|jjr|j|}t|j|j|}|dk r||j|jj<d|_qWg}x*|D]"}|jr|j|qn|j ||qnW|j ||ddS)z,Prepare linked requirements more, if needed.cSsg|]}|jr|qSr.)r).0r&r.r.r/ szHRequirementPreparer.prepare_linked_requirements_more..NF)r) rEr1rlrrIrr3rappendrr)r>rrr&rFrfrr.r.r/ prepare_linked_requirements_mores      z4RequirementPreparer.prepare_linked_requirements_morec Cs|js t|j}|j|||j|}|jr:|jr:d}n|j|jkryt||j |j |j |}Wqt k r}zt dj|||WYdd}~XqXn&|j|j}|r|j|t|dd}|r|j|_t||j|j|j}|S)NzDCould not install requirement {} because of HTTP error {} for URL {})r;)r1r5rrrir}r3rrnrrrEr r rrJr9r:rr0r'r(r)) r>r&rr1rF local_fileexcrfdistr.r.r/rs4        z/RequirementPreparer._prepare_linked_requirementcCs|jdk st|jdk st|j}|js6|jrF|jrF|j|jdS|jr^tjd|dS|j dkrldSt j j |j|j }t j j|stj|j |t|}tjd|dS)NzENot copying link to destination directory since it is a directory: %szSaved %s)rEr5r1rhrieditablearchiverSrrr[r:rorprqrQcopyrrr)r>r&r1download_locationrtr.r.r/save_linked_requirement*s$   z+RequirementPreparer.save_linked_requirementc Csx|jstdtjd|tN|jr6tdj||j|j |j t ||j |j |j}|j|jWdQRX|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)rr5rSrrrrzr rrrwupdate_editabler0r'r(r)check_if_existsr{)r>r&rr.r.r/prepare_editable_requirementDs   z0RequirementPreparer.prepare_editable_requirement)r& skip_reasonr*c Csh|jstd|dk s&tdj|jtjd|||jjt|jrRtjdt |j SQRXdS)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_byr5rrSrrrrrzrrr,)r>r&rr.r.r/prepare_installed_requirementbs  z1RequirementPreparer.prepare_installed_requirement)F)F)F)r@rArB__doc__rCrboolrrrr?rrrrrrrrrrrrrrrr __classcell__r.r.)rr/rusD$#"  &ru)NN)NN)NN)Mrloggingr<r[rQZtypingrrrrpip._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% getLoggerr@rSrr0rCr8r9rNrVrergrnrIrur.r.r.r/s\   $              1