3 igD@sddlZddlZddlmZddlmZmZmZejdddgZ Gdd d e Z Gd d d e Z Gd d d e Z GdddeZGddde ZGdddeZGdddeZejddZGdddeZddZejddZddZGd 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?/tmp/pip-build-88gy_88q/pip/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)rr r 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 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||_||_||_dS)N) candidates informationincompatibilities)rr#r$r%rrrrAszCriterion.__init__cCs djdd|jD}dj|S)Nz, css|]\}}dj||VqdS)z({!r}, via={!r})N)r)rreqr rrrrHsz%Criterion.__repr__..z Criterion({}))rr$r)r requirementsrrr__repr__Fs zCriterion.__repr__cCsdd|jDS)Ncss|] }|jVqdS)N)r)rirrrrNsz-Criterion.iter_requirement..)r$)rrrrrMszCriterion.iter_requirementcCsdd|jDS)Ncss|] }|jVqdS)N)r )rr)rrrrQsz(Criterion.iter_parent..)r$)rrrr iter_parentPszCriterion.iter_parentN)r r r rrr(rr*rrrrr"-s r"c@s eZdZdS)ResolutionErrorN)r r r rrrrr+Tsr+cseZdZfddZZS)ResolutionImpossiblecstt|j|||_dS)N)rr,rcauses)rr-)rrrrYszResolutionImpossible.__init__)r r r rrrr)rrr,Xsr,cseZdZfddZZS)ResolutionTooDeepcstt|j|||_dS)N)rr.r round_count)rr/)rrrr`szResolutionTooDeep.__init__)r r r rrrr)rrr._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|_dS)N)_p_r_states)rproviderreporterrrrrpszResolution.__init__c Cs,y |jdStk r&tdYnXdS)Nrstate)r4 IndexErrorAttributeError)rrrrr7us zResolution.statecCs>|jd}t|jj|jj|jddd}|jj|dS)zPush a new state into history. This new state will be used to hold resolution results of the next coming round. rN)mappingcriteriabacktrack_causesr8)r4r0r;copyr<r=append)rbaser7rrr_push_new_state|s  zResolution._push_new_statec Cs|jj||d|jj|d}|j|}|r8t|j}ng}|jj|t|t j d||git|t j d||id}|rt|j }|j t||n t||g}tt|||d}|jst||||<dS)N)rr )Zrequirement_or_candidaterr%) identifierr'r%)r#r$r%)r3Zadding_requirementr2Zidentifygetlistr% find_matchesroperator methodcaller attrgetterr$r?rr"rr#r) rr<rr rBrr%matchesr$rrr_add_to_criterias6     zResolution._add_to_criteriacCs>|jj||jjt|jjtjdt|jjtjd|jjdS)Nr#r$)rBZ resolutionsr#r$r=) r2Zget_preferencer7r;rr<rFrHr=)rnamerrr_get_preferences  zResolution._get_preferencec sByjj|Wntk r$dSXtfdd|jDS)NFc3s|]}jj|dVqdS))rr!N)r2is_satisfied_by)rr) current_pinrrrrsz8Resolution._is_current_pin_satisfying..)r7r;KeyErrorallr)rrKrr)rNrr_is_current_pin_satisfyings z%Resolution._is_current_pin_satisfyingcCs8|jjj}x&|jj|dD]}|j|||dqW|S)N)r!)r )r7r<r>r2Zget_dependenciesrJ)rr!r<rrrr_get_updated_criterias z Resolution._get_updated_criteriacsjj|}g}x|jD]yj}Wn0tk rZ}z|j|jwWYdd}~XnXtfdd|jD}|st |j j djjj |jj j|djj |<gSW|S)Nc3s|]}jj|dVqdS))rr!N)r2rM)rr)r!rrrrsz7Resolution._attempt_to_pin_criterion..)r!)r7r<r#rRrr?rrPrr r3Zpinningupdater;pop)rrKrr-r<eZ satisfiedr)r!rr_attempt_to_pin_criterions&      z$Resolution._attempt_to_pin_criterioncsxtjdkrjd =jj}|jj\}}dd|jjDj||gfjj |dfdd}j |}|rdSqWd 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. rcSsg|]\}}|t|jfqSr)rDr%)rkvrrr sz)Resolution._backtrack..)r!csxD]\}}|sqyjj|}Wntk r:wYnXjj|tjjtjdtjjtjd||id}t |}|sdS|j |j t |t |j|djj|<qWdS)Nrr%)rBr'r%F)r#r$r%T)r7r<rOr2rErrFrGrHrextendr%r"rDr$)rXr%rrIr#)incompatibilities_from_brokenrrr_patch_criteria!s2  z.Resolution._backtrack.._patch_criteriaTFr8) lenr4rTr;popitemr<itemsr?r3Z backtrackingrA)rZ broken_staterKr!r]successr)r\rr _backtracks zResolution._backtrackc sZjrtdjjttjigdg_xT|D]L}yjjj |ddWq4t k r~}zt |j j WYdd}~Xq4Xq4Wjxt|D]}jj|dfddjj jD}|s܈jjjdjSt|jd}j|}|r0j} d d|Djjdd<| s8t jjnjjj|jd qWt|dS) Nzalready resolved)r;r<r=)r )indexcs g|]\}}j||s|qSr)rQ)rkeyr)rrrrZjsz&Resolution.resolve..)r7)rdcSsg|]}|jD]}|qqSr)r$)rcr)rrrrZ}s)rcr7)r4 RuntimeErrorr3Zstartingr0 collections OrderedDictrJr7r<rr,rr$rArangeZstarting_roundr`ZendingminrLrVrbr=Z ending_roundr.) rr' max_roundsrrUZ round_indexZunsatisfied_namesrKZfailure_causesrar)rrresolveMs<   "  zResolution.resolveN)r r r rrpropertyr7rArJrLrQrRrVrbrlrrrrr1is ' $Yr1cCs||kr dS||krdSxn||jD]^}y|t|}Wntk rPw&YnX||krh|j|dSt||||r&|j|dSq&WdS)NTF)r*idrOadd_has_route_to_root)r<rdall_keys connectedppkeyrrrrps   rpResultzmapping 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)rn)rrXrYrrr sz!_build_result..csi|]\}}|kr||qSrr)rrXrY)rrrrrvs)r;graphr<) r;r`rnrror<rpr*rOconnectru)r7r;rqrwrdrrsrtr)rrr _build_results.    ryc@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. )rk)r1r5r6rlry)rr'rk resolutionr7rrrrlszResolver.resolveN)r{)r r r rr Zbase_exceptionrlrrrrrzsrz)rgrFZ providersrstructsrrr namedtupler Exceptionr rr objectr"r+r,r.r0r1rpruryrzrrrrs(    ' %