a *egP@sddlZddlZddlZddlmZddlmZmZmZe dddgZ Gdd d e Z Gd d d e Z Gd d d e ZGdddeZGddde ZGdddeZGdddeZe ddZGdddeZddZe ddZddZGd d!d!eZdS)"N)AbstractResolver) DirectedGraphIteratorMappingbuild_iter_viewRequirementInformation 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__rrJ/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.pyr sr cs$eZdZfddZddZZS)RequirementsConflictedcstt||||_dSN)superr__init__ criterion)selfr __class__rrrszRequirementsConflicted.__init__cCs dddd|jDS)NzRequirements conflict: {}, css|]}t|VqdSrrepr.0rrrr z1RequirementsConflicted.__str__..)formatjoinriter_requirementrrrr__str__szRequirementsConflicted.__str__r r r rr% __classcell__rrrrrs rcs$eZdZfddZddZZS)InconsistentCandidatecs"tt|||||_||_dSr)rr(r candidater)rr)rrrrr!szInconsistentCandidate.__init__cCs$d|jddd|jDS)Nz+Provided candidate {!r} does not satisfy {}rcss|]}t|VqdSrrrrrrr)r z0InconsistentCandidate.__str__..)r!r)r"rr#r$rrrr%&szInconsistentCandidate.__str__r&rrrrr( s r(c@s0eZdZdZddZddZddZdd Zd S) 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||_||_||_dSr candidates informationincompatibilities)rr,r-r.rrrrAszCriterion.__init__cCs ddd|jD}d|S)Nrcss|]\}}d||VqdS)z({!r}, via={!r})N)r!)rreqr rrrrGsz%Criterion.__repr__..z Criterion({}))r"r-r!)r requirementsrrr__repr__Fs zCriterion.__repr__cCsdd|jDS)Ncss|] }|jVqdSrrrirrrrNr z-Criterion.iter_requirement..r-r$rrrr#MszCriterion.iter_requirementcCsdd|jDS)Ncss|] }|jVqdSrr r3rrrrQr z(Criterion.iter_parent..r5r$rrr iter_parentPszCriterion.iter_parentN)r r r rrr1r#r7rrrrr*-s r*c@s eZdZdS)ResolutionErrorN)r r r rrrrr8Tsr8cseZdZfddZZS)ResolutionImpossiblecstt||||_dSr)rr9rcauses)rr:rrrrYszResolutionImpossible.__init__r r r rr'rrrrr9Xsr9cseZdZfddZZS)ResolutionTooDeepcstt||||_dSr)rr<r round_count)rr=rrrr`szResolutionTooDeep.__init__r;rrrrr<_sr<Statez!mapping criteria backtrack_causesc@sleZdZdZddZeddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZdS) 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|_dSr)_p_r_states)rproviderreporterrrrrpszResolution.__init__cCs,z |jdWSty&tdYn0dS)Nstate)rB IndexErrorAttributeErrorr$rrrrFus  zResolution.statecCs>|jd}t|j|j|jddd}|j|dS)zPush a new state into history. This new state will be used to hold resolution results of the next coming round. rENmappingcriteriabacktrack_causes)rBr>rJcopyrKrLappend)rbaserFrrr_push_new_state|s  zResolution._push_new_statec Cs|jj||d|jj|d}||}|r8t|j}ng}|jj|t|t d||git|t d||id}|rt|j }| t||n t||g}tt|||d}|jst||||<dS)N)rr )requirement_or_candidater#r. identifierr0r.r+)rAadding_requirementr@identifygetlistr. find_matchesroperator methodcaller attrgetterr-rNrr*rr,r) rrKrr rSrr.matchesr-rrr_add_to_criterias>    zResolution._add_to_criteriacsDsdS|D].\}}t|jfdd|jD|j||<qdS)aWRemove information from parents of criteria. Concretely, removes all values from each criterion's ``information`` field that have one of ``parents`` as provider of the requirement. :param criteria: The criteria to update. :param parents: Identifiers for which to remove information from all criteria. Ncs,g|]$}|jdus$j|jvr|qSr)r r@rU)rr-parentsrrr s z@Resolution._remove_information_from_criteria..)itemsr*r,r-r.)rrKr_keyrrr^r!_remove_information_from_criterias  z,Resolution._remove_information_from_criteriac Cs>|jj||jjt|jjtdt|jjtd|jjdS)Nr,r-)rS resolutionsr,r-rL) r@get_preferencerFrJrrKrYr[rL)rnamerrr_get_preferenceszResolution._get_preferencecsBzjj|Wnty$YdS0tfdd|DS)NFc3s|]}jj|dVqdS)rr)Nr@is_satisfied_byr current_pinrrrrsz8Resolution._is_current_pin_satisfying..)rFrJKeyErrorallr#)rrfrrrkr_is_current_pin_satisfyings z%Resolution._is_current_pin_satisfyingcCs4|jj}|jj|dD]}|j|||dq|S)Nr)r6)rFrKrMr@get_dependenciesr])rr)rKrrrr_get_updated_criterias z Resolution._get_updated_criteriac sjj|}g}|jD]ȉz}WnLtyt}z4j|j||jWYd}~qWYd}~n d}~00t fdd| D}|st |jj djj |jj|djj|<gS|S)Nc3s|]}jj|dVqdSrhrirr)rrrrsz7Resolution._attempt_to_pin_criterion..rp)rFrKr,rrrrAZrejecting_candidaterrNrnr#r(pinningupdaterJpop)rrfrr:rKe satisfiedrrsr_attempt_to_pin_criterions(   "  z$Resolution._attempt_to_pin_criterionc stdd|Ddd|D}fdd|D}tjdkrjd=d}|szj}|j\}}Wnttfyt |Yn0fd dj |D}| | }qLd d |j D||gffd d } | } | r2dSq2dS)a2Perform backjumping. When we enter here, the stack is like this:: [ state Z ] [ state Y ] [ state X ] .... earlier states are irrelevant. 1. No pins worked for Z, so it does not have a pin. 2. We want to reset state Y to unpinned, and pin another candidate. 3. State X holds what state Y was before the pin, but does not have the incompatibility information gathered in state Y. Each iteration of the loop will: 1. Identify Z. The incompatibility is not always caused by the latest state. For example, given three requirements A, B and C, with dependencies A1, B1 and C1, where A1 and B1 are incompatible: the last state might be related to C, so we want to discard the previous state. 2. Discard Z. 3. Discard Y but remember its incompatibility information gathered previously, and the failure we're dealing with right now. 4. Push a new state Y' based on X, and apply the incompatibility information from Y to Y'. 5a. If this causes Y' to conflict, we need to backtrack again. Make Y' the new Z and go back to step 2. 5b. If the incompatibilities apply cleanly, end backtracking. css|]}|jdur|jVqdSrr6rcrrrr.r z'Resolution._backjump..css|] }|jVqdSrr2rzrrrr/r csh|]}j|qSrr@rUrr$rr 1r z'Resolution._backjump..rEFcsh|]}j|qSrr|)rdr$rrr}?scSsg|]\}}|t|jfqSr)rWr.rkvrrrr`Gsz(Resolution._backjump..c sD]\}}|sqzjj|}Wnty8YqYn0jj|tjjtdtjjtd||id}t |}|sdS| |j t |t |j|djj|<qdS)Nr#r.rRFr+T)rFrKrmr@rXrrYrZr[rextendr.r*rWr-)rr.rr\r,incompatibilities_from_brokenrrr_patch_criteriaQs:     z-Resolution._backjump.._patch_criteriaT) itertoolschainlenrBrvrJpopitemrGrmr9r@rq isdisjointrKrarNrP) rr:Zincompatible_reqsZincompatible_depsZincompatible_state broken_staterfr)Zcurrent_dependenciesrsuccessrrr _backjumps<     zResolution._backjumpc sjrtdjttigdg_|D]N}zjjj |ddWq2t y~}zt |j j WYd}~q2d}~00q2t|D]}jj|dfddjj D}|sވjjjdjStjj t|t|jd}|}|r^d d|D} jj| d | } | jjdd<| st jjn4fd d jj D} jj | jj|jd qt|dS)Nzalready resolvedrIr6)indexcs g|]\}}||s|qSrrorrbrr$rrr`s z&Resolution.resolve..)rF)rbcSsg|]}|jD]}|qqSrr5)rr{r4rrrr`r )r:cs(h|] \}}|vr||s|qSrrrZsatisfied_namesrrrr}s z%Resolution.resolve..)rrF)rB RuntimeErrorrAstartingr> collections OrderedDictr]rFrKrr9rr-rPrangestarting_roundraendingsetkeysminrgryZresolving_conflictsrrLrc ending_roundr<) rr0 max_roundsrrw round_indexunsatisfied_namesrffailure_causesr:rZnewly_unsatisfied_namesrrrresolve}sX $       zResolution.resolveN)r r r rrpropertyrFrPr]rcrgrorrryrrrrrrr?is ' %or?c Cs||vr dS||vrdS||D]b}z|t|}WntyNYq$Yn0||vrh||dSt||||r$||dSq$dS)NTF)r7idrmadd_has_route_to_root)rKrball_keys connectedppkeyrrrrs     rResultzmapping graph criteriac s|j}dd|D}d|td<t}|ddh|jD]\}}t|j||s^qD||vrp|||D]J}z|t|}WntyYqxYn0||vr||| ||qxqDt fdd|D||jdS)NcSsi|]\}}t||qSr)rrrrr r z!_build_result..csi|]\}}|vr||qSrrrrrrrr )rJgraphrK) rJrarrrrKrr7rmconnectr)rFrJrrrbrrrrrr _build_results0       rc@seZdZdZeZdddZdS)Resolverz3The 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. )r)r?rCrDrr)rr0r resolutionrFrrrrszResolver.resolveN)r)r r r rr base_exceptionrrrrrrsr)rrrY providersrstructsrrr namedtupler Exceptionr rr(objectr*r8r9r<r>r?rrrrrrrrs,   ' e