o
    g}”eõ#  ã                   @   s¼   d dl Z d dlZd dlmZmZmZmZmZmZm	Z	 d dl
mZ ddlmZmZmZ ddlmZ ddlmZ erRd dl
mZ d d	lmZ eeef Zeeeef ZneZG d
d„ deƒZdS )é    N)ÚTYPE_CHECKINGÚDictÚIterableÚIteratorÚMappingÚSequenceÚUnion)ÚAbstractProvideré   )Ú	CandidateÚ
ConstraintÚRequirement)ÚREQUIRES_PYTHON_IDENTIFIER)ÚFactory)Ú
Preference)ÚRequirementInformationc                   @   s4  e Zd ZdZdedeeef dededeee	f ddfd	d
„Z
deeef defdd„Zdedeeef deeee f deeed f ded ddfdd„Zdedefdd„Zdedeeee f deeee f dee fdd„Zdededefdd „Zdedee fd!d"„Zededed defd#d$„ƒZdS )%ÚPipProvidera´  Pip's provider implementation for resolvelib.

    :params constraints: A mapping of constraints specified by the user. Keys
        are canonicalized project names.
    :params ignore_dependencies: Whether the user specified ``--no-deps``.
    :params upgrade_strategy: The user-specified upgrade strategy.
    :params user_requested: A set of canonicalized package names that the user
        supplied for pip to install/upgrade.
    ÚfactoryÚconstraintsÚignore_dependenciesÚupgrade_strategyÚuser_requestedÚreturnNc                 C   s2   || _ || _|| _|| _|| _t dd„ ¡| _d S )Nc                   S   s   t jS ©N)ÚmathÚinf© r   r   úu/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/provider.pyÚ<lambda>@   s    z&PipProvider.__init__.<locals>.<lambda>)Ú_factoryÚ_constraintsÚ_ignore_dependenciesÚ_upgrade_strategyÚ_user_requestedÚcollectionsÚdefaultdictÚ_known_depths)Úselfr   r   r   r   r   r   r   r   Ú__init__3   s   zPipProvider.__init__Úrequirement_or_candidatec                 C   s   |j S r   ©Úname)r'   r)   r   r   r   ÚidentifyB   s   zPipProvider.identifyÚ
identifierÚresolutionsÚ
candidatesÚinformationÚPreferenceInformationÚbacktrack_causesr   c              	      s  dd„ || D ƒ}t |Ž \}}dd„ dd„ |D ƒD ƒ}	|du}
tdd„ |	D ƒƒ}t|	ƒ}zˆ j| }W n" tyU   tj}‡ fdd„|| D ƒ}td	d„ |D ƒƒd
 }Y nw d
}|ˆ j|< ˆ j 	|tj¡}|t
k}|dk}ˆ  ||¡}| ||
 | | ||| |f	S )a[  Produce a sort key for given requirement based on preference.

        The lower the return value is, the more preferred this group of
        arguments is.

        Currently pip considers the followings in order:

        * Prefer if any of the known requirements is "direct", e.g. points to an
          explicit URL.
        * If equal, prefer if any requirement is "pinned", i.e. contains
          operator ``===`` or ``==``.
        * If equal, calculate an approximate "depth" and resolve requirements
          closer to the user-specified requirements first.
        * Order user-specified requirements by the order they are specified.
        * If equal, prefers "non-free" requirements, i.e. contains at least one
          operator, such as ``>=`` or ``<``.
        * If equal, order alphabetically for consistency (helps debuggability).
        c                 s   s   � | ]	\}}|  ¡ V  qd S r   )Zget_candidate_lookup)Ú.0ÚrÚ_r   r   r   Ú	<genexpr>_   s   € z-PipProvider.get_preference.<locals>.<genexpr>c                 S   s   g | ]
}|D ]}|j ‘qqS r   )Úoperator)r3   Zspecifier_setÚ	specifierr   r   r   Ú
<listcomp>a   s    ýþÿz.PipProvider.get_preference.<locals>.<listcomp>c                 s   s   � | ]}|r|j V  qd S r   )r8   )r3   Úireqr   r   r   r6   c   s   € Nc                 s   s    � | ]}|d d… dkV  qd S )Né   z==r   )r3   Úopr   r   r   r6   h   s   € c                 3   s,   � | ]\}}|d urˆ j |j ndV  qd S )Ng        )r&   r+   )r3   r5   Úparent©r'   r   r   r6   o   s
   € ÿ
