a lj"G@sddlZddlZddlmZmZmZmZmZmZm Z m Z ddl m Z m Z ddlmZddlmZmZddlmZddlmZmZddlmZdd lmZmZdd lmZdd lm Z d d l!m"Z"m#Z#m$Z$m%Z%erd dl&m'Z'e(e)Z*e dZ+e e dZ,e"ee+dddZ-eeedddZ.eeedddZ/eeedddZ0Gddde"Z1Gddde1Z2Gd d!d!e1Z3Gd"d#d#e"Z4Gd$d%d%e"Z5Gd&d'd'e"Z6dS)(N) TYPE_CHECKINGAny FrozenSetIterableOptionalTupleUnioncast)NormalizedNamecanonicalize_name)Version) HashErrorMetadataInconsistent)BaseDistribution)Linklinks_equivalent)Wheel)install_req_from_editableinstall_req_from_line)InstallRequirement)normalize_version_info) CandidateCandidateVersion Requirement format_name)Factory)AlreadyInstalledCandidateEditableCandidate LinkCandidatez) candidatereturncCstttf}t||r|SdS)z%The runtime version of BaseCandidate.N)rrr isinstance)r Zbase_candidate_classesr#R/usr/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.pyas_base_candidate$s r%)linktemplater!c Csh|jrJd|jr t|j}n|j}t||j|j|j|j|j t |j |j |j dd}|j|_||_|S)Nztemplate is editableinstall_optionsglobal_optionsZhashes user_supplied comes_from use_pep517isolated constraintoptions)editablereqstrurlrr,r-r.r/r0dictr)r* hash_options original_linkr&)r&r'lineireqr#r#r$make_install_req_from_link0s(  r;c CsD|jsJdt|j|j|j|j|j|j|jt |j |j |j ddS)Nztemplate not editabler()r,r-r.r/r0permit_editable_wheelsr1) r2rr5r,r-r.r/r0r<r6r)r*r7)r&r'r#r#r$make_install_req_from_editableJsr=)distr'r!c Csddlm}|jrt|j}n.|jr:|jd|jj}n|jd|j}t||j |j |j |j |j t|j|j|jdd}t||j|_|S)Nr) Distributionz @ z==r(r+)Z$pip._internal.metadata.pkg_resourcesr?r3r4r&canonical_namer5versionrr,r-r.r/r0r6r)r*r7r Z_distZ satisfied_by)r>r'Z_Distr9r:r#r#r$_make_install_req_from_dist^s*   rBc @s,eZdZUdZeed<dZd)eeede e e e ddddZ e d d d Ze d d d Zed ddZeedddZee ed ddZee d ddZee d ddZee d ddZe d ddZed ddZeddd d!Zed d"d#Zeee ed$d%d&Z e ed d'd(Z!dS)*"_InstallRequirementBackedCandidateaA candidate backed by an ``InstallRequirement``. This represents a package request with the target not being already in the environment, and needs to be fetched and installed. The backing ``InstallRequirement`` is responsible for most of the leg work; this class exposes appropriate information to the resolver. :param link: The link passed to the ``InstallRequirement``. The backing ``InstallRequirement`` will use this link to fetch the distribution. :param source_link: The link this candidate "originates" from. This is different from ``link`` when the link is found in the wheel cache. ``link`` would point to the wheel cache, while this points to the found remote link (e.g. from pypi.org). r>FNr)r& source_linkr:factorynamerAr!cCs2||_||_||_||_||_||_||_dSN)_link _source_link_factory_ireq_name_version_preparer>)selfr&rDr:rErFrAr#r#r$__init__s z+_InstallRequirementBackedCandidate.__init__r!cCs|jd|jS)N rFrArOr#r#r$__str__sz*_InstallRequirementBackedCandidate.__str__cCsdj|jjt|jdS)Nz{class_name}({link!r})) class_namer&)format __class____name__r4rHrTr#r#r$__repr__sz+_InstallRequirementBackedCandidate.__repr__cCst|j|jfSrG)hashrXrHrTr#r#r$__hash__sz+_InstallRequirementBackedCandidate.__hash__otherr!cCst||jrt|j|jSdSNF)r"rXrrHrOr^r#r#r$__eq__s z)_InstallRequirementBackedCandidate.__eq__cCs|jSrG)rIrTr#r#r$rDsz._InstallRequirementBackedCandidate.source_linkcCs|jdur|jj|_|jS):The normalised name of the project the candidate refers toN)rLr>r@rTr#r#r$ project_names  z/_InstallRequirementBackedCandidate.project_namecCs|jSrGrcrTr#r#r$rFsz'_InstallRequirementBackedCandidate.namecCs|jdur|jj|_|jSrG)rMr>rArTr#r#r$rAs  z*_InstallRequirementBackedCandidate.versioncCs$d|j|j|jjr|jjn|jS)Nz{} {} (from {}))rWrFrArHis_fileZ file_pathrTr#r#r$format_for_errors z3_InstallRequirementBackedCandidate.format_for_errorcCs tddS)NzOverride in subclass)NotImplementedErrorrTr#r#r$_prepare_distributionsz8_InstallRequirementBackedCandidate._prepare_distribution)r>r!cCs`|jdur*|j|jkr*t|jd|j|j|jdur\|j|jkr\t|jdt|jt|jdS)z:Check for consistency of project name and version of dist.NrFrA)rLr@rrKrMrAr4)rOr>r#r#r$_check_metadata_consistencysz>_InstallRequirementBackedCandidate._check_metadata_consistencyc CsJz |}Wn.ty:}z|j|_WYd}~n d}~00|||SrG)rhr rKr3ri)rOr>er#r#r$rNs  z+_InstallRequirementBackedCandidate._prepare with_requiresr!ccsH|r|jnd}|D]}|jt||jVq|j|jjVdSNr#)r>iter_dependenciesrJmake_requirement_from_specr4rKZ make_requires_python_requirementZrequires_python)rOrlZrequiresrr#r#r$rnsz4_InstallRequirementBackedCandidate.iter_dependenciescCs|jSrG)rKrTr#r#r$get_install_requirementsz:_InstallRequirementBackedCandidate.get_install_requirement)NN)"rY __module__ __qualname____doc__r__annotations__ is_installedrrrr rrPr4rUrZintr\rboolrapropertyrDrcrFrArfrhrirNrrrnrqr#r#r#r$rCzs@   rCcsHeZdZdZd eedeeeeddfdd Z e ddd Z Z S) rFNrr&r'rErFrAr!c s|}|||}|dur,td|j|j}t||}|j|ksDJ|jjr|jjst|jj} t | j } || ksJ|d| d|durt | j } || ksJd || ||dur|jr|j|jurd|_tj||||||ddS)NzUsing cached wheel link: %sz != z for wheelz{!r} != {!r} for wheel {}Tr&rDr:rErFrA)Zget_wheel_cache_entryloggerdebugr&r;Zis_wheelrerfilenamer rFr rArWZ persistentr8Zoriginal_link_is_in_wheel_cachesuperrP) rOr&r'rErFrArDZ cache_entryr:ZwheelZ wheel_nameZ wheel_versionrXr#r$rPs>      zLinkCandidate.__init__rQcCs|jj}|j|jddS)NT)Zparallel_builds)rJpreparerZprepare_linked_requirementrK)rOrr#r#r$rh"sz#LinkCandidate._prepare_distribution)NN rYrrrs is_editablerrrr rrPrrh __classcell__r#r#rr$rs*rcsHeZdZdZd eedeeeeddfdd Z e ddd Z Z S) rTNrrzcs"tj||t|||||ddS)Nr{)rrPr=)rOr&r'rErFrArr#r$rP*szEditableCandidate.__init__rQcCs|jj|jSrG)rJrZprepare_editable_requirementrKrTr#r#r$rh;sz'EditableCandidate._prepare_distribution)NNrr#r#rr$r'src@seZdZdZdZeedddddZeddd Z edd d Z e dd d Z e edddZeedddZeedddZeedddZeedddZedddZeeeedddZeedddZdS) rTNr)r>r'rEr!cCs0||_t|||_||_d}|j|j|dS)Nzalready satisfied)r>rBrKrJrZprepare_installed_requirement)rOr>r'rEZ skip_reasonr#r#r$rPCs  z"AlreadyInstalledCandidate.__init__rQcCs t|jSrG)r4r>rTr#r#r$rUTsz!AlreadyInstalledCandidate.__str__cCsdj|jj|jdS)Nz{class_name}({distribution!r}))rVZ distribution)rWrXrYr>rTr#r#r$rZWsz"AlreadyInstalledCandidate.__repr__cCst|j|j|jfSrG)r[rXrFrArTr#r#r$r\]sz"AlreadyInstalledCandidate.__hash__r]cCs(t||jr$|j|jko"|j|jkSdSr_)r"rXrFrAr`r#r#r$ra`s z AlreadyInstalledCandidate.__eq__cCs|jjSrG)r>r@rTr#r#r$rcesz&AlreadyInstalledCandidate.project_namecCs|jSrGrdrTr#r#r$rFiszAlreadyInstalledCandidate.namecCs|jjSrG)r>rArTr#r#r$rAmsz!AlreadyInstalledCandidate.versioncCs|jjSrG)r>r2rTr#r#r$rqsz%AlreadyInstalledCandidate.is_editablecCs|jd|jdS)NrRz (Installed)rSrTr#r#r$rfusz*AlreadyInstalledCandidate.format_for_errorrkccs2|sdS|jD]}|jt||jVqdSrG)r>rnrJror4rK)rOrlrpr#r#r$rnxsz+AlreadyInstalledCandidate.iter_dependenciescCsdSrGr#rTr#r#r$rq~sz1AlreadyInstalledCandidate.get_install_requirement)rYrrrsrvrDrrrPr4rUrZrwr\rrxraryr rcrFrrArrfrrrrnrqr#r#r#r$r?s, rc@seZdZdZeeeddddZedddZedd d Z e dd d Z e e d ddZeedddZeedddZeedddZedddZee dddZee dddZeeedddZe eeeddd Zeedd!d"ZdS)#ExtrasCandidateaA candidate that has 'extras', indicating additional dependencies. Requirements can be for a project with dependencies, something like foo[extra]. The extras don't affect the project/version being installed directly, but indicate that we need additional dependencies. We model that by having an artificial ExtrasCandidate that wraps the "base" candidate. The ExtrasCandidate differs from the base in the following ways: 1. It has a unique name, of the form foo[extra]. This causes the resolver to treat it as a separate node in the dependency graph. 2. When we're getting the candidate's dependencies, a) We specify that we want the extra dependencies as well. b) We add a dependency on the base candidate. See below for why this is needed. 3. We return None for the underlying InstallRequirement, as the base candidate will provide it, and we don't want to end up with duplicates. The dependency on the base candidate is needed so that the resolver can't decide that it should recommend foo[extra1] version 1.0 and foo[extra2] version 2.0. Having those candidates depend on foo=1.0 and foo=2.0 respectively forces the resolver to recognise that this is a conflict. N)baseextrasr!cCs||_||_dSrG)rr)rOrrr#r#r$rPszExtrasCandidate.__init__rQcCs,t|jdd\}}d|d|j|S)NrRrz {}[{}] {},)r4rsplitrWjoinr)rOrFrestr#r#r$rUszExtrasCandidate.__str__cCsdj|jj|j|jdS)Nz.{class_name}(base={base!r}, extras={extras!r}))rVrr)rWrXrYrrrTr#r#r$rZs zExtrasCandidate.__repr__cCst|j|jfSrG)r[rrrTr#r#r$r\szExtrasCandidate.__hash__r]cCs(t||jr$|j|jko"|j|jkSdSr_)r"rXrrr`r#r#r$ras zExtrasCandidate.__eq__cCs|jjSrG)rrcrTr#r#r$rcszExtrasCandidate.project_namecCst|jj|jS)rb)rrrcrrTr#r#r$rFszExtrasCandidate.namecCs|jjSrG)rrArTr#r#r$rAszExtrasCandidate.versioncCsd|jdt|jS)Nz{} [{}]z, )rWrrfrsortedrrTr#r#r$rfsz ExtrasCandidate.format_for_errorcCs|jjSrG)rrvrTr#r#r$rvszExtrasCandidate.is_installedcCs|jjSrG)rrrTr#r#r$rszExtrasCandidate.is_editablecCs|jjSrG)rrDrTr#r#r$rDszExtrasCandidate.source_linkrkccs|jj}||jV|sdS|j|jj}|j|jj}t|D]}t d|jj |j |qN|jj |D]$}|t||jj|}|rx|VqxdS)Nz%%s %s does not provide the extra '%s')rrJZmake_requirement_from_candidater intersectionr>Ziter_provided_extras differencerr|ZwarningrFrArnror4rK)rOrlrEZ valid_extrasZinvalid_extrasZextrarpZ requirementr#r#r$rns& z!ExtrasCandidate.iter_dependenciescCsdSrGr#rTr#r#r$rqsz'ExtrasCandidate.get_install_requirement) rYrrrsrt BaseCandidaterr4rPrUrZrwr\rrxraryr rcrFrrArfrvrrrrDrrrnrrqr#r#r#r$rs0 rc@seZdZdZdZeeedfddddZe ddd Z e e dd d Z e e dd d Ze edddZe dddZeeeedddZeedddZdS)RequiresPythonCandidateFN.)py_version_infor!cCs>|durt|}ntjdd}tddd|D|_dS)N.css|]}t|VqdSrG)r4).0cr#r#r$ z3RequiresPythonCandidate.__init__..)rsys version_infor rrM)rOrrr#r#r$rPs z RequiresPythonCandidate.__init__rQcCs d|jSNzPython rMrTr#r#r$rUszRequiresPythonCandidate.__str__cCstSrGREQUIRES_PYTHON_IDENTIFIERrTr#r#r$rc sz$RequiresPythonCandidate.project_namecCstSrGrrTr#r#r$rF szRequiresPythonCandidate.namecCs|jSrGrrTr#r#r$rAszRequiresPythonCandidate.versioncCs d|jSr)rArTr#r#r$rfsz(RequiresPythonCandidate.format_for_errorrkcCsdSrmr#)rOrlr#r#r$rnsz)RequiresPythonCandidate.iter_dependenciescCsdSrGr#rTr#r#r$rqsz/RequiresPythonCandidate.get_install_requirement)rYrrrsrvrDrrrwrPr4rUryr rcrFrrArfrxrrrnrrqr#r#r#r$rs r)7Zloggingrtypingrrrrrrrr Zpip._vendor.packaging.utilsr r Zpip._vendor.packaging.versionr Zpip._internal.exceptionsr rZpip._internal.metadatarZpip._internal.models.linkrrZpip._internal.models.wheelrZpip._internal.req.constructorsrrZpip._internal.req.req_installrZpip._internal.utils.miscrrrrrrrErZ getLoggerrYr|rrr%r;r=rBrCrrrrrr#r#r#r$sF(            {2Cu