U jac@sdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZddlmZddlmZmZmZmZmZmZmZdd lmZdd lmZdd lm Z dd l!m"Z"m#Z#dd l$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2m3Z3ddl4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:ddl;mZ>ddl?m@Z@eAeBZCddZDddZEGdddZFd-dd ZGd!d"ZHd#d$ZId.d%d&ZJd/d'd(ZKd)d*ZLGd+d,d,ZMdS)0z)Prepares a distribution for installation N)DictIterableListOptionalTuple)canonicalize_name) Distribution))make_distribution_for_install_requirement)InstalledDistribution)DirectoryUrlHashUnsupported HashMismatch HashUnpinnedInstallationErrorNetworkConnectionErrorPreviousBuildDirErrorVcsHashUnsupported) PackageFinder)Link)Wheel)BatchDownloader Downloader)HTTPRangeRequestUnsupporteddist_from_wheel_url) PipSession)InstallRequirement)RequirementTracker) deprecated) copy2_fixed)Hashes MissingHashes) indent_log) display_pathhide_urlis_installable_dirrmtree) TempDirectory) unpack_file)vcsc Cs2t|}|||||W5QRX|S)z(Prepare a distribution for installation.)r trackprepare_distribution_metadataget_pkg_resources_distribution)req req_trackerfinderbuild_isolation abstract_distr0x/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-bug3gbve/pip/_internal/operations/prepare.py_get_prepared_distribution2s r2cCs0t|j}|dk st|j|t|jddS)N)url)r'get_backend_for_schemeschemeAssertionErrorunpackr"r3)linklocation vcs_backendr0r0r1unpack_vcs_link@s  r;c@seZdZddZdS)FilecCs*||_|dkr t|d|_n||_dS)Nr)path mimetypes guess_type content_type)selfr=r@r0r0r1__init__Isz File.__init__N)__name__ __module__ __qualname__rBr0r0r0r1r<Gsr<cCsVtddd}d}|r t|||}|r.|}d}n|||j\}}|rL||t||S)Nr7Tkindglobally_managed)r%_check_download_dirr=check_against_pathr<)r8download download_dirhashestemp_diralready_downloaded_path from_pathr@r0r0r1 get_http_urlRs  rQc CsLzt||Wn8tjk rF}ztdt|||W5d}~XYnXdS)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)rshutilSpecialFileErrorloggerwarningstr)srcdester0r0r1_copy2_ignoring_special_filesmsrZcsLtj|}tj|tj|fdd}tj||dtddS)Ncs6g}|kr|ddg7}tj|kr2|g7}|S)Nz.toxz.nox)osr=abspath)dnamesskippedsourcetarget_basenametarget_dirnamer0r1ignores   z!_copy_source_tree..ignoreT)rdsymlinks copy_function)r[r=r\basenamedirnamerRcopytreerZ)ratargettarget_abspathrdr0r`r1_copy_source_trees   rlcCs<d}|rt|||}|r|}n|j}|r2||t|dS)z,Get file and optionally check its hash. N)rI file_pathrJr<)r8rLrMrOrPr0r0r1 get_file_urls  rncCs|jrt||dS|rPtdddddtj|r@t|t|j |dS|j rft |||d}nt ||||d}|j st|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. NzA future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default. z21.3i) replacementgone_inissue)rM)is_vcsr;is_existing_dirrr[r=isdirr$rlrmis_filernrQis_wheelr&r@)r8r9rKrLrMfiler0r0r1 unpack_urls2    rxcCsptj||j}tj|s dStd||rlz||Wn,tk rjt d|t |YdSX|S)z Check 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=joinfilenameexistsrTinforJr rUunlink)r8rLrM download_pathr0r0r1rIs   rIcs~eZdZdZfddZddZddZdd Zd d Zdd dZ dddZ dddZ ddZ ddZ ddZddZZS)RequirementPreparerzPrepares a Requirement c stt||_||_||_||_t|||_t|||_ ||_ ||_ ||_ | |_ | |_| |_| |_i|_d|_dS)N)r)superrBsrc_dir build_dirr,_sessionr _downloadr_batch_downloadr-rLr.require_hashes use_user_siteuse_lazy_wheel in_tree_build _downloaded_previous_requirement_header) rArrLrr.r,session progress_barr-rrZ lazy_wheelr __class__r0r1rBs    zRequirementPreparer.__init__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) r8ruoriginal_link_is_in_wheel_cacherVr!rmr+rrTr|r rz)rAr+messageZ informationr0r0r1_log_preparing_linkOs  z'RequirementPreparer._log_preparing_linkcCsj|jjr dS|jdkst|jr8|jr8|jj|_dS|j|jd|dt |jrft d ||jdS)z1Ensure source_dir of a linked InstallRequirement.NT) autodeleteparallel_buildszpip 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.) r8rv source_dirr6rsrrmensure_has_source_dirrr#rformat)rAr+rr0r0r1_ensure_link_req_src_diras$  z,RequirementPreparer._ensure_link_req_src_dircCsX|js|jddS|jjr t|jr0t|jdkrF|jsFt |jddpVt S)NT)trust_internetF) rrMr8rrrrsr original_link is_pinnedr r)rAr+r0r0r1_get_linked_req_hashess  z*RequirementPreparer._get_linked_req_hashescCs|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)rrrTdebugrurvrrzrnamer|versionr3splitrrr)rAr8wheelrr3r0r0r1 _fetch_metadata_using_lazy_wheels0     z4RequirementPreparer._fetch_metadata_using_lazy_wheelFc Cstdddj}i}|D]}|js$t|||j<q|||}|D](\}\}} td||||}||_qD|D]}| ||qrdS)z>Download any requirements which were only fetched by metadata.r7TrFzDownloading link %s to %sN) r%r=r8r6rkeysrTrlocal_file_path_prepare_linked_requirement) rApartially_downloaded_reqsrrNZlinks_to_fully_downloadr+Zbatch_downloadr8filepath_r0r0r1_complete_partial_requirementss   z2RequirementPreparer._complete_partial_requirementsc Cs|js t|j}||td}|jdk rP|jrP||}t|j|j|}|dk rl|df|j|jj <n(| |}|dk rd|_ |W5QRS| ||W5QRSQRXdS)z3Prepare a requirement to be obtained from req.link.NT) r8r6rr rLrvrrIrr3rneeds_more_preparationr)rAr+rr8rmrMZ wheel_distr0r0r1prepare_linked_requirements    z.RequirementPreparer.prepare_linked_requirementcCsdd|D}|D]P}|jdk r|jjr||}t|j|j|}|dk r|df|j|jj<d|_qg}|D]"}|jr||ql| ||ql|j ||ddS)z,Prepare linked requirements more, if needed.cSsg|]}|jr|qSr0)r).0r+r0r0r1 szHRequirementPreparer.prepare_linked_requirements_more..NF)r) rLr8rvrrIrr3rappendrr)rAreqsrr+rMrmrr0r0r1 prepare_linked_requirements_mores"  z4RequirementPreparer.prepare_linked_requirements_morec Cs|js t|j}|||||}|r:|jr:d}n|j|jkrzt||j |j |j |}Wqt k r}zt d|||W5d}~XYqXn(|j|j\}}|r||t||}|r|j|_t||j|j|j} | S)NzDCould not install requirement {} because of HTTP error {} for URL {})r8r6rrrsrr3rrxrrrLrrrrJr<r=rr2r,r-r.) rAr+rr8rM local_fileexcrmr@distr0r0r1rsH      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)rLr6r8rrrseditablearchiverTrrr[r=ryrzr{rRcopyr!r|)rAr+r8download_locationr~r0r0r1save_linked_requirement?s&   z+RequirementPreparer.save_linked_requirementc Csx|jstdtd|tN|jr6td|||j | t ||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.)rr6rTr|r rrrrrupdate_editabler2r,r-r.check_if_existsr)rAr+rr0r0r1prepare_editable_requirementYs&  z0RequirementPreparer.prepare_editable_requirementc Cst|jstd|dk s&td|jtd|||jjt*|jrRtdt | W5QRSQRXdS)z1Prepare 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_byr6rrTr|rr rrr r*)rAr+ skip_reasonr0r0r1prepare_installed_requirementvs$ z1RequirementPreparer.prepare_installed_requirement)F)F)F)rCrDrE__doc__rBrrrrrrrrrrr __classcell__r0r0rr1rs 3#! !  %r)NN)NN)NN)Nrloggingr>r[rRtypingrrrrrpip._vendor.packaging.utilsrZpip._vendor.pkg_resourcesrpip._internal.distributionsr %pip._internal.distributions.installedr pip._internal.exceptionsr r r rrrr"pip._internal.index.package_finderrpip._internal.models.linkrpip._internal.models.wheelrpip._internal.network.downloadrrZ pip._internal.network.lazy_wheelrrpip._internal.network.sessionrZpip._internal.req.req_installrpip._internal.req.req_trackerrpip._internal.utils.deprecationrpip._internal.utils.filesystemrpip._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' getLoggerrCrTr2r;r<rQrZrlrnrxrIrr0r0r0r1sV    $              ! " ?