
    <ȋh]                    N   U d dl mZ d dlZd dlZd dlZd dl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m Z  ddl!m"Z"m#Z# ddl$m%Z% dZ&de'd<   d#dZ( G d deee	e
f                   Z) G d deee	e
f                   Z*d$d"Z+dS )%    )annotationsN)TYPE_CHECKINGGeneric   )	CTKTRTDirectedGraphIterableViewIteratorMappingRequirementInformationStatebuild_iter_view   )AbstractResolverResult)	Criterion)InconsistentCandidateRequirementsConflictedResolutionImpossibleResolutionTooDeepResolverException)
CollectionIterableMapping)AbstractProvider
Preference)BaseReporterg?float_OPTIMISTIC_BACKJUMPING_RATIOstateState[RT, CT, KT]returnResult[RT, CT, KT]c                   | j         }d |                                D             }d |t          d           <   t                      }|                    d            d h| j                                        D ]\  }}t          | j        ||          s||vr|                    |           |                                D ]X}	 |t          |                   }n# t          $ r Y %w xY w||vr|                    |           |	                    ||           Yt          fd|                                D             || j                  S )Nc                4    i | ]\  }}t          |          |S  )id.0kvs      h/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/pip/_vendor/resolvelib/resolvers/resolution.py
<dictcomp>z!_build_result.<locals>.<dictcomp>(   s$    %K%K%K41abeeQ%K%K%K    c                $    i | ]\  }}|v 	||S r'   r'   )r*   r+   r,   	connecteds      r-   r.   z!_build_result.<locals>.<dictcomp>>   s$    DDD$!QQ)^^A^^^r/   )mappinggraphcriteria)r2   itemsr(   r
   addr4   _has_route_to_rootiter_parentKeyErrorconnectr   )	r!   r2   all_keysr3   key	criterionppkeyr1   s	           @r-   _build_resultr@   &   sq   mG%K%K7==??%K%K%KHHRXX&3ooE	IIdOOO!%I...00 % %Y!%.#xKK 	eIIcNNN&&(( 	% 	%A1   5  		$MM$$$$$	% DDDD'--//DDD   s   C
C('C(c                      e Zd ZdZd3dZed4d
            Zd5dZd6dZd7dZ	d8dZ
d9dZd:d Zd;d"Zd<d%Zd5d&Zd5d'Zd=d*Zd>d,Zd?d1Zd2S )@
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.
    providerAbstractProvider[RT, CT, KT]reporterBaseReporter[RT, CT, KT]r#   Nonec                d    || _         || _        g | _        t          | _        d | _        d | _        d S N)_p_r_statesr    _optimistic_backjumping_ratio_save_states_optimistic_start_round)selfrC   rE   s      r-   __init__zResolution.__init__K   s:    
 02 .K*<@37$$$r/   r"   c                b    	 | j         d         S # t          $ r}t          d          |d }~ww xY w)Nr!   )rL   
IndexErrorAttributeError)rP   es     r-   r!   zResolution.stateY   sC    	1<## 	1 	1 	1 ))q0	1s    
.).c                    | j         d         }t          |j                                        |j                                        |j        dd                   }| j                             |           dS )zPush a new state into history.

        This new state will be used to hold resolution results of the next
        coming round.
        rS   Nr2   r4   backtrack_causes)rL   r   r2   copyr4   rY   append)rP   baser!   s      r-   _push_new_statezResolution._push_new_state`   ss     |BL%%'']''))!21115
 
 

 	E"""""r/   r4   dict[KT, Criterion[RT, CT]]requirementr	   parent	CT | Nonec           
        | j                             ||           | j                            |          }|                    |          }|rt          |j                  }ng }| j                            |t          |t          j
        d          ||gi          t          |t          j        d          ||i                    }|r8t          |j                  }|                    t          ||                     nt          ||          g}t          t!          |          ||          }|j        st%          |          |||<   d S )N)r_   r`   )requirement_or_candidateiter_requirementincompatibilities
identifierrequirementsre   
candidatesinformationre   )rK   adding_requirementrJ   identifygetlistre   find_matchesr   operatormethodcaller
attrgetterrk   r[   r   r   r   rj   r   )	rP   r4   r_   r`   rg   r=   re   matchesrk   s	            r-   _add_to_criteriazResolution._add_to_criterian   s{    	""{6"JJJW%%{%KK
LL,,	 	# $Y%@ A A "'&&!(%&899k]+ 
 .#$788./  ' 
 
  	Hy455K5k6JJKKKK1+vFFGK&w//#/
 
 
	
 # 	4(333(r/   parentsCollection[KT]c                     sdS |                                 D ]5\  }}t          |j         fd|j        D             |j                  ||<   6dS )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.
        Nc                d    g | ],}|j         !j                            |j                   v*|-S rI   )r`   rJ   rm   )r*   rk   rv   rP   s     r-   
