+
    :1jeB                        R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^RI	H
t
 ^RIHt ^RIHt ^RIHt ^R	IHt ]'       d   ^ R
IHt ^RIHt ]! ]4      t ! R R4      t ! R R]4      tR# )zImplements directed graphs to sort and manipulate packages within a prefix.

Object inheritance:

.. autoapi-inheritance-diagram:: PrefixGraph GeneralGraph
   :top-classes: conda.models.prefix_graph.PrefixGraph
   :parts: 1
)annotations)defaultdict)	getLogger)TYPE_CHECKING)context)on_win)CyclicalDependencyError)
NoarchType	MatchSpec)Iterable)PrefixRecordc                      ] tR t^ tRtRR R lltR tR t]R 4       t	R t
R tR	 tR
 tR tR t]R 4       t]R 4       t]R 4       t]R 4       tRtR# )PrefixGrapha.  
A directed graph structure used for sorting packages (prefix_records) in prefixes and
manipulating packages within prefixes (e.g. removing and pruning).

The terminology used for edge direction is "parents" and "children" rather than "successors"
and "predecessors". The parent nodes of a record are those records in the graph that
match the record's "depends" field.  E.g. NodeA depends on NodeB, then NodeA is a child
of NodeB, and NodeB is a parent of NodeA.  Nodes can have zero parents, or more than two
parents.

Most public methods mutate the graph.
c                    V ^8  d   QhRRRR/# )   recordszIterable[PrefixRecord]specszIterable[MatchSpec] )formats   "9lib/python3.14/site-packages/conda/models/prefix_graph.py__annotate__PrefixGraph.__annotate__.   s      -6I    c                	*  aa	 \        V4      p\        V4      pV  / ;V n        pV  / ;V n        pV F  o	\         ;QJ d    . R  S	P                   4       F  NK  	  5M! R  S	P                   4       4      pV Uau/ uFH  o\
        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       g   KE  SRbKJ  	  ppWsS	&   \        P                  V	3R lV 4       4      pV'       g   K  WS	&   K  	  V P                  4        R# u upi )c              3  8   "   T F  p\        V4      x  K  	  R # 5iNr
   .0ds   & r   	<genexpr>'PrefixGraph.__init__.<locals>.<genexpr>8   s     &J\y||\   c              3  D   <"   T F  qP                  S4      x  K  	  R # 5ir   match)r   mrecs   & r   r    r!   <   s     @-?wws||-?s    TFNc              3  X   <"   T F  qP                  S4      '       g   K  Vx  K!  	  R # 5ir   r$   )r   snodes   & r   r    r!   ?   s     *Mewwt}11es   *
