U
    cUh&                     @   s   d dl Z d dlZd dlmZ d dlmZ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rd d	lmZ d d
lmZ eeef Zeeeef ZneZedZedZe	eef eeeeef dddZG dd deZ dS )    N)	lru_cache)TYPE_CHECKINGDictIterableIteratorMappingSequenceTypeVarUnion)AbstractProvider   )	Candidate
ConstraintRequirement)REQUIRES_PYTHON_IDENTIFIER)Factory)
Preference)RequirementInformationDV)mapping
identifierdefaultreturnc                 C   s8   || kr| | S | d\}}}|r4|| kr4| | S |S )ai  Get item from a package name lookup mapping with a resolver identifier.

    This extra logic is needed when the target mapping is keyed by package
    name, which cannot be directly looked up with an identifier (which may
    contain requested extras). Additional logic is added to also look up a value
    by "cleaning up" the extras from the identifier.
    [)	partition)r   r   r   nameZopen_bracket_ r   l/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/provider.py_get_with_identifier6   s    r    c                   @   s  e Zd ZdZeeeef eeeee	f ddddZ
eeef edddZeeeef eeee f eeed	 f ed	 d
dddZeeeee f eeee f ee dddZeddeeedddZeee dddZeeed	 ed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.
    N)factoryconstraintsignore_dependenciesupgrade_strategyuser_requestedr   c                 C   s2   || _ || _|| _|| _|| _tdd | _d S )Nc                   S   s   t jS N)mathinfr   r   r   r   <lambda>g       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__Z   s    zPipProvider.__init__)requirement_or_candidater   c                 C   s   |j S r'   )r   )r4   r6   r   r   r   identifyi   s    zPipProvider.identifyPreferenceInformationr   )r   resolutions
candidatesinformationbacktrack_causesr   c                    sJ  zt t||  W n tk
r,   d}Y nX d}|rVdd || D }t| \}}	nd\}}	dd dd |	D D }
|d	k	}td
d |
D }t|
}z j| }W nR tk
r   tj	}|r fdd|| D }t
dd |D d }ntj	}Y nX d}| j|<  j|tj	}|t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 following 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. If the depth cannot
          by determined (eg: due to no matching parents), it is considered
          infinite.
        * 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).
        FTc                 s   s   | ]\}}|  V  qd S r'   )Zget_candidate_lookup).0rr   r   r   r   	<genexpr>   s     z-PipProvider.get_preference.<locals>.<genexpr>)Nr   c                 S   s   g | ]}|D ]
}|j qqS r   )operator)r=   Zspecifier_set	specifierr   r   r   
<listcomp>   s    z.PipProvider.get_preference.<locals>.<listcomp>c                 s   s   | ]}|r|j V  qd S r'   )rA   )r=   ireqr   r   r   r?      s      Nc                 s   s   | ]}|d d dkV  qd S )N   z==r   )r=   opr   r   r   r?      s     c                 3   s*   | ]"\}}|d k	r j |j ndV  qd S )Ng        )r3   r   )r=   r   parentr4   r   r   r?      s   c                 s   s   | ]
}|V  qd S r'   r   )r=   dr   r   r   r?      s     g      ?)nextiterStopIterationzipanyboolr0   KeyErrorr(   r)   minr3   getr   is_backtrack_cause)r4   r   r9   r:   r;   r<   Zhas_informationZlookups	candidateZireqs	operatorsdirectZpinnedZunfreeZrequested_orderZparent_depthsZinferred_depthrequires_pythonbacktrack_causer   rG   r   get_preferencel   sN    


zPipProvider.get_preference)r   requirementsincompatibilitiesr   c                    sH   t td fdd}t j|t d} jj||||| | jdS )N)r   r   c                    s4    j dkrdS  j dkr0t j| dd}|dk	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-neededNr   F)r/   r    r0   )r   Z
user_orderrG   r   r   _eligible_for_upgrade   s    

z7PipProvider.find_matches.<locals>._eligible_for_upgrader\   )r   rY   
constraintZprefers_installedrZ   is_satisfied_by)	strrN   r    r-   r   emptyr,   Zfind_candidatesr_   )r4   r   rY   rZ   r]   r^   r   rG   r   find_matches   s    zPipProvider.find_matches)maxsize)requirementrS   r   c                 C   s
   | |S r'   )r_   )r4   rd   rS   r   r   r   r_      s    zPipProvider.is_satisfied_by)rS   r   c                 C   s   | j  }dd ||D S )Nc                 S   s   g | ]}|d k	r|qS r'   r   )r=   r>   r   r   r   rB      s      z0PipProvider.get_dependencies.<locals>.<listcomp>)r.   iter_dependencies)r4   rS   Zwith_requiresr   r   r   get_dependencies   s    zPipProvider.get_dependencies)r   r<   r   c                 C   s8   |D ].}| |j jkr dS |jr| |jjkr dS qdS )NTF)rd   r   rF   )r   r<   rW   r   r   r   rR      s    zPipProvider.is_backtrack_cause)__name__
__module____qualname____doc__r   r   r`   r   rN   intr5   r
   r   r   r7   r   r   r   r   rX   rb   r   r_   rf   staticmethodrR   r   r   r   r   r!   O   s:   


]* r!   )!r1   r(   	functoolsr   typingr   r   r   r   r   r   r	   r
   Z pip._vendor.resolvelib.providersr   baser   r   r   r:   r   r"   r   r    pip._vendor.resolvelib.resolversr   r8   r`   Z_ProviderBaser   r   r    r!   r   r   r   r   <module>   s*   (

