
0c@_ª:  ã               @   sZ  d  d l  Z  d d l m Z d d l m Z d d l m Z e  j d d d g ƒ Z Gd	 d
 „  d
 e	 ƒ Z
 Gd d „  d e
 ƒ Z Gd d „  d e
 ƒ Z Gd d „  d e ƒ Z Gd d „  d e
 ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z e  j d d ƒ Z Gd d „  d e ƒ Z d d „  Z e  j d d ƒ Z d d  „  Z Gd! d" „  d" e ƒ Z d S)#é    Né   )Úcollections_abc)ÚAbstractResolver)ÚDirectedGraphÚRequirementInformationÚrequirementÚparentc               @   s   e  Z d  Z d Z d S)ÚResolverExceptionzÆA 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__© r   r   ú?/tmp/pip-build-jynh7p1z/pip/pip/_vendor/resolvelib/resolvers.pyr	      s   r	   c                   s.   e  Z d  Z ‡  f d d †  Z d d „  Z ‡  S)ÚRequirementsConflictedc                s#   t  t |  ƒ j | ƒ | |  _ d  S)N)Úsuperr   Ú__init__Ú	criterion)Úselfr   )Ú	__class__r   r   r      s    zRequirementsConflicted.__init__c             C   s,   d j  d j d d „  |  j j ƒ  Dƒ ƒ ƒ S)NzRequirements conflict: {}z, c             s   s   |  ] } t  | ƒ Vq d  S)N)Úrepr)Ú.0Úrr   r   r   ú	<genexpr>   s    z1RequirementsConflicted.__str__.<locals>.<genexpr>)ÚformatÚjoinr   Úiter_requirement)r   r   r   r   Ú__str__   s    zRequirementsConflicted.__str__)r
   r   r   r   r   r   r   )r   r   r      s   r   c                   s.   e  Z d  Z ‡  f d d †  Z d d „  Z ‡  S)ÚInconsistentCandidatec                s/   t  t |  ƒ j | | ƒ | |  _ | |  _ d  S)N)r   r   r   Ú	candidater   )r   r   r   )r   r   r   r   !   s    	zInconsistentCandidate.__init__c             C   s2   d j  |  j d j d d „  |  j j ƒ  Dƒ ƒ ƒ S)Nz+Provided candidate {!r} does not satisfy {}z, c             s   s   |  ] } t  | ƒ Vq d  S)N)r   )r   r   r   r   r   r   )   s    z0InconsistentCandidate.__str__.<locals>.<genexpr>)r   r   r   r   r   )r   r   r   r   r   &   s    zInconsistentCandidate.__str__)r
   r   r   r   r   r   r   )r   r   r       s   r   c               @   sp   e  Z d  Z d Z d d „  Z d d „  Z e d d „  ƒ Z d d	 „  Z d
 d „  Z	 d d „  Z
 d d „  Z d S)Ú	CriterionaQ  Representation 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.
    c             C   s   | |  _  | |  _ | |  _ d  S)N)Ú
candidatesÚinformationÚincompatibilities)r   r!   r"   r#   r   r   r   r   A   s    		zCriterion.__init__c             C   s,   d j  d d „  |  j Dƒ ƒ } d j | ƒ S)Nz, c             s   s'   |  ] \ } } d  j  | | ƒ Vq d S)z({!r}, via={!r})N)r   )r   Úreqr   r   r   r   r   H   s   z%Criterion.__repr__.<locals>.<genexpr>zCriterion({}))r   r"   r   )r   Úrequirementsr   r   r   Ú__repr__F   s    	zCriterion.__repr__c             C   sm   | j  | g ƒ } t | t j ƒ s0 t | ƒ } |  d | d t | | ƒ g d g  ƒ } | si t | ƒ ‚ | S)z.Build an instance from a requirement.
        r!   r"   r#   )Úfind_matchesÚ