<listcomp>z@Resolution._remove_information_from_criteria.<locals>.<listcomp>   sM       ##*27++K,>??wNN	   ONNr/   )r5   r   rj   rk   re   )rP   r4   rv   r<   r=   s   ` `  r-   !_remove_information_from_criteriaz,Resolution._remove_information_from_criteria   s      	F&nn.. 	 	NC%$    '0'<   + HSMM	 	r/   namer   r   c                   | j                             || j        j        t	          | j        j        t          j        d                    t	          | j        j        t          j        d                    | j        j                  S )Nrj   rk   )rg   resolutionsrj   rk   rY   )	rJ   get_preferencer!   r2   r   r4   rq   rs   rY   )rP   r|   s     r-   _get_preferencezResolution._get_preference   s~    w%%
*&
##L11  (
##M22  "Z8 & 
 
 	
r/   r=   Criterion[RT, CT]boolc                     	  j         j        |         n# t          $ r Y dS w xY wt           fd|                                D                       S )NFc              3  P   K   | ] }j                             |           V  !dS )r_   	candidateNrJ   is_satisfied_by)r*   rcurrent_pinrP   s     r-   	<genexpr>z8Resolution._is_current_pin_satisfying.<locals>.<genexpr>   sL       
 
 G##[#II
 
 
 
 
 
r/   )r!   r2   r9   allrd   )rP   r|   r=   r   s   `  @r-   _is_current_pin_satisfyingz%Resolution._is_current_pin_satisfying   s    	*,T2KK 	 	 	55	 
 
 
 
 
//11
 
 
 
 
 	
s    
%%r   r   c                    | j         j                                        }| j                            |          D ]}|                     |||           |S )Nr   r`   )r!   r4   rZ   rJ   get_dependenciesru   )rP   r   r4   r_   s       r-   _get_updated_criteriaz Resolution._get_updated_criteria   s_    :&++--733i3HH 	K 	KK!!(K	!JJJJr/   list[Criterion[RT, CT]]c                p     j         j        |         }g }|j        D ]	                                }nQ# t          $ rD} j                            |j                   |                    |j                   Y d }~cd }~ww xY wt           fd|
                                D                       }|st          |           j                                        j         j                            |            j         j                            |d             j         j        |<   g c S |S )Nc              3  P   K   | ] }j                             |           V  !dS r   r   )r*   r   r   rP   s     r-   r   z7Resolution._attempt_to_pin_criterion.<locals>.<genexpr>   sL         ''A'KK     r/   r   )r!   r4   rj   r   r   rK   rejecting_candidater=   r[   r   rd   r   pinningupdater2   pop)rP   r|   r=   causesr4   rV   	satisfiedr   s   `      @r-   _attempt_to_pin_criterionz$Resolution._attempt_to_pin_criterion   sj   J'-	*,"- 	 	I55i@@)   ++AKCCCak***      "3355    I  B+IyAAAGOOiO000J&&x000 J""4...'0DJt$III s   8
B:BBincompatibilities_from_brokenlist[tuple[KT, list[CT]]]c                   |D ] \  }}|s		 | j         j        |         }n# t          $ r Y )w xY w| j                            |t          | j         j        t          j        d                    t          | j         j        t          j        d          ||i                    }t          |          }|s dS |
                    |j                   t          |t          |j                  |          | j         j        |<   dS )Nrd   re   rf   Fri   T)r!   r4   r9   rJ   rp   r   rq   rr   rs   r   extendre   r   ro   rk   )rP   r   r+   re   r=   rt   rj   s          r-   _patch_criteriazResolution._patch_criteria   s>   
 %B 	 	 A $  J/2		   g**,J')*<==  #2J''(;<<)*# # +  G ,;7+C+CJ uu$$Y%@AAA%.% !677"3& & &DJ""
 ts    
