a J{_@@sddlZddlmZddlmZmZedddgZGdd d eZ Gd d d e Z Gd d d e Z Gddde Z Gddde ZGdddeZGdddeZeddZGddde ZddZeddZddZGd d!d!eZdS)"N)AbstractResolver) DirectedGraphbuild_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__rr8/usr/lib/python3.9/site-packages/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(rz0InconsistentCandidate.__str__..)r r(r!rr"r#rrrr$%szInconsistentCandidate.__str__r%rrrrr's r'c@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||_||_||_dSr) candidates informationincompatibilities)rr*r+r,rrrr@szCriterion.__init__cCs ddd|jD}d|S)Nrcss|]\}}d||VqdS)z({!r}, via={!r})N)r )rZreqrrrrrFsz%Criterion.__repr__..z Criterion({}))r!r+r )r requirementsrrr__repr__Es zCriterion.__repr__cCs:t||g}t||g}|||gd}|s6t||S)z%Build an instance from a requirement.r,)r find_matchesrr)clsproviderrrcandsinfosrrrrfrom_requirementLs  zCriterion.from_requirementcCsdd|jDS)Ncss|] }|jVqdSr)rrirrrrWrz-Criterion.iter_requirement..r+r#rrrr"VszCriterion.iter_requirementcCsdd|jDS)Ncss|] }|jVqdSrrr6rrrrZrz(Criterion.iter_parent..r8r#rrr iter_parentYszCriterion.iter_parentcCsXt|j}|t||t|dd|D}t|||t|j}|sTt||S)z5Build a new instance from this and a new requirement.cSsg|] \}}|qSrr)rr_rrr `rz)Criterion.merged_with..) listr+appendrrr0typer,r)rr2rrr4r3rrrr merged_with\s zCriterion.merged_withcCs4|j|}|sdS|j|}t||t|j|S)zBuild a new instance from this, but excluding specified candidates. Returns the new instance, or None if we still have no valid candidates. N)r*Z excludingr,r?r=r+)rr*r3Z incompatsrrr excluded_offs   zCriterion.excluded_ofN) r r r r rr. classmethodr5r"r:r@rArrrrr),s  r)c@s eZdZdS)ResolutionErrorN)r r r rrrrrCrsrCcseZdZfddZZS)ResolutionImpossiblecstt||||_dSr)rrDrcauses)rrErrrrwszResolutionImpossible.__init__r r r rr&rrrrrDvsrDcseZdZfddZZS)ResolutionTooDeepcstt||||_dSr)rrGr round_count)rrHrrrr~szResolutionTooDeep.__init__rFrrrrrG}srGStatezmapping 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|_dSr)_p_r_states)rr2reporterrrrrszResolution.__init__cCs,z |jdWSty&tdYn0dS)Nstate)rM IndexErrorAttributeErrorr#rrrrPs  zResolution.statecCs2|jd}t|j|jd}|j|dS)zPush a new state into history. This new state will be used to hold resolution results of the next coming round. rOmappingcriteriaN)rMrIrTcopyrUr>)rbaserPrrr_push_new_states  zResolution._push_new_statecCsf|j|||j|}z|jj|}Wn"tyLt|j||}Yn0| |j||}||fSr) rLZadding_requirementrKZidentifyrPrUKeyErrorr)r5r@)rrrnamecritrrr_merge_into_criterions  z Resolution._merge_into_criterioncCs*|\}}|j|jj||j|jSr)rKZget_preferencerPrTgetr*Zfor_preferencer+)ritemrZrrrr_get_criterion_item_preferences  z)Resolution._get_criterion_item_preferencecsBzjj|Wnty$YdS0tfdd|DS)NFc3s|]}j|VqdSrrKZis_satisfied_byrZ current_pinrrrrsz8Resolution._is_current_pin_satisfying..)rPrTrYallr")rrZrrrar_is_current_pin_satisfyings z%Resolution._is_current_pin_satisfyingcCs4i}|j|D]}|j||d\}}|||<q|S)Nr9)rKZget_dependenciesr\)rr(rUrrZr[rrr_get_criteria_to_updates  z"Resolution._get_criteria_to_updatec sg}|jD]z}Wn<tyX}z$||jWYd}~q WYd}~n d}~00tfdd|D}|st|j j j |dj j |<j j |gS|S)Nc3s|]}j|VqdSrr`rr(rrrrsz7Resolution._attempt_to_pin_criterion..)r*rdrr>rrbr"r'rLZpinningrPrTpoprUupdate)rrZrrErUeZ satisfiedrrer_attempt_to_pin_criterions$  "   z$Resolution._attempt_to_pin_criterioncstjdkrjd=j}|j\}}dd|jD||gfj |fdd} |}|rdSqdS) 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|]\}}||jfqSrr/rkvrrrr< sz)Resolution._backtrack..c sdD]Z\}}|sqzjj|}Wnty8YqYn0||}|durRdS|jj|<qdS)NFT)rPrUrYrA)rlr,rZincompatibilities_from_brokenrrr_patch_criterias    z.Resolution._backtrack.._patch_criteriaTF) lenrMrfrTpopitemrUitemsr>rLZ backtrackingrX)rZ broken_staterZr(rosuccessrrnr _backtracks  zResolution._backtrackc sPjrtdjttidg_|D]X}zj|dd\}}Wn0tyz}zt |j j WYd}~n d}~00|j j |<q0t|D]}j|fddj j D}|sjj j St|jd\}} || } | r*} | s2dd| D} t | nj|j qt|dS)Nzalready resolvedrSr9csg|]}j|s|qSr)rc)rr^r#rrr<Ks z&Resolution.resolve..)keycSsg|]}|jD]}|qqSrr8)rcr7rrrr<dr)rM RuntimeErrorrLZstartingrI collections OrderedDictr\rrDrr+rPrUrXrangeZstarting_roundrrZendingminr_rirtZ ending_roundrG) rr- max_roundsrrZr[rhZ round_indexZunsatisfied_criterion_itemsrZfailure_causesrsrErr#rresolve4s@ "        zResolution.resolveN)r r r r rpropertyrPrXr\r_rcrdrirtr}rrrrrJs    !HrJc Cs||vr dS||vrdS||D]b}z|t|}WntyNYq$Yn0||vrh||dSt||||r$||dSq$dS)NTF)r:idrYadd_has_route_to_root)rUruall_keys connectedppkeyrrrros     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)rrkrrr rz!_build_result..csi|]\}}|vr||qSrrrkrrrrr)rTgraphrU) rTrrrrrrUrr:rYZconnectr)rPrTrrrurrrrrr _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|)rJr2rNr}r)rr-r|Z resolutionrPrrrr}szResolver.resolveN)r)r r r r r Zbase_exceptionr}rrrrrsr)rxZ providersrZstructsrr namedtupler Exceptionr rr'objectr)rCrDrGrIrJrrrrrrrrs&   F i