
    )hP                    0   d dl mZ d dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZ dd	lmZmZmZmZmZ erdd
l m!Z!m"Z" ddl#m$Z$ ddZ% G d deeeef         Z& G d deeeef         Z'	 	 	 	 	 	 	 	 	 	 ddZ(y)    )annotationsN)TYPE_CHECKING
CollectionGenericIterableMapping   )	CTKTRTDirectedGraphIterableViewIteratorMappingRequirementInformationStatebuild_iter_view   )AbstractResolverResult)	Criterion)InconsistentCandidateRequirementsConflictedResolutionImpossibleResolutionTooDeepResolverException)AbstractProvider
Preference)BaseReporterc                   | j                   }|j                         D ci c]  \  }}t        |      | }}}d |t        d       <   t               }|j	                  d        d h}| j
                  j                         D ]~  \  }}t        | j
                  |||      s||vr|j	                  |       |j                         D ]8  }		 |t        |	         }
|
|vr|j	                  |
       |j                  |
|       :  t        |j                         D ci c]  \  }}||v s|| c}}|| j
                        S c c}}w # t        $ r Y w xY wc c}}w )N)mappinggraphcriteria)r    itemsidr   addr"   _has_route_to_rootiter_parentKeyErrorconnectr   )stater    kvall_keysr!   	connectedkey	criterionppkeys              ^/var/www/html/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers/resolution.py_build_resultr4   "   sF   mmG;B==?%K41abeQh%KH%KHRX&3oE	IIdO!%I....0 %Y!%..#xKeIIcN&&( 	%A1 5 		$MM$$	%% ")--/D$!QQ)^AD + &L   Es#   D?EE
%E
	EEc                      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dZ	 	 	 	 ddZddZy)
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.
    c                .    || _         || _        g | _        y N)_p_r_states)selfproviderreporters      r3   __init__zResolution.__init__G   s    
 02    c                \    	 | j                   d   S # t        $ r}t        d      |d }~ww xY w)Nr*   )r;   
IndexErrorAttributeError)r<   es     r3   r*   zResolution.stateP   s3    	1<<## 	1 )q0	1s    	+&+c                    | j                   d   }t        |j                  j                         |j                  j                         |j
                  dd       }| j                   j                  |       y)zPush a new state into history.

        This new state will be used to hold resolution results of the next
        coming round.
        rB   Nr    r"   backtrack_causes)r;   r   r    copyr"   rH   append)r<   baser*   s      r3   _push_new_statezResolution._push_new_stateW   s^     ||BLL%%']]'')!2215

 	E"r@   c           
     p   | j                   j                  ||       | j                  j                  |      }|j	                  |      }|rt        |j                        }ng }| j                  j                  |t        |t        j                  d      ||gi      t        |t        j                  d      ||i            }|r1t        |j                        }|j                  t        ||             nt        ||      g}t        t!        |      ||      }|j"                  st%        |      |||<   y )N)requirementparent)requirement_or_candidateiter_requirementincompatibilities
identifierrequirementsrR   
candidatesinformationrR   )r:   adding_requirementr9   identifygetlistrR   find_matchesr   operatormethodcaller
attrgetterrX   rJ   r   r   r   rW   r   )	r<   r"   rN   rO   rT   r0   rR   matchesrX   s	            r3   _add_to_criteriazResolution._add_to_criteriae   s1    	""{6"JWW%%{%K
LL,	 $Y%@%@ A "''&&!(%%&89k]+
 .##$78./ ' 
 y445K5k6JK1+vFGK&w/#/
	
 ##(33(r@   c           
     "   |sy|j                         D ]t  \  }}t        |j                  |j                  D cg c]7  }|j                  '| j
                  j                  |j                        |vr|9 c}|j                        ||<   v yc c}w )aW  Remove information from parents of criteria.

        Concretely, removes all values from each criterion's ``information``
        field that have one of ``parents`` as provider of the requirement.

        :param criteria: The criteria to update.
        :param parents: Identifiers for which to remove information from all criteria.
        N)r#   r   rW   rX   rO   r9   rZ   rR   )r<   r"   parentsr/   r0   rX   s         r3   !_remove_information_from_criteriaz,Resolution._remove_information_from_criteria   s     &nn. 	NC%$$ (1'<'<##**277++K,>,>?wN	   ++HSM	s   <Bc                V   | j                   j                  || j                  j                  t	        | j                  j
                  t        j                  d            t	        | j                  j
                  t        j                  d            | j                  j                        S )NrW   rX   )rT   resolutionsrW   rX   rH   )	r9   get_preferencer*   r    r   r"   r^   r`   rH   )r<   names     r3   _get_preferencezResolution._get_preference   s    ww%%

