ó
Ýēk^c           @` sy   d  d l  m Z m Z m Z m Z d  d l m Z d  d l m	 Z	 e	 e
  Z d   Z d   Z d   Z e d  Z d S(	   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   reduce(   t	   getLoggerc   	      c` sh  t  |   d k r d Sx' |  j   D] \ } } | j |  q# Wt t j |  j    t |  j    } |  j d   | D  x t	 r
t
 t d   |  j   D   } | sī Pn  x# | D] } | V|  j | d  qŧ Wx* t
 |  j    D] } | t |  8} qí Wq Wt  |   d k rdd d l m } d } | | j d j d	   |  j   D     n  d S(
   u'  Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceding sets.
i    Nc         S` s   i  |  ] } t    |  q S(    (   t   set(   t   .0t   item(    (    s4   lib/python2.7/site-packages/conda/common/toposort.pys
   <dictcomp>   s   	 c         s` s-   |  ]# \ } } t  |  d  k r | Vq d S(   i    N(   t   len(   R   R   t   dep(    (    s4   lib/python2.7/site-packages/conda/common/toposort.pys	   <genexpr>!   s    i   (   t   CondaValueErroru/   Cyclic dependencies exist among these items: {}u    -> c         s` s   |  ] } t  |  Vq d  S(   N(   t   repr(   R   t   x(    (    s4   lib/python2.7/site-packages/conda/common/toposort.pys	   <genexpr>/   s    (   R	   t   itemst   discardt   _reduceR   t   uniont   valuest   keyst   updatet   Truet   sortedt   popt   Nonet
   exceptionsR   t   formatt   join(	   t   datat   kt   vt   extra_items_in_depst   orderedR   R
   R   t   msg(    (    s4   lib/python2.7/site-packages/conda/common/toposort.pyt	   _toposort   s&    	(	"c         C` s^   t  |  j   d d   } | d d } |  j |  x! |  j   D] } | j |  qC W| S(   u   
    Pop an item from the graph that has the fewest dependencies in the case of a tie
    The winners will be sorted alphabetically
    t   keyc         S` s   t  |  d  |  d f S(   Ni   i    (   R	   (   R   (    (    s4   lib/python2.7/site-packages/conda/common/toposort.pyt   <lambda>6   s    i    (   R   R   R   R   R   (   R   R   R#   R
   (    (    s4   lib/python2.7/site-packages/conda/common/toposort.pyt   pop_key1   s    c         c` s§   t  |   d k r d St |   } x~ t rĒ y t |  } | VWq% t k
 r } t j | j d  |  sp d St |   Vt |   } q% q% t	 k
 r d SXq% Wd S(   u(  Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependencies, each subsequent set consists of items that depend upon
items in the preceding sets.
i    N(
   R	   R"   R   t   nextt
   ValueErrort   logt   debugt   argsR%   t   StopIteration(   R   t   tt   valuet   err(    (    s4   lib/python2.7/site-packages/conda/common/toposort.pyt   _safe_toposort@   s     			c         C` s`   d   |  j    D }  d |  k r6 |  d j d  n  | rL t t |    St t |    Sd  S(   Nc         S` s%   i  |  ] \ } } t  |  |  q S(    (   R   (   R   R   R   (    (    s4   lib/python2.7/site-packages/conda/common/toposort.pys
   <dictcomp>c   s   	 u   pythonu   pip(   R   R   t   listR/   R"   (   R   t   safe(    (    s4   lib/python2.7/site-packages/conda/common/toposort.pyt   toposorta   s    N(   t
   __future__R    R   R   R   t	   functoolsR   R   t   loggingR   t   __name__R(   R"   R%   R/   R   R2   (    (    (    s4   lib/python2.7/site-packages/conda/common/toposort.pyt   <module>   s   "	%		!