a
    <Bìj”^  ã                   @  s8  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dœdd„Z(G dd„ deee	e
f ƒZ)G dd„ deee	e
f ƒZ*ddddddœ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[RT, CT, KT]úResult[RT, CT, KT])ÚstateÚreturnc              
     sè   | j }dd„ | ¡ D ƒ}d |td ƒ< tƒ }| d ¡ d h‰ | j ¡ D ]€\}}t| j||ˆ ƒs^qD||vrp| |¡ | ¡ D ]J}z|t|ƒ }W n ty¢   Y qxY n0 ||vr¶| |¡ | 	||¡ qxqDt
‡ fdd„| ¡ D ƒ|| jd�S )Nc                 S  s   i | ]\}}t |ƒ|“qS © )Úid©Ú.0ÚkÚvr$   r$   új/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers/resolution.pyÚ
<dictcomp>(   ó    z!_build_result.<locals>.<dictcomp>c                   s   i | ]\}}|ˆ v r||“qS r$   r$   r&   ©Ú	connectedr$   r*   r+   >   r,   )ÚmappingÚgraphÚcriteria)r/   Úitemsr%   r	   Úaddr1   Ú_has_route_to_rootÚiter_parentÚKeyErrorÚconnectr   )r"   r/   Úall_keysr0   ÚkeyÚ	criterionÚpÚpkeyr$   r-   r*   Ú_build_result&   s0    



ýr=   c                   @  s  e Zd ZdZddddœdd„Zedd	œd
d„ƒZdd	œdd„Zdddddœdd„Zddddœdd„Z	dddœdd„Z
ddddœd d!„Zd"dd#œd$d%„Zdd&dœd'd(„Zd)dd*œd+d,„Zdd	œd-d.„Zdd	œd/d0„Zd1dd2œd3d4„Zd&d1d5œd6d7„Zd8d9dd:œd;d<„Zd=S )>Ú
Resolutionz­Stateful resolution object.

    This is designed as a one-off object that holds information to kick start
    the resolution process, and holds the results afterwards.
    zAbstractProvider[RT, CT, KT]zBaseReporter[RT, CT, KT]ÚNone)ÚproviderÚreporterr#   c                 C  s(   || _ || _g | _t| _d | _d | _d S ©N)Ú_pÚ_rÚ_statesr   Ú_optimistic_backjumping_ratioÚ_save_statesZ_optimistic_start_round)Úselfr@   rA   r$   r$   r*   Ú__init__K   s    zResolution.__init__r    )r#   c              
   C  s@   z| j d W S  ty: } ztdƒ|‚W Y d }~n
d }~0 0 d S )Néÿÿÿÿr"   )rE   Ú
IndexErrorÚAttributeError)rH   Úer$   r$   r*   r"   Y   s    zResolution.statec                 C  s>   | j d }t|j ¡ |j ¡ |jdd… d�}| j  |¡ dS )z‰Push a new state into history.

        This new state will be used to hold resolution results of the next
        coming round.
        rJ   N©r/   r1   Úbacktrack_causes)rE   r   r/   Úcopyr1   rO   Úappend)rH   Úbaser"   r$   r$   r*   Ú_push_new_state`   s    
