o 7]hD@sddlZddlZddlmZddlmZmZmZedddgZ Gdd d e Z Gd d d e Z Gd d d e Z GdddeZGddde ZGdddeZGdddeZeddZGdddeZddZeddZddZGd 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__rrB/usr/lib/python3/dist-packages/pip/_vendor/resolvelib/resolvers.pyr sr c$eZdZfddZddZZS)RequirementsConflictedctt||||_dSN)superr__init__ criterion)selfr __class__rrr zRequirementsConflicted.__init__cCs dddd|jDS)NzRequirements conflict: {}, cs|]}t|VqdSrrepr.0rrrr z1RequirementsConflicted.__str__..)formatjoinriter_requirementrrrr__str__szRequirementsConflicted.__str__r r r rr) __classcell__rrrrrs rcr)InconsistentCandidatecs"tt|||||_||_dSr)rr,r candidater)rr-rrrrr s zInconsistentCandidate.__init__cCs$d|jddd|jDS)Nz+Provided candidate {!r} does not satisfy {}rcsrrrr rrrr#(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)rr0r1r2rrrr@ zCriterion.__init__cCs ddd|jD}d|S)Nrcss |] \}}d||VqdS)z({!r}, via={!r})N)r%)r!reqr rrrr#Fs  z%Criterion.__repr__..z Criterion({}))r&r1r%)r requirementsrrr__repr__Es  zCriterion.__repr__cCdd|jDS)Ncs|]}|jVqdSr)rr!irrrr#Mz-Criterion.iter_requirement..r1r(rrrr'LzCriterion.iter_requirementcCr7)Ncsr8rr r9rrrr#Pr;z(Criterion.iter_parent..r<r(rrr iter_parentOr=zCriterion.iter_parentN)r r r rrr6r'r?rrrrr.,s  r.c@s eZdZdS)ResolutionErrorN)r r r rrrrr@Ssr@ceZdZfddZZS)ResolutionImpossiblecrr)rrBrcauses)rrCrrrrXs zResolutionImpossible.__init__r r r rr+rrrrrBWrBcrA)ResolutionTooDeepcrr)rrFr round_count)rrGrrrr_rzResolutionTooDeep.__init__rDrrrrrF^rErFStatez!mapping criteria backtrack_causesc@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|_dSr)_p_r_states)rproviderreporterrrrror3zResolution.__init__cCs$z|jdWStytdw)Nstate)rL IndexErrorAttributeErrorr(rrrrPts   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. rONmappingcriteriabacktrack_causes)rLrHrTcopyrUrVappend)rbaserPrrr_push_new_state{s  zResolution._push_new_statec Cs|jj||d|jj|d}||}|rt|j}ng}|jj|t|t d||git|t d||id}|rJt|j }| t||nt||g}tt|||d}|js`t||||<dS)N)rr )requirement_or_candidater'r2 identifierr5r2r/)rKadding_requirementrJidentifygetlistr2 find_matchesroperator methodcaller attrgetterr1rXrr.rr0r) rrUrr r]rr2matchesr1rrr_add_to_criterias>     zResolution._add_to_criteriac Cs>|jj||jjt|jjtdt|jjtd|jjdS)Nr0r1)r] resolutionsr0r1rV) rJget_preferencerPrTrrUrcrerV)rnamerrr_get_preferenceszResolution._get_preferencecsBzjj|Wn tyYdSwtfdd|DS)NFc3 |] }jj|dVqdS)rr-NrJis_satisfied_byr  current_pinrrrr#  z8Resolution._is_current_pin_satisfying..)rPrTKeyErrorallr')rrjrrrpr_is_current_pin_satisfyings z%Resolution._is_current_pin_satisfyingcCs4|jj}|jj|dD] }|j|||dq |S)Nr-r>)rPrUrWrJget_dependenciesrg)rr-rUrrrr_get_updated_criterias z Resolution._get_updated_criteriac sjj|}g}|jD]Vz}Wnty,}z ||jWYd}~q d}~wwtfdd|D}|sBt |j j djj |jj |djj |<gS|S)Nc3rlrmrnr r-rrrr#rrz7Resolution._attempt_to_pin_criterion..rv)rPrUr0rxrrXrrtr'r,rKpinningupdaterTpop)rrjrrCrUe satisfiedrryr_attempt_to_pin_criterions*      z$Resolution._attempt_to_pin_criterioncstjdkrIjd=j}|j\}}dd|jD||gfjj |dfdd} |}|rBdStjdksd S) aPerform backtracking. 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. Discard Z. 2. Discard Y but remember its incompatibility information gathered previously, and the failure we're dealing with right now. 3. Push a new state Y' based on X, and apply the incompatibility information from Y to Y'. 4a. If this causes Y' to conflict, we need to backtrack again. Make Y' the new Z and go back to step 2. 4b. If the incompatibilities apply cleanly, end backtracking. rOcSsg|] \}}|t|jfqSr)rar2r!kvrrr s z)Resolution._backtrack..rvc sD]R\}}|s qzjj|}Wn tyYqwjj|tjjtdtjjtd||id}t |}|s@dS| |j t |t |j|djj|<qdS)Nr'r2r\Fr/T)rPrUrsrJrbrrcrdrerextendr2r.rar1)rr2rrfr0incompatibilities_from_brokenrrr_patch_criteria s<    z.Resolution._backtrack.._patch_criteriaTF) lenrLr|rTpopitemrUitemsrXrK backtrackingrZ)r broken_staterjr-rsuccessrrr _backtracks  =zResolution._backtrackc sTjrtdjttigdg_|D] }z jjj |ddWqt y9}zt |j j d}~wwt|D]c}jj|dfddjj D}|sgjjjdjSt|jd}|}|rd d|D} jj| d } | jjdd<| st jjnjj|jd qBt|) Nzalready resolvedrSr>)indexcs g|] \}}||s|qSr)ru)r!keyrr(rrrhs  z&Resolution.resolve..)rP)rcSsg|] }|jD]}|qqSrr<)r!cr:rrrrxs)rC)rrP)rL RuntimeErrorrKstartingrH collections OrderedDictrgrPrUrrBrr1rZrangestarting_roundrendingminrkrresolving_conflictsrrV ending_roundrF) rr5 max_roundsr"r} round_indexunsatisfied_namesrjfailure_causesrCrrr(rresolveLsL        zResolution.resolveN)r r r rrpropertyrPrZrgrkrurxrrrrrrrrIhs ' $ YrIc Cs||vrdS||vr dS||D]/}z|t|}Wn ty%Yqw||vr2||dSt||||rA||dSqdS)NTF)r?idrsadd_has_route_to_root)rUrall_keys connectedppkeyrrrrs$   rResultzmapping graph criteriac s|j}dd|D}d|td<t}|ddh|jD]>\}}t|j||s/q"||vr8|||D]#}z|t|}Wn tyOYqsz!_build_result..csi|] \}}|vr||qSrrrrrrrs)rTgraphrU) rTrrrrrUrr?rsconnectr)rPrTrrrrrrrrr _build_results4       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)rIrMrNrr)rr5r resolutionrPrrrrszResolver.resolveN)r)r r r rr base_exceptionrrrrrrsr)rrc providersrstructsrrr namedtupler Exceptionr rr,objectr.r@rBrFrHrIrrrrrrrrs,   ' %