**&

####L1 (

####M2 "ZZ88 & 
 	
r@   c                     	  j                   j                  |   t         fd|j	                         D              S # t        $ r Y yw xY w)NFc              3  X   K   | ]!  }j                   j                  |        # yw)rN   	candidateNr9   is_satisfied_by).0rcurrent_pinr<   s     r3   	<genexpr>z8Resolution._is_current_pin_satisfying.<locals>.<genexpr>   s-      
 GG##[#I
   '*)r*   r    r(   allrQ   )r<   ri   r0   rs   s   `  @r3   _is_current_pin_satisfyingz%Resolution._is_current_pin_satisfying   sU    	**,,T2K  
//1
 
 	
  		s   A   	AAc                    | j                   j                  j                         }| j                  j	                  |      D ]  }| j                  |||        |S )Nrn   rO   )r*   r"   rI   r9   get_dependenciesrb   )r<   rn   r"   rN   s       r3   _get_updated_criteriaz Resolution._get_updated_criteria   sW    ::&&++-7733i3H 	KK!!(K	!J	Kr@   c                     j                   j                  |   }g }|j                  D ]  	  j                        }t         fd|j                         D              }|st        |       j
                  j                          j                   j                  j                  |        j                   j                  j                  |d         j                   j                  |<   g c S  |S # t        $ rL} j
                  j                  |j                         |j                  |j                         Y d }~d }~ww xY w)Nc              3  X   K   | ]!  }j                   j                  |        # ywrm   ro   )rq   rr   rn   r<   s     r3   rt   z7Resolution._attempt_to_pin_criterion.<locals>.<genexpr>   s-       ''A'Kru   ry   )r*   r"   rW   r|   r   r:   rejecting_candidater0   rJ   rv   rQ   r   pinningupdater    pop)r<   ri   r0   causesr"   rE   	satisfiedrn   s   `      @r3   _attempt_to_pin_criterionz$Resolution._attempt_to_pin_criterion   s   JJ''-	*,"-- 	I55i@  "335 I +IyAAGGOOiO0JJ&&x0 JJ""4.'0DJJt$I7	> 9 * ++AKKCakk*s   C77	E AEEc                @   |D ]  \  }}|s
	 | j                   j                  |   }| j                  j	                  |t        | j                   j                  t        j                  d            t        | j                   j                  t        j                  d      ||i            }t        |      }|s y|j                  |j                         t        |t        |j                        |      | j                   j                  |<    y# t        $ r Y w xY w)NrQ   rR   rS   FrV   T)r*   r"   r(   r9   r]   r   r^   r_   r`   r   extendrR   r   r\   rX   )r<   incompatibilities_from_brokenr+   rR   r0   ra   rW   s          r3   _patch_criteriazResolution._patch_criteria   s   
 %B 	 A $ JJ//2	 gg**,JJ''))*<= #2JJ''''(;<)*# + G ,;7+CJ$$Y%@%@A%.% !6!67"3&DJJ"/	8 /  s   D	DDc                   t        j                  d |D        d |D              }|D ch c]  }| j                  j                  |       }}t	        | j
                        dk\  rK| j
                  d= | j                  }	 	 | j
                  j                         }|j                  j                         \  }}||vrna| j                  j                  |      D ch c]  }| j                  j                  |       }	}|	j                  |      sn|j                  sn|j                  j!                         D 