ýzResolution._push_new_statezdict[KT, Criterion[RT, CT]]r   z	CT | None)r1   ÚrequirementÚparentr#   c           	      C  sÌ   | j j||d� | jj|d�}| |¡}|r8t|jƒ}ng }| jj|t|t	 
d¡||giƒt|t	 d¡||iƒd�}|r”t|jƒ}| t||ƒ¡ nt||ƒg}tt|ƒ||d�}|jsÀt|ƒ‚|||< d S )N)rT   rU   )Zrequirement_or_candidateÚiter_requirementÚincompatibilities©Ú
identifierÚrequirementsrW   ©Ú
candidatesÚinformationrW   )rD   Zadding_requirementrC   ÚidentifyÚgetÚlistrW   Úfind_matchesr   ÚoperatorÚmethodcallerÚ
attrgetterr]   rQ   r   r   r   r\   r   )	rH   r1   rT   rU   rY   r:   rW   Úmatchesr]   r$   r$   r*   Ú_add_to_criterian   s>    
ýýù
ýzResolution._add_to_criteriazCollection[KT])r1   Úparentsr#   c                   sD   ˆ sdS |  ¡ D ].\}}t|j‡ ‡fdd„|jD ƒ|jƒ||< qd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                   s,   g | ]$}|j d u s$ˆj |j ¡ˆ vr|‘qS rB   )rU   rC   r^   )r'   r]   ©rg   rH   r$   r*   Ú
<listcomp>ª   s   
üz@Resolution._remove_information_from_criteria.<locals>.<listcomp>)r2   r   r\   r]   rW   )rH   r1   rg   r9   r:   r$   rh   r*   Ú!_remove_information_from_criteriaš   s    þöz,Resolution._remove_information_from_criteriar   r   )Únamer#   c              	   C  s>   | j j|| jjt| jjt d¡ƒt| jjt d¡ƒ| jjd�S )Nr\   r]   )rY   Úresolutionsr\   r]   rO   )	rC   Zget_preferencer"   r/   r   r1   rb   rd   rO   )rH   rk   r$   r$   r*   Ú_get_preferenceµ   s    þþõzResolution._get_preferencezCriterion[RT, CT]Úbool)rk   r:   r#   c                   sB   zˆj j| ‰ W n ty$   Y dS 0 t‡ ‡fdd„| ¡ D ƒƒS )NFc                 3  s   | ]}ˆj j|ˆ d �V  qdS ©)rT   Ú	candidateN©rC   Zis_satisfied_by©r'   Úr©Zcurrent_pinrH   r$   r*   Ú	<genexpr>Ë   s   ÿz8Resolution._is_current_pin_satisfying.<locals>.<genexpr>)r"   r/   r6   ÚallrV   )rH   rk   r:   r$   rt   r*   Ú_is_current_pin_satisfyingÄ   s    þz%Resolution._is_current_pin_satisfyingr   )rp   r#   c                 C  s4   | j j ¡ }| jj|d�D ]}| j|||d� q|S )N©rp   ©rU   )r"   r1   rP   rC   Úget_dependenciesrf   )rH   rp   r1   rT   r$   r$   r*   Ú_get_updated_criteriaÐ   s    z Resolution._get_updated_criteriazlist[Criterion[RT, CT]]c                   sä   ˆj j| }g }|jD ]È‰ zˆ ˆ ¡}W nL tyt } z4ˆj |jˆ ¡ | |j¡ W Y d }~qW Y d }~n
d }~0 0 t	‡ ‡fdd„| 
¡ D ƒƒ}|s tˆ |ƒ‚ˆjjˆ d� ˆj j |¡ ˆj j |d ¡ ˆ ˆj j|< g   S |S )Nc                 3  s   | ]}ˆj j|ˆ d �V  qdS ro   rq   rr   ©rp   rH   r$   r*   ru   æ   s   ÿz7Resolution._attempt_to_pin_criterion.<locals>.<genexpr>rx   )r"   r1   r\   r{   r   rD   Zrejecting_candidater:   rQ   rv   rV   r   ZpinningÚupdater/   Úpop)rH   rk   r:   Úcausesr1   rM   Z	satisfiedr$   r|   r*   Ú_attempt_to_pin_criterionÖ   s(    
"þ
z$Resolution._attempt_to_pin_criterionzlist[tuple[KT, list[CT]]])Úincompatibilities_from_brokenr#   c              	   C  s²   |D ]¨\}}|sqz| j j| }W n ty8   Y qY n0 | jj|t| j jt d¡ƒt| j jt d¡||iƒd�}t	|ƒ}|s„ dS | 
|j¡ t|t|jƒ|d�| j j|< qdS )NrV   rW   rX   Fr[   T)r"   r1   r6   rC   ra   r   rb   rc   rd   r   ÚextendrW   r   r`   r]   )rH   r�   r(   rW   r:   re   r\   r$   r$   r*   Ú_patch_criteriaû   s:    
þýúýzResolution._patch_criteriac                 C  s    | j du rdd„ | jD ƒ| _ dS )zCSave states for potential rollback if optimistic backjumping fails.Nc                 S  s0   g | ](}t |j ¡ |j ¡ |jd d … d�‘qS )NrN   )r   r/   rP   r1   rO   )r'   Úsr$   r$   r*   ri   !  s   ûýz*Resolution._save_state.<locals>.<listcomp>)rG   rE   ©rH   r$   r$   r*   Ú_save_state  s    
úzResolution._save_statec                 C  s   d| _ | jr| j| _d| _dS )z3Rollback states and disable optimistic backjumping.g        N)rF   rG   rE   r…   r$   r$   r*   Ú_rollback_states*  s    zResolution._rollback_statesz$list[RequirementInformation[RT, CT]])r   r#   c           
   	     sN  t  dd„ |D ƒdd„ |D ƒ¡}‡ fdd„|D ƒ}tˆ jƒdk�rJˆ jd= ˆ j}zˆ j ¡ }|j ¡ \}}W n  tt	fyŒ   t
