
    wBf                     J    d Z ddlmZ ddlmZ  ee      Zd Zd Z	d Z
d	dZy)
z#Topological sorting implementation.    )reduce)	getLoggerc           	   #     K   t        |       dk(  ry| j                         D ]  \  }}|j                  |        t        t        j
                  | j                               t	        | j                               z
  }| j                  |D ci c]  }|t	                c}       	 t        | j                         D ch c]  \  }}t        |      dk(  s| c}}      }|snJ|D ]  }| | j                  |d        t        | j                               D ]  }|t	        |      z  } t        |       dk7  rCddlm} d} ||j                  dj                  d | j                         D                          yc c}w c c}}w w)a;  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.
    r   N   )CondaValueErrorz/Cyclic dependencies exist among these items: {}z -> c              3   2   K   | ]  }t        |        y w)N)repr).0xs     5lib/python3.12/site-packages/conda/common/toposort.py	<genexpr>z_toposort.<locals>.<genexpr>-   s     4RT!W4Rs   )lenitemsdiscard_reducesetunionvalueskeysupdatesortedpop
exceptionsr   formatjoin)	datakvextra_items_in_depsitemdeporderedr   msgs	            r   	_toposortr$      sQ     4yA~ 

 1			! "#))T[[];c$))+>NNKK)<=su=>


N94CA$NO 	!DJHHT4 	! $++-( 	 C3w<C	   4yA~0?cjj4Rdiik4R)RSTT	  >Ns%   B
FF  F>F
F
B2Fc                     t        | j                         d       }|d   d   }| j                  |       | j                         D ]  }|j	                  |        |S )z
    Pop an item from the graph that has the fewest dependencies in the case of a tie
    The winners will be sorted alphabetically
    c                 (    t        | d         | d   fS )N   r   )r   )r    s    r   <lambda>zpop_key.<locals>.<lambda>5   s    3tAw<a2I     )keyr   )r   r   r   r   r   )r   r   r*   r!   s       r   pop_keyr+   0   sW    
 4::<%IJE
(1+CHHSM{{} C Jr)   c              #   $  K   t        |       dk(  ryt        |       }	 	 t        |      }| # t        $ rK}t        j                  |j                  d          | sY d}~yt        |        t        |       }Y d}~ad}~wt        $ r Y yw xY ww)a<  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.
    r   N)	r   r$   next
ValueErrorlogdebugargsr+   StopIteration)r   tvalueerrs       r   _safe_toposortr6   @   s      4yA~$A
	GEK   
	IIchhqk"$-$A 		sB   B/ B	B$A>B!A>9B>B
BBBc                     | j                         D ci c]  \  }}|t        |       } }}d| v r| d   j                  d       |rt        t	        |             S t        t        |             S c c}}w )Npythonpip)r   r   r   listr6   r$   )r   safer   r   s       r   toposortr<   `   sj    "&**,/$!QAs1vI/D/4 	Xu%N4())IdO$$ 0s   A/N)T)__doc__	functoolsr   r   loggingr   __name__r/   r$   r+   r6   r<    r)   r   <module>rB      s1    * ' "UJ @%r)   