a
    e0h                     @   s   d dl mZ d dlmZ ddlmZ erld dl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 G dd	 d	eZd
S )    )AbstractProvider)MYPY_CHECK_RUNNING   )
Constraint)AnyDictIterableOptionalSequenceSetTupleUnion)	CandidateRequirement)Factoryc                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Z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.
    c                 C   s"   || _ || _|| _|| _|| _d S N)_factory_constraints_ignore_dependencies_upgrade_strategy_user_requested)selffactoryconstraintsignore_dependenciesupgrade_strategyuser_requested r   Z/var/www/auris/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/provider.py__init__+   s
    	zPipProvider.__init__c                 C   s   |j S r   name)r   
dependencyr   r   r   identify:   s    zPipProvider.identifyc           	      C   sV   dd }|dd |D }t dd |D }|r>tt|jnd}|dk}||||fS )az  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 points to an explicit URL.
        * If equal, prefer if any requirements contain ``===`` and ``==``.
        * If equal, prefer if requirements include version constraints, e.g.
          ``>=`` and ``<``.
        * If equal, prefer user-specified (non-transitive) requirements.
        * If equal, order alphabetically for consistency (helps debuggability).
        c                 S   sn   dd | D }t | \}}tdd |D r0dS dd |D }dd |D }tdd |D rbd	S |rjd
S dS )a  Rate how restrictive a set of requirements are.

            ``Requirement.get_candidate_lookup()`` returns a 2-tuple for
            lookup. The first element is ``Optional[Candidate]`` and the
            second ``Optional[InstallRequirement]``.

            * If the requirement is an explicit one, the explicitly-required
              candidate is returned as the first element.
            * If the requirement is based on a PEP 508 specifier, the backing
              ``InstallRequirement`` is returned as the second element.

            We use the first element to check whether there is an explicit
            requirement, and the second for equality operator.
            c                 s   s   | ]}|  V  qd S r   )get_candidate_lookup.0rr   r   r   	<genexpr>d       zNPipProvider.get_preference.<locals>._get_restrictive_rating.<locals>.<genexpr>c                 s   s   | ]}|d uV  qd S r   r   )r'   candr   r   r   r)   f   r*   r   c                 s   s   | ]}|r|j V  qd S r   )	specifier)r'   ireqr   r   r   r)   h   r*   c                 S   s   g | ]}|D ]
}|j qqS r   )operator)r'   spec_setr,   r   r   r   
<listcomp>i   s   zOPipProvider.get_preference.<locals>._get_restrictive_rating.<locals>.<listcomp>c                 s   s   | ]}|d v V  qdS ))z==z===Nr   )r'   opr   r   r   r)   n   r*   r         )zipany)requirementslookupscandsireqs	spec_sets	operatorsr   r   r   _get_restrictive_ratingT   s    z;PipProvider.get_preference.<locals>._get_restrictive_ratingc                 s   s   | ]\}}|V  qd S r   r   )r'   req_r   r   r   r)   u   r*   z-PipProvider.get_preference.<locals>.<genexpr>c                 s   s   | ]\}}|d uV  qd S r   r   )r'   r>   parentr   r   r   r)   v   r*    
setuptools)allnextiterr"   )	r   
resolution
candidatesinformationr<   restrictive
transitivekey
delay_thisr   r   r   get_preference>   s    !
zPipProvider.get_preferencec                    sD   |sg S |d j } fdd} jj| j|t || dS )Nr   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)
constraintprefers_installed)project_namer   find_candidatesr   getr   empty)r   r6   r"   rO   r   rN   r   find_matches   s    
zPipProvider.find_matchesc                 C   s
   | |S r   )is_satisfied_by)r   requirement	candidater   r   r   rW      s    zPipProvider.is_satisfied_byc                 C   s   | j  }dd ||D S )Nc                 S   s   g | ]}|d ur|qS r   r   r&   r   r   r   r0      s   z0PipProvider.get_dependencies.<locals>.<listcomp>)r   iter_dependencies)r   rY   with_requiresr   r   r   get_dependencies   s    zPipProvider.get_dependenciesN)
__name__
__module____qualname____doc__r    r$   rL   rV   rW   r\   r   r   r   r   r       s   
Gr   N) pip._vendor.resolvelib.providersr   pip._internal.utils.typingr   baser   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   (