isinstancer   ÚSequenceÚlistr   r   )ÚclsÚproviderr   r   r!   r   r   r   r   Úfrom_requirementM   s    	zCriterion.from_requirementc             C   s   d d „  |  j  Dƒ S)Nc             s   s   |  ] } | j  Vq d  S)N)r   )r   Úir   r   r   r   ^   s    z-Criterion.iter_requirement.<locals>.<genexpr>)r"   )r   r   r   r   r   ]   s    zCriterion.iter_requirementc             C   s   d d „  |  j  Dƒ S)Nc             s   s   |  ] } | j  Vq d  S)N)r   )r   r.   r   r   r   r   a   s    z(Criterion.iter_parent.<locals>.<genexpr>)r"   )r   r   r   r   Úiter_parent`   s    zCriterion.iter_parentc             C   s–   t  |  j ƒ } | j t | | ƒ ƒ | j d d „  | Dƒ ƒ } t | t j ƒ s_ t  | ƒ } t |  ƒ | | t  |  j	 ƒ ƒ } | s’ t
 | ƒ ‚ | S)z>Build a new instance from this and a new requirement.
        c             S   s   g  |  ] \ } } | ‘ q Sr   r   )r   r   Ú_r   r   r   ú
<listcomp>h   s   	 z)Criterion.merged_with.<locals>.<listcomp>)r*   r"   Úappendr   r'   r(   r   r)   Útyper#   r   )r   r,   r   r   Zinfosr!   r   r   r   r   Úmerged_withc   s    !zCriterion.merged_withc                sg   t  |  j ƒ } | j ˆ  ƒ ‡  f d d †  |  j Dƒ } | sB d St |  ƒ | t  |  j ƒ | ƒ } | S)zœBuild a new instance from this, but excluding specified candidate.

        Returns the new instance, or None if we still have no valid candidates.
        c                s"   g  |  ] } | ˆ  k r | ‘ q Sr   r   )r   Úc)r   r   r   r1   w   s   	 z)Criterion.excluded_of.<locals>.<listcomp>N)r*   r#   r2   r!   r3   r"   )r   r   Z	incompatsr!   r   r   )r   r   Úexcluded_ofp   s    !zCriterion.excluded_ofN)r
   r   r   r   r   r&   Úclassmethodr-   r   r/   r4   r6   r   r   r   r   r    -   s   r    c               @   s   e  Z d  Z d S)ÚResolutionErrorN)r
   r   r   r   r   r   r   r8   ~   s   r8   c                   s"   e  Z d  Z ‡  f d d †  Z ‡  S)ÚResolutionImpossiblec                s#   t  t |  ƒ j | ƒ | |  _ d  S)N)r   r9   r   Úcauses)r   r:   )r   r   r   r   ƒ   s    zResolutionImpossible.__init__)r
   r   r   r   r   r   )r   r   r9   ‚   s   r9   c                   s"   e  Z d  Z ‡  f d d †  Z ‡  S)ÚResolutionTooDeepc                s#   t  t |  ƒ j | ƒ | |  _ d  S)N)r   r;   r   Úround_count)r   r<   )r   r   r   r   Š   s    zResolutionTooDeep.__init__)r
   r   r   r   r   r   )r   r   r;   ‰   s   r;   ÚStatezmapping criteriac               @   s”   e  Z d  Z d Z d d „  Z e d d „  ƒ Z d d „  Z d d	 „  Z d
 d „  Z	 d d „  Z
 d d „  Z d d „  Z d d „  Z d d „  Z d S)Ú
Resolutionz­Stateful resolution object.

    This is designed as a one-off object that holds information to kick start
    the resolution process, and holds the results afterwards.
    c             C   s   | |  _  | |  _ g  |  _ d  S)N)Ú_pÚ_rÚ_states)r   r,   Úreporterr   r   r   r   š   s    		zResolution.__init__c             C   s4   y |  j  d SWn t k
 r/ t d ƒ ‚ Yn Xd  S)Nr   Ústateéÿÿÿÿ)rA   Ú
IndexErrorÚAttributeError)r   r   r   r   rC   Ÿ   s    zResolution.statec             C   s|   y |  j  d } Wn- t k
 r@ t d t j ƒ  d i  ƒ } Yn( Xt d | j j ƒ  d | j j ƒ  ƒ } |  j  j | ƒ d S)z‰Push a new state into history.

        This new state will be used to hold resolution results of the next
        coming round.
        r   ÚmappingÚcriteriaNrD   )	rA   rE   r=   ÚcollectionsÚOrderedDictrG   ÚcopyrH   r2   )r   ÚbaserC   r   r   r   Ú_push_new_state¦   s     !zResolution._push_new_statec             C   sˆ   |  j  j | | ƒ |  j j | ƒ } y |  j j | } Wn* t k
 re t j |  j | | ƒ } Yn X| j	 |  j | | ƒ } | | f S)N)
r@   Zadding_requirementr?   ZidentifyrC   rH   ÚKeyErrorr    r-   r4   )r   r   r   ÚnameÚcritr   r   r   Ú_merge_into_criterion¶   s    z Resolution._merge_into_criterionc             C   sW   | \ } } y |  j  j | } Wn t k
 r: d  } Yn X|  j j | | j | j ƒ S)N)rC   rG   rN   r?   Zget_preferencer!   r"   )r   ÚitemrO   r   Zpinnedr   r   r   Ú_get_criterion_item_preferenceÁ   s    	z)Resolution._get_criterion_item_preferencec                sS   y ˆ j  j | ‰  Wn t k
 r, d SYn Xt ‡  ‡ f d d †  | j ƒ  Dƒ ƒ S)NFc             3   s$   |  ] } ˆ j  j | ˆ  ƒ Vq d  S)N)r?   Úis_satisfied_by)r   r   )Úcurrent_pinr   r   r   r   Ñ   s   z8Resolution._is_current_pin_satisfying.<locals>.<genexpr>)rC   rG   rN   Úallr   )r   rO   r   r   )rU   r   r   Ú_is_current_pin_satisfyingË   s    	z%Resolution._is_current_pin_satisfyingc             C   sL   i  } x? |  j  j | ƒ D]+ } |  j | d | ƒ\ } } | | | <q W| S)Nr   )r?   Zget_dependenciesrQ   )r   r   rH   r   rO   rP   r   r   r   Ú_get_criteria_to_updateÕ   s
    z"Resolution._get_criteria_to_updatec                só   g  } xæ | j  D]Û ‰  y ˆ j ˆ  ƒ } Wn8 t k
 rc } z | j | j ƒ w WYd  d  } ~ Xn Xt ‡  ‡ f d d †  | j ƒ  Dƒ ƒ } | s¡ t ˆ  | ƒ ‚ ˆ j j	 ˆ  ƒ ˆ j
 j j | d  ƒ ˆ  ˆ j
 j | <ˆ j
 j j | ƒ g  SW| S)Nc             3   s$   |  ] } ˆ j  j | ˆ  ƒ Vq d  S)N)r?   rT   )r   r   )r   r   r   r   r   ê   s   z7Resolution._attempt_to_pin_criterion.<locals>.<genexpr>)r!   rX   r   r2   r   rV   r   r   r@   ZpinningrC   rG   ÚpoprH   Úupdate)r   rO   r   r:   rH   ÚeZ	satisfiedr   )r   r   r   Ú_attempt_to_pin_criterionÜ   s$    z$Resolution._attempt_to_pin_criterionc             C   sÇ   |  j  d =x¶ t |  j  ƒ d k rÂ |  j  j ƒ  } y | j j ƒ  \ } } Wn t k
 ra w Yn X|  j j | ƒ |  j ƒ  |  j	 j
 | j | ƒ } | d  k r® |  j  d =q | |  j	 j
 | <d SWd S)Nr   é   TFrD   rD   )rA   ÚlenrY   rG   ÚpopitemrN   r@   ZbacktrackingrM   rC   rH   r6   )r   Z
prev_staterO   r   r   r   r   r   Ú
_backtracký   s     


zResolution._backtrackc                s³  ˆ  j  r t d ƒ ‚ ˆ  j ƒ  xw | D]o } y ˆ  j | d d  ƒ\ } } Wn7 t k
 r„ } z t | j j ƒ ‚ WYd  d  } ~ Xn X| ˆ  j j	 | <q& Wˆ  j
 j ƒ  xú t | ƒ D]ì } ˆ  j
 j | ƒ ˆ  j ƒ  ˆ  j } ‡  f d d †  ˆ  j j	 j ƒ  Dƒ }	 |	 s(ˆ  j  d =ˆ  j
 j | ƒ ˆ  j St |	 d ˆ  j ƒ\ } }
 ˆ  j | |
 ƒ } | rŒˆ  j ƒ  } | sŒd d „  | Dƒ } t | ƒ ‚ ˆ  j
 j | | ƒ q³ Wt | ƒ ‚ d  S)	Nzalready resolvedr   c                s%   g  |  ] } ˆ  j  | Œ  s | ‘ q Sr   )rW   )r   rR   )r   r   r   r1   4  s   	z&Resolution.resolve.<locals>.<listcomp>r   Úkeyc             S   s&   g  |  ] } | j  D] } | ‘ q q Sr   )r"   )r   rP   r.   r   r   r   r1   K  s   	 rD   )rA   ÚRuntimeErrorrM   rQ   r   r9   r   r"   rC   rH   r@   ZstartingÚrangeZstarting_roundÚitemsZendingÚminrS   r\   r`   Zending_roundr;   )r   r%   Ú