cg c]  \  }
}|
t#        |j$                        f }}
}|j'                  ||gf       | j)                          | j+                  |      }|ryt	        | j
                        dk\  rKyc c}w # t        t        f$ r t        |      dw xY wc c}w c c}}
w )a2  Perform backjumping.

        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.  Identify Z. The incompatibility is not always caused by the latest
            state. For example, given three requirements A, B and C, with
            dependencies A1, B1 and C1, where A1 and B1 are incompatible: the
            last state might be related to C, so we want to discard the
            previous state.
        2.  Discard Z.
        3.  Discard Y but remember its incompatibility information gathered
            previously, and the failure we're dealing with right now.
        4.  Push a new state Y' based on X, and apply the incompatibility
            information from Y to Y'.
        5a. If this causes Y' to conflict, we need to backtrack again. Make Y'
            the new Z and go back to step 2.
        5b. If the incompatibilities apply cleanly, end backtracking.
        c              3  N   K   | ]  }|j                   |j                     y wr8   rz   rq   cs     r3   rt   z'Resolution._backjump.<locals>.<genexpr>5  s     >!)=QXX>s   %%c              3  4   K   | ]  }|j                     y wr8   )rN   r   s     r3   rt   z'Resolution._backjump.<locals>.<genexpr>6  s     +qQ]]+s      rB   TNF)	itertoolschainr9   rZ   lenr;   r*   r   r    popitemrC   r(   r   r{   
isdisjointr"   r#   r\   rR   rJ   rL   r   )r<   r   incompatible_reqsrr   incompatible_depsbroken_stateri   rn   dcurrent_dependenciesr+   r,   r   successs                 r3   	_backjumpzResolution._backjump  s   > 09>v>+F+0
 ;LLQTWW--a0LL$,,1$R   ::LA#'<<#3#3#5L&2&:&:&B&B&DOD) 00
 261I1I)1T(,-DGG$$Q'($ ( ,667HI
 $++3 8 <H;P;P;V;V;X-371aD,,-.-) -
 *00$1DE  "**+HIG [ $,,1$f i M #H- A.v6D@A(-s   "F27F7 "G;!G7Gc           
         t        |D ci c]  }|j                  D ]  }t        |      | ! c}}j                               S c c}}w )z5Extract causes from list of criterion and deduplicate)r\   rX   r$   values)r<   criteronr   is       r3   _extract_causeszResolution._extract_causesn  s>     xG!GARUAXGUGNNPQQGs   $A
c                   | j                   rt        d      | j                  j                          t	        t        j                         i g       g| _         |D ]+  }	 | j                  | j                  j                  |d        - | j                          t        |      D ]  }| j                  j!                  |       | j                  j                  j#                         D cg c]  \  }}| j%                  ||      s| }}}|s4| j                  j'                  | j                         | j                  c S t)        | j                  j                  j+                               t)        |      z
  }	t-        |      dkD  rt/        | j0                  j3                  || j                  j4                  t7        | j                  j                  t9        j:                  d            t7        | j                  j                  t9        j:                  d            | j                  j<                  	            }
n|}
|
st        d
      t-        |
      dkD  rt?        |