*)	tuplesetgraphspec_matchesdependsanydictfromkeys	_toposort)
selfr   r   r-   r.   parent_match_specsr'   parent_nodesmatching_specsr*   s
   &&&   `  @r   __init__PrefixGraph.__init__.   s     .E

U+--LD!&&JT\\&J&JT\\&J!J #"C3@-?@333@-?@@ T	"  
 '$K!]]*Me*MMN~%3T"  	s   9D	D D Dc                T  aa V P                    Uu0 uF  q!P                  V4      '       g   K  VkK  	  ppVP                  R4      ;'       g    R F4  p\        VR7      oVP	                  V3R lV P                    4       4       K6  	  \        4       oV F4  pSP                  V4       SP	                  V P                  V4      4       K6  	  \        \        V3R lV P                   4      4      oS F  pV P                  V4       K  	  V P                  4        \        S4      # u upi )z
Remove all matching nodes, and any associated child nodes.

Args:
    spec (MatchSpec):

Returns:
    tuple[PrefixRecord]: The removed nodes.

track_features)featuresc              3  Z   <"   T F   pSP                  V4      '       g   K  Vx  K"  	  R # 5ir   r$   )r   r*   feature_specs   & r   r    *PrefixGraph.remove_spec.<locals>.<genexpr>V   s!     X|?Q?QRV?Ws   +
+c                   < V S9   # r   r   )r*   remove_theses   &r   <lambda>)PrefixGraph.remove_spec.<locals>.<lambda>\   s
    1Er   r   )r-   r%   get_raw_valuer   updater,   addall_descendantsr+   filter_remove_noder3   )r4   specr*   node_matchesfeature_namer>   rA   s   &&   @@r   remove_specPrefixGraph.remove_specE   s     *.Hzz$7GH !../?@FFBFL$l;LXXX G u DT" 4 4T :; ! V$EtzzRS Dd# !\""! Is
   D%D%c                  aa V P                   pV P                  oV UUu/ uF#  q"V Uu0 uF  q2W,          9   g   K  VkK  	  upbK%  	  ppp\        ;QJ d%    . V3R lVP                  4        4       F  NK  	  5M! V3R lVP                  4        4       4      o\        \	        V3R lV P                   4      4      pV F  pV P                  V4       K  	  V P                  4        V# u upi u uppi )z
A specialized method used to determine only dependencies of requested specs.

Returns:
    tuple[PrefixRecord]: The removed nodes.

c              3  R   <"   T F  w  rV'       d   K  VS9   g   K  Vx  K  	  R # 5ir   r   r   r*   childrenr.   s   &  r   r    JPrefixGraph.remove_youngest_descendant_nodes_with_specs.<locals>.<genexpr>o   s,      *
"8  $ 4 D"8   ''
'c                   < V S9   # r   r   )r*   youngest_nodes_with_specss   &r   rB   IPrefixGraph.remove_youngest_descendant_nodes_with_specs.<locals>.<lambda>u   s    (A Ar   )r-   r.   r+   itemsrH   rI   r3   )r4   r-   r*   keyinverted_graphremoved_nodesr.   rV   s   &     @@r   +remove_youngest_descendant_nodes_with_specs7PrefixGraph.remove_youngest_descendant_nodes_with_specsb   s     

((KP
KP4%>%35:+=33%>>5 	 
 %*E *
"0"6"6"8*
EE *
"0"6"6"8*
 %
!
 A4::N
 "Dd# " ?
s   	C.C)C)C.)C.c                	,    \        V P                  4      # r   )iterr-   )r4   s   &r   r   PrefixGraph.records|   s    DJJr   c                L  aa V P                   pV P                  o\        V P                   4      p\        4       o V UUu/ uF#  q3V Uu0 uF  qCW,          9   g   K  VkK  	  upbK%  	  ppp\        ;QJ d%    . V3R lVP	                  4        4       F  NK  	  5M! V3R lVP	                  4        4       4      pV'       g   M-V F%  pSP                  V4       V P                  V4       K'  	  K  \        \        V3R lV4      4      oV P                  4        S# u upi u uppi )z|Prune back all packages until all child nodes are anchored by a spec.

Returns:
    tuple[PrefixRecord]: The pruned nodes.

c              3  R   <"   T F  w  rV'       d   K  VS9  g   K  Vx  K  	  R # 5ir   r   rQ   s   &  r   r    $PrefixGraph.prune.<locals>.<genexpr>   s,      #&<ND $($< &<rT   c                   < V S9   # r   r   )r*   r[   s   &r   rB   #PrefixGraph.prune.<locals>.<lambda>   s
     5r   )	r-   r.   r+   r,   rX   rF   rI   rH   r3   )	r4   r-   original_orderr*   rY   rZ   prunable_nodesr[   r.   s	   &      @@r   prunePrefixGraph.prune   s    

((tzz*OTOTteBesuz/AsseBBu   #U #&4&:&:&<#UU #&4&:&:&<# N
 "&!!$'!!$' ' 5~F
 	# Cs    	D 	DD"D D c                	B   a \        V3R  lV P                   4       4      # )c              3  L   <"   T F  qP                   S8X  g   K  Vx  K  	  R # 5ir   name)r   r'   rm   s   & r   r    /PrefixGraph.get_node_by_name.<locals>.<genexpr>   s     B:CT1ACC:s   $
$)nextr-   )r4   rm   s   &fr   get_node_by_namePrefixGraph.get_node_by_name   s    B4::BBBr   c                	  a V P                   pV UUu/ uF#  qV Uu0 uF  q1W#,          9   g   K  VkK  	  upbK%  	  pppX.p\        4       o^ pV\        V4      8  dM   WEV,          ,           F.  pVS9  g   K  SP                  V4       VP	                  V4       K0  	  V^,          pK\  \        \        V3R lV4      4      # u upi u uppi )    c                   < V S9   # r   r   r*   
nodes_seens   &r   rB   -PrefixGraph.all_descendants.<locals>.<lambda>   
    );r   r-   r,   lenrF   appendr+   rH   )	r4   r*   r-   rY   rZ   nodesq
child_noderv   s	   &&      @r   rG   PrefixGraph.all_descendants   s    

KP
KP4%>%35:+=33%>>5 	 
 U
#e*n,1X66
Z/NN:.LL, 7 FAV;UCDD ?
s   	CCCCCc                	$  a V P                   pV.p\        4       o^ pV\        V4      8  dM   W#V,          ,           F.  pVS9  g   K  SP                  V4       VP	                  V4       K0  	  V^,          pK\  \        \        V3R lV4      4      # )rs   c                   < V S9   # r   r   ru   s   &r   rB   +PrefixGraph.all_ancestors.<locals>.<lambda>   rx   r   ry   )r4   r*   r-   r|   r}   parent_noderv   s   &&    @r   all_ancestorsPrefixGraph.all_ancestors   sz    

U
#e*n$1Xj0NN;/LL-  / FAV;UCDDr   c                    V P                   pW9  d   \        RV R24      hVP                  V4       V P                  P                  VR4       VP	                  4        F  w  rVP                  VR4       K  	  R# )z/Removes this node and all edges referencing it.znode z does not existN)r-   KeyErrorpopr.   rX   )r4   r*   r-   edgess   &&  r   rI   PrefixGraph._remove_node   sf    

U4&899		$dD) ;;=KDIIdD! )r   c                	   V P                   P                  4        UUu/ uF  w  rV\        P                  V4      bK  	  pppV P	                  V4       \
        P                  '       d   \        V P                  V4      4      pM\        V P                  V4      4      pV P                   pV Uu/ uF  qWQ,          bK  	  upV n         V# u uppi u upi r   )
r-   rX   r1   r2   _toposort_prepare_graphr   allow_cyclesr+   _topo_sort_handle_cycles_toposort_raise_on_cycles)r4   r*   parents
graph_copysorted_nodesoriginal_graphs   &     r   r3   PrefixGraph._toposort   s    >Bjj>N>N>P
>P]TD$--((>P 	 
 	$$Z0 !>!>z!JKL !?!?
!KLL=IJ\TN00\J

 Ks   !C	.Cc              #  	  "   V'       g   R #  \         P                  \        R VP                  4        4       R R7      4      pV'       g   MSV F  pVx  VP	                  VR 4       K  	  VP                  4        F  pV F  pVP	                  VR 4       K  	  K   	  K  \        V4      ^ 8w  d   \        \        V4      4      hR # 5i)Nc              3  N   "   T F  w  r\        V4      ^ 8X  g   K  Vx  K  	  R# 5i)rs   N)rz   r   r*   r   s   &  r   r    8PrefixGraph._toposort_raise_on_cycles.<locals>.<genexpr>   s      R}mdGPQ@QTT}s   %
%c                    V P                   # r   rl   xs   &r   rB   7PrefixGraph._toposort_raise_on_cycles.<locals>.<lambda>   s    !&&r   rY   )	r1   r2   sortedrX   r   valuesrz   r   r+   )clsr-   no_parent_nodesr*   r   s   &&   r   r   %PrefixGraph._toposort_raise_on_cycles   s     "mmRu{{}R(O #'
		$% ( !<<>+DKKd+ , * u:?)%,77 s   CCc              #  	*  aa"   SP                  4        F  w  r#VP                  VR 4       K  	  SP                  4        UUu0 uF  qD F  qUkK  	  K  	  uppoV3R lS 4       p\        V3R lV 4       R R7      pT R j  xL
  V P	                  S4      p  \        V4      p	V	x  K  u uppi  L.  \         dF   p
\        P                  RT
4       T P                  S4      x  T P	                  S4      p R p
?
Kf  R p
?
i\         d     R # i ; i5i)Nc              3  J   <"   T F  pSV,          '       d   K  Vx  K  	  R # 5ir   r   )r   r*   r-   s   & r   r    7PrefixGraph._topo_sort_handle_cycles.<locals>.<genexpr>   s      K%$uT{{%s   #
#c              3  :   <"   T F  pVS9  g   K  Vx  K  	  R # 5ir   r   )r   r*   nodes_that_are_parentss   & r   r    r      s#      1D55 1s   	
c                    V P                   # r   rl   r   s   &r   rB   6PrefixGraph._topo_sort_handle_cycles.<locals>.<lambda>  s    !&&r   r   z%r)rX   r   r   r   r   ro   r   logdebug_toposort_pop_keyStopIteration)r   r-   kvr   r*   nodes_without_parentsdisconnected_nodestvalueer   s   &f         @r   r   $PrefixGraph._topo_sort_handle_cycles   s     KKMDAEE!TN "
 !&"
 .W74D7D"
 !L% K#1
 !
 &%%))%0Q'"
 	& +  		$"++E2211%8  sY   ?DB+-DB1DB3 )	D3D>:C>8D>DDDDDc                    \        R V P                  4        4       4      ^ ,          ^,          pV P                  V4       V P                  4        F  pVP                  VR4       K  	  V# )z
Pop an item from the graph that has the fewest parents.
In the case of a tie, use the node with the alphabetically-first package name.
c              3  ^   "   T F#  w  r\        V4      VP                  4       V3x  K%  	  R # 5ir   )rz   dist_strr   s   &  r   r    0PrefixGraph._toposort_pop_key.<locals>.<genexpr>"  s&      *
GTmdS\4==?D1}s   +-N)r   rX   r   r   )r-   node_with_fewest_parentsr   s   &  r   r   PrefixGraph._toposort_pop_key  sh     $* *
GL{{}*
 $

$$  			*+||~GKK0$7 & ('r   c                	   V  FU  pVP                   R 8X  g   K  W,          p\        V4       F(  pVP                   R8X  g   K  VP                  VR4       K*  	  KW  	  \        R V  4       R4      p\        R V  4       R4      pV'       dR   Vf   \	        R4      hW,          pV P                  4        F&  w  rWR9   g   K  W9  g   K  VP                  V4       K(  	  \        '       d   \        R V  4       R4      pV'       dr   W,          pV P                  4        FS  w  r\        VR4      '       g   K  VP                  \        P                  8X  g   K:  W9  g   KB  VP                  V4       KU  	  R# R# R# )pythonpipNc              3  J   "   T F  qP                   R 8X  g   K  Vx  K  	  R# 5i)menuinstNrl   r   r*   s   & r   r    6PrefixGraph._toposort_prepare_graph.<locals>.<genexpr><  s     Put		Z8Oddu   #
#c              3  J   "   T F  qP                   R 8X  g   K  Vx  K  	  R# 5i)r   Nrl   r   s   & r   r    r   =  s     LUTii86KDDUr   z.Found menuinst without Python in prefix graph.c              3  J   "   T F  qP                   R 8X  g   K  Vx  K  	  R# 5i)condaNrl   r   s   & r   r    r   N  s     Ng9Mttr   noarch)rm   r+   r   ro   RuntimeErrorrX   
setdefaultr   hasattrr   r	   r   )	r-   r*   r   parentmenuinst_nodepython_nodemenuinst_parents
conda_nodeconda_parentss	   &        r   r   #PrefixGraph._toposort_prepare_graph,  s1    DyyH$+#GnF{{e+FD1 -  PuPRVWLULdS ""#STT$3!&)d.J&&}5 "/ 6 NNPTUJ % 1%*[[]MDh// KK:+<+<< 5**:6 &3  r   )r-   r.   Nr   )__name__
__module____qualname____firstlineno____doc__r8   rM   r\   propertyr   rh   rp   rG   r   rI   r3   classmethodr   r   staticmethodr   r   __static_attributes__r   r   r   r   r       s    .#:4    BCE"E	" 8 82 % %N ( ( +7 +7r   r   c                  6   a  ] tR tRtRtRV 3R lltR tRtV ;t# )GeneralGraphi  a'  
Compared with PrefixGraph, this class takes in more than one record of a given name,
and operates on that graph from the higher view across any matching dependencies.  It is
not a Prefix thing, but more like a "graph of all possible candidates" thing, and is used
for unsatisfiability analysis
c                	  < \        V4      p\        S
V `	  W4       \        \        4      V n        V F  pV P
                  P                  VP                  / 4      p\         ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4       F>  pVP                  VP                  / 4      pVP                  V4       WdVP                  &   K@  	  W@P
                  VP                  &   K  	  / p\        \        V P                  P                  4       4      4       FZ  w  r8VP                  VP                  / 4      p	V	P                  \        P                  R V 4       4      4       WVP                  &   K\  	  Wpn        R# )c              3  8   "   T F  p\        V4      x  K  	  R # 5ir   r
   r   s   & r   r    (GeneralGraph.__init__.<locals>.<genexpr>  s     @<aYq\\<r"   c              3  8   "   T F  qP                   x  K  	  R # 5ir   rl   )r   _s   & r   r    r     s     #ALqFFLr"   N)r+   superr8   r   r1   specs_by_namegetrm   r/   r   reversedlistr-   rX   rE   r2   graph_by_name)r4   r   r   r*   parent_dictdepdepsconsolidated_graphr6   cg	__class__s   &&&       r   r8   GeneralGraph.__init__  s*   .((.D,,00B?Ku@4<<@uu@4<<@@"sxx4$(,CHH% A -8tyy)   "*4

0@0@0B+C"DD#''		26BIIdmm#AL#AAB,.tyy) #E 0r   c                \   . pVP                  V.4       . pV'       Ed   VP                  ^ 4      pVR,          pWd9   d   K+  VP                  V4       Wb8X  d   V# . pV P                  P                  VP                  4      pVf   Kq  VP                  4        F  w  rVP                  \        V
4      4       K!  	  V Fh  pVP                  VP                  8X  d   VP                  VP                  8w  d   K;  \        V4      pVP                  V4       VP                  V4       Kj  	  EK  R# )z/Return shorted path from root_spec to spec_nameN)	r{   r   r   r   rm   rX   extendr   version)r4   	root_spectarget_specqueuevisitedpathr*   rR   r   r   r   adjnew_paths   &&&          r   breadth_first_search_by_name)GeneralGraph.breadth_first_search_by_name  s    i[!e99Q<D8DNN4 "H&&**4995E} ;;=T
+ )88{///CKK;CVCV4V#DzHOOC(LL*   r   )r   r   r   )	r   r   r   r   r   r8   r   r   __classcell__)r   s   @r   r   r     s    0(+ +r   r   N)r   
__future__r   collectionsr   loggingr   typingr   base.contextr   common.compatr   
exceptionsr   enumsr	   
match_specr   collections.abcr   r   r   r   r   r   r   r   r   r   <module>r     sS    # #    " " 0  !(%x7 x7j5+; 5+r   