--c                D    | j         d | j        D             | _         dS dS )zCSave states for potential rollback if optimistic backjumping fails.Nc           	         g | ]O}t          |j                                        |j                                        |j        d d                    PS )NrX   )r   r2   rZ   r4   rY   )r*   ss     r-   rz   z*Resolution._save_state.<locals>.<listcomp>!  sf     ! ! !  INN,,Z__..%&%7%:  ! ! !r/   )rN   rL   rP   s    r-   _save_statezResolution._save_state  s>    $! ! ! ! !D %$r/   c                L    d| _         | j        r| j        | _        d| _        dS dS )z3Rollback states and disable optimistic backjumping.g        N)rM   rN   rL   r   s    r-   _rollback_stateszResolution._rollback_states*  s7    -0* 	%,DL $D	% 	%r/   r   $list[RequirementInformation[RT, CT]]c                p    t          j        d |D             d |D                       } fd|D             }t           j                  dk    rd j        d=  j        }	 	  j                                        }|j                                        \  }}n%# t          t          f$ r t          |          dw xY w j        s||vrnk j        r j        ||vr                                   fd j                            |          D             }|                    |          sn	|j        snd	 |j                                        D             }|                    ||gf                                                                  |          }	|	rdS t           j                  dk    dd
S )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  2   K   | ]}|j         	|j         V  d S rI   r   r*   cs     r-   r   z'Resolution._backjump.<locals>.<genexpr>Q  s+      >>!)=QX)=)=)=)=>>r/   c              3  $   K   | ]}|j         V  d S rI   )r_   r   s     r-   r   z'Resolution._backjump.<locals>.<genexpr>R  s$      ++qQ]++++++r/   c                D    h | ]}j                             |          S r'   rJ   rm   )r*   r   rP   s     r-   	<setcomp>z'Resolution._backjump.<locals>.<setcomp>T  s)    LLLQTW--a00LLLr/      rS   TNc                D    h | ]}j                             |          S r'   r   )r*   drP   s     r-   r   z'Resolution._backjump.<locals>.<setcomp>w  s6     ( ( (,-DG$$Q''( ( (r/   c                @    g | ]\  }}|t          |j                  fS r'   )ro   re   r)   s      r-   rz   z(Resolution._backjump.<locals>.<listcomp>  s9     - - -371aD,--.- - -r/   F)	itertoolschainlenrL   r!   r   r2   popitemrT   r9   r   rM   rN   r   rJ   r   
isdisjointr4   r5   r[   r]   r   )
rP   r   incompatible_reqsincompatible_depsbroken_stater|   r   current_dependenciesr   successs
   `         r-   	_backjumpzResolution._backjump1  sI   > 09>>v>>>++F+++0
 0
 MLLL:KLLL$,1$$R   :L&A#'<#3#3#5#5L&2&:&B&B&D&DOD))"H- A A A.v66D@A :$555 
 6')1$555$$&&&
( ( ( (151I1I)1T1T( ( ($ ,667HII 
 $+ M&P- -;G;P;V;V;X;X- - -)
 *00$1DEEE  """**+HIIG  tu $,1$$@ us   #5B "B;criteronc                X    t          d |D                                                       S )z5Extract causes from list of criterion and deduplicatec                B    i | ]}|j         D ]}t          |          |S r'   )rk   r(   )r*   r   is      r-   r.   z.Resolution._extract_causes.<locals>.<dictcomp>  s/    GGG!GGARUUAGGGGr/   )ro   values)rP   r   s     r-   _extract_causeszResolution._extract_causes  s-     GGxGGGNNPPQQQr/   rh   Iterable[RT]
max_roundsintc                     j         rt          d           j                                         t	          t          j                    i g           g _         |D ]Q}	                       j        j	        |d            &# t          $ r}t          |j        j                  |d }~ww xY w                                  d }d }t          |          D ]l} j                            |            j        ra j        Z|8|}t'          ||z
   j        z            }|dk    r                                  en |||z
  |k    r                                   fd j        j	                                        D             }|s) j                             j                    j        c S t/           j        j	                                                  t/          |          z
  t3          |          dk    rt5           j                            | j        j        t=           j        j	        t?          j         d	                    t=           j        j	        t?          j         d
                     j        j!                            }	n|}	|	st          d          t3          |	          dk    rtE          |	 j#                  }
n|	d         }
 $                    |
          }|r҉ %                    |          } j        &                    |           	  '                    |          }tQ          | o j        o j                  }n"# t          $ r  j        r
 j        rd}n Y nw xY w|r j        r                                  n| j        j!        d d <   |st           j        j!                  n_ fd j        j	                                        D             } )                     j        j	        |                                              j        *                    | j                   ntW          |          )Nzalready resolvedrX   r   )indexr   c                F    g | ]\  }}                     ||          |S r'   r   )r*   r<   r=   rP   s      r-   rz   z&Resolution.resolve.<locals>.<listcomp>  sC     ! ! !"C66sIFF!! ! !r/   )r!   r   rj   rk   )identifiersr~   rj   rk   rY   z-narrow_requirement_selection returned 0 names)r<   )r   Tc                N    h | ]!\  }}|v 	                     ||          |"S r'   r   )r*   r<   r=   satisfied_namesrP   s      r-   r   z%Resolution.resolve.<locals>.<setcomp>  sJ     + + +&Yo-- ;;CKK . ---r/   )r   r!   ),rL   RuntimeErrorrK   startingr   collectionsOrderedDictru   r!   r4   r   r   r=   rk   r]   rangestarting_roundrM   rN   r   r   r5   endingsetkeysr   ro   rJ   narrow_requirement_selectionr2   r   rq   rs   rY   minr   r   r   resolving_conflictsr   r   r{   ending_roundr   )rP   rh   r   r   rV   optimistic_rounds_cutoff"optimistic_backjumping_start_roundround_indexunsatisfied_namesnarrowed_unstatisfied_namesr|   failure_criterionr   r   failed_optimistic_backjumpingnewly_unsatisfied_namesr   s   `               @r-   resolvezResolution.resolve  s7   < 	31222 #/11!#  
  	K 	KAK%%dj&91T%JJJJ) K K K*1;+BCCJK 	 04 9=* ,, o	F o	FKG"""555 1 !d6G6S5=9D6/2#k1T5WW0 0, 0144--///  5 .9#&HH34 4 --/// ! ! ! !&*j&9&?&?&A&A! ! ! % "TZ000z!!! "$*"5":":"<"<==DU@V@VVO$%%)).2G88$5$(J$6#2 J/$/==$ $ %4 J/$/>>% % *.)D 9  / /++  /@+ / T"#RSSS .//!336D<PQQQ215 $ > >t D D  )'--.?@@ ++6+:::"nnV44G 59# . >. -5 511 ,   9 d>O 8<55 65 1 PT5F P))++++5;DJ/2 # P24:3NOOOP
+ + + + +*.**=*C*C*E*E+ + +' 66J')@   $$&&&G  {$* EEEE
+++s*    "B
B,B''B,!MM43M4N)rC   rD   rE   rF   r#   rG   )r#   r"   )r#   rG   )r4   r^   r_   r	   r`   ra   r#   rG   )r4   r^   rv   rw   r#   rG   )r|   r   r#   r   )r|   r   r=   r   r#   r   )r   r   r#   r^   )r|   r   r#   r   )r   r   r#   r   )r   r   r#   r   )r   r   r#   r   )rh   r   r   r   r#   r"   )__name__
__module____qualname____doc__rQ   propertyr!   r]   ru   r{   r   r   r   r   r   r   r   r   r   r   r'   r/   r-   rB   rB   D   sh        8 8 8 8 1 1 1 X1# # # #*) *) *) *)X   6
 
 
 


 

 

 

   # # # #J! ! ! !F
 
 
 
% % % %d d d dLR R R RN, N, N, N, N, N,r/   rB   c                  "    e Zd ZdZeZ	 ddd	Zd
S )Resolverz3The thing that performs the actual resolution work.d   rh   r   r   r   r#   r$   c                    t          | 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   )rB   rC   rE   r   r@   )rP   rh   r   
resolutionr!   s        r-   r   zResolver.resolve3  s>    @  t}==
""<J"GGU###r/   N)r   )rh   r   r   r   r#   r$   )r   r   r   r   r   base_exceptionr   r'   r/   r-   r   r   .  s=        ==&N
 "$ "$ "$ "$ "$ "$ "$r/   r   r4   Mapping[KT, Criterion[RT, CT]]r<   	KT | Noner;   dict[int, KT | None]r1   set[KT | None]r   c                :   ||v rdS || vrdS |J | |                                          D ]o}	 |t          |                   }n# t          $ r Y %w xY w||v r|                    |            dS t	          | |||          r|                    |            dS pdS )NTF)r8   r(   r9   r6   r7   )r4   r<   r;   r1   r>   r?   s         r-   r7   r7   X  s     it
(u???c]&&(( 
 
	BqEE?DD 	 	 	H	9MM#44hh	BB 	MM#44	 5s   A
AA)r!   r"   r#   r$   )
r4   r   r<   r   r;   r   r1   r   r#   r   ),
__future__r   r   r   rq   typingr   r   structsr   r   r	   r
   r   r   r   r   r   abstractr   r   r=   r   
exceptionsr   r   r   r   r   collections.abcr   r   r   	providersr   r   	reportersr   r    __annotations__r@   rB   r   r7   r'   r/   r-   <module>r      s>   " " " " " " "          ) ) ) ) ) ) ) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 / . . . . . . .                           )==========88888888(((((('*  * * * *   <g, g, g, g, g,R$ g, g, g,T'$ '$ '$ '$ '$B
+ '$ '$ '$T     r/   