max_roundsr   rO   rP   r[   Zround_indexÚcurrZunsatisfied_criterion_itemsr   Zfailure_causesÚresultr:   r   )r   r   Úresolve  s>    	
%
	
zResolution.resolveN)r
   r   r   r   r   ÚpropertyrC   rM   rQ   rS   rW   rX   r\   r`   ri   r   r   r   r   r>   “   s   

!"r>   c             C   s®   | | k r d S| |  k r  d Sx‡ |  | j  ƒ  D]u } y | t | ƒ } Wn t k
 rb w1 Yn X| | k r€ | j | ƒ d St |  | | | ƒ r1 | j | ƒ d Sq1 Wd S)NTF)r/   ÚidrN   ÚaddÚ_has_route_to_root)rH   ra   Úall_keysÚ	connectedÚpÚpkeyr   r   r   rm   T  s     rm   ÚResultzmapping graph criteriac                sF  |  j  } d d „  | j ƒ  Dƒ } d  | t d  ƒ <t ƒ  } | j d  ƒ d  h ‰  x½ |  j j ƒ  D]¬ \ } } t |  j | | ˆ  ƒ sˆ qa | | k r¡ | j | ƒ xi | j ƒ  D][ } y | t | ƒ } Wn t k
 rß w® Yn X| | k rù | j | ƒ | j	 | | ƒ q® Wqa Wt
 d ‡  f d d †  | j ƒ  Dƒ d | d |  j ƒ S)Nc             S   s%   i  |  ] \ } } | t  | ƒ “ q Sr   )rk   )r   ÚkÚvr   r   r   ú
<dictcomp>l  s   	 z!_build_result.<locals>.<dictcomp>rG   c                s+   i  |  ]! \ } } | ˆ  k r | | “ q Sr   r   )r   rs   rt   )ro   r   r   ru   ‚  s   	 ÚgraphrH   )rG   rd   rk   r   rl   rH   rm   r/   rN   Úconnectrr   )rC   rG   rn   rv   ra   r   rp   rq   r   )ro   r   Ú_build_resultj  s.    			rx   c               @   s+   e  Z d  Z d Z e Z d d d „ Z d S)ÚResolverz8The thing that performs the actual resolution work.
    éd   c             C   s4   t  |  j |  j ƒ } | j | d | ƒ} t | ƒ S)a  Take 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.
        rf   )r>   r,   rB   ri   rx   )r   r%   rf   Ú
resolutionrC   r   r   r   ri   Ž  s    zResolver.resolveN)r
   r   r   r   r	   Zbase_exceptionri   r   r   r   r   ry   ˆ  s   ry   )rI   Úcompatr   Z	providersr   Ústructsr   Ú
namedtupler   Ú	Exceptionr	   r   r   Úobjectr    r8   r9   r;   r=   r>   rm   rr   rx   ry   r   r   r   r   Ú<module>   s$   QÁ