|ƒd‚Y n0 ˆ js ||vr �q
ˆ jrÀˆ jdu rÀ||vrÀˆ  ¡  ‡ fd	d„ˆ j |¡D ƒ}| |¡sè�q
|jsò�q
tˆ jƒd
krPt
|ƒ‚qPdd„ |j ¡ D ƒ}| ||gf¡ ˆ  ¡  ˆ  |¡}	|	r2dS q2d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                 s  s   | ]}|j d ur|j V  qd S rB   ry   ©r'   Úcr$   r$   r*   ru   Q  r,   z'Resolution._backjump.<locals>.<genexpr>c                 s  s   | ]}|j V  qd S rB   )rT   rˆ   r$   r$   r*   ru   R  r,   c                   s   h | ]}ˆ j  |¡’qS r$   ©rC   r^   rr   r…   r$   r*   Ú	<setcomp>T  r,   z'Resolution._backjump.<locals>.<setcomp>é   rJ   Nc                   s   h | ]}ˆ j  |¡’qS r$   rŠ   )r'   Údr…   r$   r*   r‹   w  s   r   c                 S  s   g | ]\}}|t |jƒf‘qS r$   )r`   rW   r&   r$   r$   r*   ri   ˆ  s   z(Resolution._backjump.<locals>.<listcomp>TF)Ú	itertoolsÚchainÚlenrE   r"   r~   r/   ÚpopitemrK   r6   r   rF   rG   r†   rC   rz   Ú
isdisjointr1   r2   rQ   rS   rƒ   )
rH   r   Zincompatible_reqsZincompatible_depsZbroken_staterk   rp   Zcurrent_dependenciesr�   Úsuccessr$   r…   r*   Ú	_backjump1  sV    þ
ÿþÿþý

ÿ

ÿ
zResolution._backjump)Úcriteronr#   c                 C  s   t dd„ |D ƒ ¡ ƒS )z5Extract causes from list of criterion and deduplicatec                 S  s"   i | ]}|j D ]}t|ƒ|“qqS r$   )r]   r%   )r'   r‰   Úir$   r$   r*   r+      r,   z.Resolution._extract_causes.<locals>.<dictcomp>)r`   Úvalues)rH   r•   r$   r$   r*   Ú_extract_causesœ  s    zResolution._extract_causesúIterable[RT]Úint©rZ   Ú
max_roundsr#   c                   s  ˆj rtdƒ‚ˆj ¡  tt ¡ i g d�gˆ_ |D ]P}zˆjˆjj	|d d� W q2 t
y€ } zt|jjƒ|‚W Y d }~q2d }~0 0 q2ˆ ¡  d }d }t|ƒD �]V}ˆjj|d� ˆj�rˆjd u�r|d u rö|}t|| ˆj ƒ}|dkrôˆ ¡  qœn"|d u�r|| |k�rˆ ¡  qœ‡fdd„ˆjj	 ¡ D ƒ}|�sRˆjjˆjd� ˆj  S tˆjj	 ¡ ƒt|ƒ ‰ t|ƒd	k�r¼tˆjj|ˆjjtˆjj	t  d
¡ƒtˆjj	t  d¡ƒˆjj!d�ƒ}	n|}	|	�sÎtdƒ‚t|	ƒd	k�rìt"|	ˆj#d�}
n|	d }
ˆ $|
¡}|�r®ˆ %|¡}ˆjj&|d� zˆ '|¡}W n, t�yV   ˆj�rPˆj�rPd}n‚ Y n0 t(| �onˆj�onˆjƒ}|�rŠˆj�rŠˆ ¡  n"|ˆjj!d d …< |�sâtˆjj!ƒ‚n4‡ ‡fdd„ˆjj	 ¡ D ƒ}ˆ )ˆjj	|¡ ˆ ¡  ˆjj*|ˆjd� qœt+|ƒ‚d S )Nzalready resolvedrN   ry   )Úindexr   c                   s    g | ]\}}ˆ   ||¡s|‘qS r$   ©rw   ©r'   r9   r:   r…   r$   r*   ri   Õ  s   þz&Resolution.resolve.<locals>.<listcomp>)r"   r   r\   r]   )Zidentifiersrl   r\   r]   rO   z-narrow_requirement_selection returned 0 names)r9   )r   Tc                   s(   h | ] \}}|ˆ v rˆ  ||¡s|’qS r$   rž   rŸ   ©Zsatisfied_namesrH   r$   r*   r‹   "  s   ýz%Resolution.resolve.<locals>.<setcomp>)r�   r"   ),rE   ÚRuntimeErrorrD   Zstartingr   ÚcollectionsÚOrderedDictrf   r"   r1   r   r   r:   r]   rS   ÚrangeZstarting_roundrF   rG   rš   r‡   r2   ZendingÚsetÚkeysr�   r`   rC   Znarrow_requirement_selectionr/   r   rb   rd   rO   Úminrm   r€   r˜   Zresolving_conflictsr”   rn   rj   Zending_roundr   )rH   rZ   rœ   rs   rM   Zoptimistic_rounds_cutoffZ"optimistic_backjumping_start_roundZround_indexZunsatisfied_namesZnarrowed_unstatisfied_namesrk   Zfailure_criterionr   r“   Zfailed_optimistic_backjumpingZnewly_unsatisfied_namesr$   r    r*   Úresolve¢  s¼    
ýÿ&ÿ
ÿÿ

þ
þþõÿ

ÿý

þÿzResolution.resolveN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rI   Úpropertyr"   rS   rf   rj   rm   rw   r{   r€   rƒ   r†   r‡   r”   r˜   r¨   r$   r$   r$   r*   r>   D   s"   ,%#kr>   c                   @  s(   e Zd ZdZeZd
ddddœdd„Zd	S )ÚResolverz3The thing that performs the actual resolution work.éd   r™   rš   r!   r›   c                 C  s$   t | j| jƒ}|j||d�}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œ   )r>   r@   rA   r¨   r=   )rH   rZ   rœ   Ú
resolutionr"   r$   r$   r*   r¨   8  s     zResolver.resolveN)r¯   )r©   rª   r«   r¬   r   Zbase_exceptionr¨   r$   r$   r$   r*   r®   3  s    ýr®   zMapping[KT, Criterion[RT, CT]]z	KT | Nonezdict[int, KT | None]zset[KT | None]rn   )r1   r9   r8   r.   r#   c              	   C  s˜   ||v rdS || vrdS |d us$J ‚| |   ¡ D ]b}z|t|ƒ }W n tyZ   Y q0Y n0 ||v rt| |¡  dS t| |||ƒr0| |¡  dS q0dS )NTF)r5   r%   r6   r3   r4   )r1   r9   r8   r.   r;   r<   r$   r$   r*   r4   ]  s"    


r4   ),Ú
__future__r   r¢   rŽ   rb   Útypingr   r   Ústructsr   r   r   r	   r
   r   r   r   r   Zabstractr   r   r:   r   Ú
exceptionsr   r   r   r   r   Úcollections.abcr   r   r   Z	providersr   r   Z	reportersr   r   Ú__annotations__r=   r>   r®   r4   r$   r$   r$   r*   Ú<module>   s(   ,   r*