ÿc                 s   s   � | ]}|V  qd S r   r   )r3   Údr   r   r   r6   s   s   € g      ð?Ú
setuptools)ÚzipÚanyÚboolr#   ÚKeyErrorr   r   Úminr&   Úgetr   Úis_backtrack_cause)r'   r-   r.   r/   r0   r2   ZlookupsÚ	candidateZireqsÚ	operatorsÚdirectZpinnedZunfreeZrequested_orderZparent_depthsZinferred_depthÚrequires_pythonZ
delay_thisÚbacktrack_causer   r>   r   Úget_preferenceE   sB   þ
þú

÷zPipProvider.get_preferencec                 C   sD   || j v r
| j | S | d¡\}}}|r|| j v r| j | S t ¡ S )Nú[)r    Ú	partitionr   Úempty)r'   r-   r+   Zopen_bracketr5   r   r   r   Ú_get_constraint™   s   


zPipProvider._get_constraintÚrequirementsÚincompatibilitiesc                    s8   dt dtf‡ fdd„}ˆ jj||ˆ  |¡||ƒ |d�S )Nr+   r   c                    s&   ˆ j dkrdS ˆ j dkr| ˆ jv S dS )aÔ  Are upgrades allowed for this project?

            This checks the upgrade strategy, and whether the project was one
            that the user specified in the command line, in order to decide
            whether we should upgrade if there's a newer version available.

            (Note that we don't need access to the `--upgrade` flag, because
            an upgrade strategy of "to-satisfy-only" means that `--upgrade`
            was not specified).
            ÚeagerTzonly-if-neededF)r"   r#   r*   r>   r   r   Ú_eligible_for_upgrade®   s
   


z7PipProvider.find_matches.<locals>._eligible_for_upgrade)r-   rR   Ú
constraintZprefers_installedrS   )ÚstrrC   r   Zfind_candidatesrQ   )r'   r-   rR   rS   rU   r   r>   r   Úfind_matches¨   s   ûzPipProvider.find_matchesÚrequirementrH   c                 C   s
   |  |¡S r   )Úis_satisfied_by)r'   rY   rH   r   r   r   rZ   Ç   s   
zPipProvider.is_satisfied_byc                 C   s   | j  }dd„ | |¡D ƒS )Nc                 S   s   g | ]}|d ur|‘qS r   r   )r3   r4   r   r   r   r9   Ì   s    z0PipProvider.get_dependencies.<locals>.<listcomp>)r!   Úiter_dependencies)r'   rH   Zwith_requiresr   r   r   Úget_dependenciesÊ   s   zPipProvider.get_dependenciesc                 C   s8   |D ]}| |j jkr dS |jr| |jjkr dS qdS )NTF)rY   r+   r=   )r-   r2   rL   r   r   r   rG   Î   s   €zPipProvider.is_backtrack_cause)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   rW   r   rC   Úintr(   r   r   r   r,   r   r   r   r   rM   rQ   rX   rZ   r\   ÚstaticmethodrG   r   r   r   r   r   (   sb    
þ
ýüû
ú
ùþ
ýüûú
ùTþýü
ûÿÿþr   )r$   r   Útypingr   r   r   r   r   r   r   Z pip._vendor.resolvelib.providersr	   Úbaser   r   r   r/   r   r   r   r   Ú pip._vendor.resolvelib.resolversr   r1   rW   Z_ProviderBaser   r   r   r   r   Ú<module>   s    $