| j@                        }n|
d   }| jC                  |      }|rx| jE                  |      }| j                  jG                  |       | jI                  |      }|| j                  j<                  d d  |st        | j                  j<                        | j                  j                  j#                         D ch c]  \  }}||	v r| j%                  ||      s| }}}| jK                  | j                  j                  |       | j                          | j                  jM                  || j                         	 tO        |      # t        $ r%}t        |j                  j                        |d }~ww xY wc c}}w c c}}w )Nzalready resolvedrG   rz   )index)r*   r   rW   rX   )identifiersrg   rW   rX   rH   z-narrow_requirement_selection returned 0 names)r/   r   )r   )r   r*   )(r;   RuntimeErrorr:   startingr   collectionsOrderedDictrb   r*   r"   r   r   r0   rX   rL   rangestarting_roundr#   rw   endingsetkeysr   r\   r9   narrow_requirement_selectionr    r   r^   r`   rH   minrj   r   r   resolving_conflictsr   re   ending_roundr   )r<   rU   
max_roundsrr   rE   round_indexr/   r0   unsatisfied_namessatisfied_namesnarrowed_unstatisfied_namesri   failure_criterionr   r   newly_unsatisfied_namess                   r3   resolvezResolution.resolvet  s   <<122 #//1!#
  	KAK%%djj&9&91T%J	K 	 , K	FKGG"""5 '+jj&9&9&?&?&A!"C66sIF ! ! %TZZ0zz! "$**"5"5":":"<=DU@VVO$%).2GG88$5$(JJ$6$6#2 JJ//$//=$ %4 JJ//$//>% *.)D)D 9 /+  /@+ /"#RSS ./!36D<P<PQ215 $ > >t D --.?@ ++6+:..017

++A. .tzz/J/JKK +/***=*=*C*C*E+&Yo- ;;CK +' + 66JJ'')@ $$&GG  {$** EWK	FZ  
++k * K*1;;+B+BCJK!x+s$   (N8*O)("O/8	O& O!!O&N)r=   zAbstractProvider[RT, CT, KT]r>   zBaseReporter[RT, CT, KT]returnNone)r   State[RT, CT, KT])r   r   )r"   dict[KT, Criterion[RT, CT]]rN   r   rO   z	CT | Noner   r   )r"   r   rd   zCollection[KT]r   r   )ri   r   r   r   )ri   r   r0   zCriterion[RT, CT]r   bool)rn   r
   r   r   )ri   r   r   list[Criterion[RT, CT]])r   zlist[tuple[KT, list[CT]]]r   r   )r   $list[RequirementInformation[RT, CT]]r   r   )r   r   r   r   )rU   Iterable[RT]r   intr   r   )__name__
__module____qualname____doc__r?   propertyr*   rL   rb   re   rj   rw   r|   r   r   r   r   r    r@   r3   r6   r6   @   s    3.3 +3 
	3 1 1#*)-*) *) 	*)
 
*)X3>L	6




#4

	

#J!-F!	!FWrR/R	-Rf,r@   r6   c                  *    e Zd ZdZeZ	 d	 	 	 	 	 ddZy)Resolverz3The thing that performs the actual resolution work.c                ~    t        | j                  | j                        }|j                  ||      }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.
        )r   )r6   r=   r>   r   r4   )r<   rU   r   
resolutionr*   s        r3   r   zResolver.resolve  s9    @  t}}=
""<J"GU##r@   N)d   )rU   r   r   r   r   Result[RT, CT, KT])r   r   r   r   r   base_exceptionr   r   r@   r3   r   r     s0    =&N
 "$""$ "$ 
	"$r@   r   c                    ||v ry|| vry|J | |   j                         D ]I  }	 |t        |         }||v r|j                  |        yt	        | |||      s8|j                  |        y y# t        $ r Y Xw xY w)NTF)r'   r$   r(   r%   r&   )r"   r/   r-   r.   r1   r2   s         r3   r&   r&     s     i
(??c]&&( 
	BqE?D 9MM#hh	BMM#
   		s   A//	A;:A;)r*   r   r   r   )
r"   zMapping[KT, Criterion[RT, CT]]r/   z	KT | Noner-   zdict[int, KT | None]r.   zset[KT | None]r   r   ))
__future__r   r   r   r^   typingr   r   r   r   r   structsr
   r   r   r   r   r   r   r   r   abstractr   r   r0   r   
exceptionsr   r   r   r   r   	providersr   r   	reportersr   r4   r6   r   r&   r   r@   r3   <module>r      s    "    H H
 
 
 /    8(<Z,R$ Z,z'$B
+ '$T,	 # 	
 
r@   