3 Re:@sddlZddlmZddlmZddlmZejdddgZGd d d e Z Gd d d e Z Gd dde Z Gddde ZGddde ZGdddeZGdddeZejddZGddde ZddZejddZdd ZGd!d"d"eZdS)#N)collections_abc)AbstractResolver) DirectedGraphRequirementInformation requirementparentc@seZdZdZdS)ResolverExceptionzA base class for all exceptions raised by this module. Exceptions derived by this class should all be handled in this module. Any bubbling pass the resolver should be treated as a bug. N)__name__ __module__ __qualname____doc__rr/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el9.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.pyr sr cs$eZdZfddZddZZS)RequirementsConflictedcstt|j|||_dS)N)superr__init__ criterion)selfr) __class__rrrszRequirementsConflicted.__init__cCs djdjdd|jjDS)NzRequirements conflict: {}z, css|]}t|VqdS)N)repr).0rrrr sz1RequirementsConflicted.__str__..)formatjoinriter_requirement)rrrr__str__szRequirementsConflicted.__str__)r r r rr __classcell__rr)rrrs rcs$eZdZfddZddZZS)InconsistentCandidatecs"tt|j||||_||_dS)N)rrr candidater)rr r)rrrr!szInconsistentCandidate.__init__cCs$dj|jdjdd|jjDS)Nz+Provided candidate {!r} does not satisfy {}z, css|]}t|VqdS)N)r)rrrrrr)sz0InconsistentCandidate.__str__..)rr rrr)rrrrr&szInconsistentCandidate.__str__)r r r rrrrr)rrr s rc@sLeZdZdZddZddZeddZdd Zd d Z d d Z ddZ dS) CriterionaQRepresentation of possible resolution results of a package. This holds three attributes: * `information` is a collection of `RequirementInformation` pairs. Each pair is a requirement contributing to this criterion, and the candidate that provides the requirement. * `incompatibilities` is a collection of all known not-to-work candidates to exclude from consideration. * `candidates` is a collection containing all possible candidates deducted from the union of contributing requirements and known incompatibilities. It should never be empty, except when the criterion is an attribute of a raised `RequirementsConflicted` (in which case it is always empty). .. note:: This class is intended to be externally immutable. **Do not** mutate any of its attribute containers. cCs||_||_||_dS)N) candidates informationincompatibilities)rr"r#r$rrrrAszCriterion.__init__cCs djdd|jD}dj|S)Nz, css|]\}}dj||VqdS)z({!r}, via={!r})N)r)rreqrrrrrHsz%Criterion.__repr__..z Criterion({}))rr#r)r requirementsrrr__repr__Fs zCriterion.__repr__cCsF|j|g}t|tjs t|}||t||ggd}|sBt||S)z.Build an instance from a requirement. )r"r#r$) find_matches isinstancerSequencelistrr)clsproviderrrr"rrrrfrom_requirementMs   zCriterion.from_requirementcCsdd|jDS)Ncss|] }|jVqdS)N)r)rirrrr^sz-Criterion.iter_requirement..)r#)rrrrr]szCriterion.iter_requirementcCsdd|jDS)Ncss|] }|jVqdS)N)r)rr/rrrrasz(Criterion.iter_parent..)r#)rrrr iter_parent`szCriterion.iter_parentcCsht|j}|jt|||jdd|D}t|tjsBt|}t|||t|j }|sdt ||S)z>Build a new instance from this and a new requirement. cSsg|] \}}|qSrr)rr_rrr hsz)Criterion.merged_with..) r+r#appendrr(r)rr*typer$r)rr-rrinfosr"rrrr merged_withcs  zCriterion.merged_withcsJt|j}|jfdd|jD}|s0dSt||t|j|}|S)zBuild a new instance from this, but excluding specified candidate. Returns the new instance, or None if we still have no valid candidates. csg|]}|kr|qSrr)rc)r rrr2wsz)Criterion.excluded_of..N)r+r$r3r"r4r#)rr Z incompatsr"rr)r r excluded_ofps  zCriterion.excluded_ofN) r r r r rr' classmethodr.rr0r6r8rrrrr!-s  r!c@s eZdZdS)ResolutionErrorN)r r r rrrrr:~sr:cseZdZfddZZS)ResolutionImpossiblecstt|j|||_dS)N)rr;rcauses)rr<)rrrrszResolutionImpossible.__init__)r r r rrrr)rrr;sr;cseZdZfddZZS)ResolutionTooDeepcstt|j|||_dS)N)rr=r round_count)rr>)rrrrszResolutionTooDeep.__init__)r r r rrrr)rrr=sr=Statezmapping criteriac@sdeZdZdZddZeddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZdS) ResolutionzStateful resolution object. This is designed as a one-off object that holds information to kick start the resolution process, and holds the results afterwards. cCs||_||_g|_dS)N)_p_r_states)rr-reporterrrrrszResolution.__init__c Cs,y |jdStk r&tdYnXdS)Nrstate)rC IndexErrorAttributeError)rrrrrEs zResolution.statec Cs\y|jd}Wn$tk r2ttjid}YnXt|jj|jjd}|jj|dS)zPush a new state into history. This new state will be used to hold resolution results of the next coming round. r)mappingcriteriaNrF) rCrGr? collections OrderedDictrIcopyrJr3)rbaserErrr_push_new_stateszResolution._push_new_statec Csh|jj|||jj|}y|jj|}Wn$tk rNtj|j||}YnX|j |j||}||fS)N) rBZadding_requirementrAZidentifyrErJKeyErrorr!r.r6)rrrnamecritrrr_merge_into_criterions z Resolution._merge_into_criterionc CsF|\}}y|jj|}Wntk r0d}YnX|jj||j|jS)N)rErIrPrAZget_preferencer"r#)ritemrQrZpinnedrrr_get_criterion_item_preferences z)Resolution._get_criterion_item_preferencec sByjj|Wntk r$dSXtfdd|jDS)NFc3s|]}jj|VqdS)N)rAis_satisfied_by)rr) current_pinrrrrsz8Resolution._is_current_pin_satisfying..)rErIrPallr)rrQrr)rWrr_is_current_pin_satisfyings z%Resolution._is_current_pin_satisfyingcCs8i}x.|jj|D]}|j||d\}}|||<qW|S)N)r)rAZget_dependenciesrS)rr rJrrQrRrrr_get_criteria_to_updates  z"Resolution._get_criteria_to_updatecsg}x|jD]yj}Wn0tk rN}z|j|jw WYdd}~XnXtfdd|jD}|szt|jj j j j |dj j |<j j j|gSW|S)Nc3s|]}jj|VqdS)N)rArV)rr)r rrrrsz7Resolution._attempt_to_pin_criterion..)r"rZrr3rrXrrrBZpinningrErIpoprJupdate)rrQrr<rJeZ satisfiedr)r rr_attempt_to_pin_criterions$      z$Resolution._attempt_to_pin_criterionc Cs|jd=xt|jdkr|jj}y|jj\}}Wntk rJw YnX|jj||j|j j |j |}|dkr|jd=q ||j j |<dSWdS)NrTFrFrF) rClenr[rIpopitemrPrBZ backtrackingrOrErJr8)rZ prev_staterQr rrrr _backtracks    zResolution._backtrackcsFjrtdjx^|D]V}yj|dd\}}Wn.tk rd}zt|jjWYdd}~XnX|jj |<qWj j xt |D]}j j |jj}fddjj jD} | sjd=j j|jSt| jd\}} j|| } | r(j} | s(dd| D} t| j j||qWt|dS) Nzalready resolved)rcsg|]}j|s|qSr)rY)rrT)rrrr24sz&Resolution.resolve..r)keycSsg|]}|jD]}|qqSr)r#)rrRr/rrrr2KsrF)rC RuntimeErrorrOrSrr;rr#rErJrBZstartingrangeZstarting_rounditemsZendingminrUr^rbZ ending_roundr=)rr& max_roundsrrQrRr]Z round_indexcurrZunsatisfied_criterion_itemsrZfailure_causesresultr<r)rrresolves>      zResolution.resolveN)r r r r rpropertyrErOrSrUrYrZr^rbrkrrrrr@s    !"r@cCs||kr dS||krdSxn||jD]^}y|t|}Wntk rPw&YnX||krh|j|dSt||||r&|j|dSq&WdS)NTF)r0idrPadd_has_route_to_root)rJrcall_keys connectedppkeyrrrroTs   roResultzmapping graph criteriac s|j}dd|jD}d|td<t}|jddhx|jjD]\}}t|j||s`qF||krr|j|xV|jD]J}y|t|}Wntk rw|YnX||kr|j||j ||q|WqFWt fdd|jD||jdS)NcSsi|]\}}|t|qSr)rm)rkvrrr lsz!_build_result..csi|]\}}|kr||qSrr)rrurv)rqrrrws)rIgraphrJ) rIrfrmrrnrJror0rPconnectrt)rErIrprxrcrrrrsr)rqr _build_resultjs.    rzc@seZdZdZeZdddZdS)Resolverz8The thing that performs the actual resolution work. dcCs$t|j|j}|j||d}t|S)aTake a collection of constraints, spit out the resolution result. The return value is a representation to the final resolution result. It is a tuple subclass with three public members: * `mapping`: A dict of resolved candidates. Each key is an identifier of a requirement (as returned by the provider's `identify` method), and the value is the resolved candidate. * `graph`: A `DirectedGraph` instance representing the dependency tree. The vertices are keys of `mapping`, and each edge represents *why* a particular package is included. A special vertex `None` is included to represent parents of user-supplied requirements. * `criteria`: A dict of "criteria" that hold detailed information on how edges in the graph are derived. Each key is an identifier of a requirement, and the value is a `Criterion` instance. The following exceptions may be raised if a resolution cannot be found: * `ResolutionImpossible`: A resolution cannot be found for the given combination of requirements. The `causes` attribute of the exception is a list of (requirement, parent), giving the requirements that could not be satisfied. * `ResolutionTooDeep`: The dependency tree is too deeply nested and the resolver gave up. This is usually caused by a circular dependency, but you can try to resolve this by increasing the `max_rounds` argument. )rh)r@r-rDrkrz)rr&rh resolutionrErrrrkszResolver.resolveN)r|)r r r r r Zbase_exceptionrkrrrrr{sr{)rKcompatrZ providersrstructsr namedtupler Exceptionr rrobjectr!r:r;r=r?r@rortrzr{rrrrs&      Q B