U ʗReD@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__rr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/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 sz1RequirementsConflicted.__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(sz0InconsistentCandidate.__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-rrrr@szCriterion.__init__cCs ddd|jD}d|S)Nrcss|]\}}d||VqdS)z({!r}, via={!r})N)r )rreqr rrrrFsz%Criterion.__repr__..z Criterion({}))r!r,r )r requirementsrrr__repr__Es zCriterion.__repr__cCsdd|jDS)Ncss|] }|jVqdSr)rrirrrrMsz-Criterion.iter_requirement..r,r#rrrr"LszCriterion.iter_requirementcCsdd|jDS)Ncss|] }|jVqdSrr r1rrrrPsz(Criterion.iter_parent..r3r#rrr iter_parentOszCriterion.iter_parentN)r r r rrr0r"r5rrrrr),s r)c@s eZdZdS)ResolutionErrorN)r r r rrrrr6Ssr6cseZdZfddZZS)ResolutionImpossiblecstt||||_dSr)rr7rcauses)rr8rrrrXszResolutionImpossible.__init__r r r rr&rrrrr7Wsr7cseZdZfddZZS)ResolutionTooDeepcstt||||_dSr)rr:r round_count)rr;rrrr_szResolutionTooDeep.__init__r9rrrrr:^sr:Statez!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)rproviderreporterrrrroszResolution.__init__cCs.z |jdWStk r(tdYnXdS)Nstate)r@ IndexErrorAttributeErrorr#rrrrDts 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. rCNmappingcriteriabacktrack_causes)r@r<rHcopyrIrJappend)rbaserDrrr_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- identifierr/r-r*)r?adding_requirementr>identifygetlistr- find_matchesroperator methodcaller attrgetterr,rLrr)rr+r) rrIrr rQrr-matchesr,rrr_add_to_criterias>    zResolution._add_to_criteriac Cs>|jj||jjt|jjtdt|jjtd|jjdS)Nr+r,)rQ resolutionsr+r,rJ) r>get_preferencerDrHrrIrWrYrJ)rnamerrr_get_preferenceszResolution._get_preferencecsDzjj|Wntk r&YdSXtfdd|DS)NFc3s|]}jj|dVqdS)rr(Nr>is_satisfied_byr current_pinrrrrsz8Resolution._is_current_pin_satisfying..)rDrHKeyErrorallr")rr^rrrcr_is_current_pin_satisfyingsz%Resolution._is_current_pin_satisfyingcCs4|jj}|jj|dD]}|j|||dq|S)Nr(r4)rDrIrKr>get_dependenciesr[)rr(rIrrrr_get_updated_criterias z Resolution._get_updated_criteriac sjj|}g}|jD]z}Wn6tk r^}z||jWYqW5d}~XYnXtfdd|D}|st |j j djj |jj |djj |<gS|S)Nc3s|]}jj|dVqdSr`rarr(rrrrsz7Resolution._attempt_to_pin_criterion..rh)rDrIr+rjrrLrrfr"r'r?pinningupdaterHpop)rr^rr8rIe satisfiedrrkr_attempt_to_pin_criterions&     z$Resolution._attempt_to_pin_criterioncstjdkrjd=j}|j\}}dd|jD||gfjj |dfdd} |}|rdSqd 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. rCcSsg|]\}}|t|jfqSr)rUr-rkvrrr sz)Resolution._backtrack..rhc sD]\}}|sqzjj|}Wntk r:YqYnXjj|tjjtdtjjtd||id}t |}|sdS| |j t |t |j|djj|<qdS)Nr"r-rPFr*T)rDrIrer>rVrrWrXrYrextendr-r)rUr,)rtr-rrZr+incompatibilities_from_brokenrrr_patch_criteria s:    z.Resolution._backtrack.._patch_criteriaTF) lenr@rnrHpopitemrIitemsrLr? backtrackingrN)r broken_stater^r(rzsuccessrrxr _backtracks zResolution._backtrackc shjrtdjttigdg_|D]L}zjjj |ddWq2t k r|}zt |j j W5d}~XYq2Xq2t|D]}jj|dfddjj D}|sڈjjjdjSt|jd}|}|r@d d|D} jj| d } | jjdd<| sHt jjnjj|jd qt|dS) Nzalready resolvedrGr4)indexcs g|]\}}||s|qSr)rg)rkeyrr#rrrvhs z&Resolution.resolve..)rD)rcSsg|]}|jD]}|qqSrr3)rcr2rrrrvxs)r8)rrD)r@ RuntimeErrorr?startingr< collections OrderedDictr[rDrIrr7rr,rNrangestarting_roundr}endingminr_rqresolving_conflictsrrJ ending_roundr:) rr/ max_roundsrro round_indexunsatisfied_namesr^failure_causesr8rrr#rresolveLsF       zResolution.resolveN)r r r rrpropertyrDrNr[r_rgrjrqrrrrrrr=hs ' $Yr=c Cs||kr dS||krdS||D]d}z|t|}Wntk rPYq$YnX||krj||dSt||||r$||dSq$dS)NTF)r5idreadd_has_route_to_root)rIrall_keys connectedppkeyrrrrs    rResultzmapping graph criteriac s|j}dd|D}d|td<t}|ddh|jD]\}}t|j||s^qD||krp|||D]L}z|t|}Wntk rYqxYnX||kr||| ||qxqDt fdd|D||jdS)NcSsi|]\}}t||qSr)rrsrrr sz!_build_result..csi|]\}}|kr||qSrrrsrrrrs)rHgraphrI) rHr}rrrrIrr5reconnectr)rDrHrrrrrrrrr _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=rArBrr)rr/r resolutionrDrrrrszResolver.resolveN)r)r r r rr base_exceptionrrrrrrsr)rrW providersrstructsrrr namedtupler Exceptionr rr'objectr)r6r7r:r<r=rrrrrrrrs,   ' %