o gQ^@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 eCd!eDddfd"d#ZEGd$d%d%ZF  d;ded&e"d'e eCd(e e/deFf d)d*ZGd+eCd,eCddfd-d.ZHd/eCd0eCddfd1d2ZI d;ded'e eCd(e e/deFfd3d4ZJ  d;ded eCd&e"d!eDd'e eCd(e e/de eFfd5d6ZKded'eCd(e e/de eCfd7d8ZLGd9d:d:ZMdS)s  r:c@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__strrrAr/r/r/r0r;Dsr;download download_dirhashescCsVtddd}d}|rt|||}|r|}d}n|||j\}}|r&||t||S)Nr8Tkindglobally_managed)r#_check_download_dirr<check_against_pathr;)r2rFrGrHtemp_diralready_downloaded_path from_pathr=r/r/r0 get_http_urlMs    rQsrcdestc 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)rshutilSpecialFileErrorloggerwarningrE)rRrSer/r/r0_copy2_ignoring_special_filesesrYsourcetargetcsbtj|}tj|tj|dtdttdttffdd }tj||dt ddS)Ndnamesr*cs6g}|kr |ddg7}tj|kr|g7}|S)Nz.toxz.nox)osr<abspath)r\r]skippedrZtarget_basenametarget_dirnamer/r0ignore~s   z!_copy_source_tree..ignoreT)rdsymlinks copy_function) r^r<r_basenamedirnamerErrTcopytreerY)rZr[target_abspathrdr/rar0_copy_source_treeys   & rkcCs<d}|r t|||}|r|}n|j}|r||t|dS)z'Get file and optionally check its hash.N)rL file_pathrMr;)r2rGrHrOrPr/r/r0 get_file_urls   rmcCs|jr t|||ddS|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. )r4N)rH)is_vcsr:is_existing_dirr^r<isdirr"rkrlis_filermrQis_wheelr$r=)r2r3rFr4rGrHfiler/r/r0 unpack_urls&   rtcCsptj||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<joinfilenameexistsrVinforMr rWunlink)r2rGrH download_pathr/r/r0rLs"     rLcsTeZdZdZdedeedededededed e d ed ed ed e deddffdd Z de ddfddZ de deddfddZde defddZdedeefddZ d0dee deddfd d!Z d0de dedefd"d#Z d0d$ee deddfd%d&Zde dedefd'd(Zde ddfd)d*Zde defd+d,Zde d-edefd.d/ZZS)1RequirementPreparerzPrepares a Requirement build_dirrGsrc_dirr)r'session progress_barr(require_hashes use_user_site lazy_wheelr4 in_tree_buildr*Ncszt||_||_||_||_t|||_t|||_ ||_ ||_ ||_ | |_ | |_| |_| |_| |_i|_d|_dS)N)r)superrAr}r|r'_sessionr _downloadr_batch_downloadr(rGr)rruse_lazy_wheelr4r _downloaded_previous_requirement_header)r@r|rGr}r)r'r~rr(rrrr4r __class__r/r0rAs"    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) r2rqoriginal_link_is_in_wheel_cacherErrlr&rrVrxrrv)r@r&message informationr/r/r0_log_preparing_link8s  "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.) r2rr source_dirrorrlensure_has_source_dirr|r!rformat)r@r&rr/r/r0_ensure_link_req_src_dirIs"   z,RequirementPreparer._ensure_link_req_src_dircCsX|js |jddS|jjrt|jrt|jdur#|js#t |jddp+t S)NT)trust_internetF) rrHr2rnrror original_link is_pinnedr r)r@r&r/r/r0_get_linked_req_hashesns  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)rrrVdebugrqrrrrvrnamerxversionr5splitrrr)r@r2wheelrr5r/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.r8TrIzDownloading link %s to %sN) r#r<r2rkeysrVrlocal_file_path_prepare_linked_requirement) r@rrrNlinks_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) r2rrrGrrrrLrr5rneeds_more_preparationr)r@r&rr2rlrH 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) rGr2rrrrLrr5rappendrr)r@rrr&rHrlrr/r/r0 prepare_linked_requirements_mores$   z4RequirementPreparer.prepare_linked_requirements_morec Cs|jsJ|j}|||||}|r|jrd}n>|j|jvrHzt||j|j |j |j |}Wn(t yG}z t d|||d}~ww|j|j}|rU||t|dd}|ra|j|_t||j|j|j}|S)NzDCould not install requirement {} because of HTTP error {} for URL {})r=)r2rrrorr5rrtrrr4rGr r rrMr;r<rr1r'r(r)) r@r&rr2rH local_fileexcrldistr/r/r0rsH        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)rGr2rnroeditablearchiverVrrr^r<rurvrwrTcopyrrx)r@r&r2download_locationrzr/r/r0save_linked_requirement4s(   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)rrVrxrrr rrr}update_editabler1r'r(r)check_if_existsr)r@r&rr/r/r0prepare_editable_requirementNs*   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_byrrVrxrrrrrr-)r@r&rr/r/r0prepare_installed_requirementls   $z1RequirementPreparer.prepare_installed_requirement)F)rBrCrD__doc__rErboolrrrintrArrrrrrrrrrrrrrrr __classcell__r/r/rr0r{s     6 %  " !   - r{)NN)Nrloggingr>r^rTtypingrrrrpip._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% getLoggerrBrVrr1rErr:r;rQrYrkrmrtrLr{r/r/r/r0s   $                  7