B
    `dE;                 @   s  d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d
dlmZmZ erd dlmZmZmZmZmZmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d
dlm%Z% d
dl&m'Z' ed Z(e )e*Z+dd Z,dd Z-dd Z.G dd deZ/G dd de/Z0G dd de/Z1G d d! d!eZ2G d"d# d#eZ3G d$d% d%eZ4dS )&    N)InvalidSpecifierSpecifierSet)canonicalize_name)Version)install_req_from_editableinstall_req_from_line)InstallRequirement)normalize_version_info)get_requires_python)MYPY_CHECK_RUNNING   )	Candidateformat_name)AnyOptionalSequenceSetTupleUnion)_BaseVersion)Distribution)AbstractDistribution)Link)Requirement)Factory)AlreadyInstalledCandidateEditableCandidateLinkCandidatec             C   s<   |j rtdt| j|j|j|j|jt|j	|j
|jddS )Nzparent is editable)install_optionsglobal_optionshashes)
comes_from
use_pep517isolated
constraintoptions)editableAssertionErrorr   urlr!   r"   r#   r$   dictr   r   hash_options)linkparent r-   R/tmp/pip-unpacked-wheel-hu9qqap1/pip/_internal/resolution/resolvelib/candidates.pymake_install_req_from_link)   s    r/   c             C   s<   |j stdt| j|j|j|j|jt|j	|j
|jddS )Nzparent not editable)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.   make_install_req_from_editable:   s    r0   c             C   sF   t dt| j| j|j|j|j|jt	|j
|j|jdd}| |_|S )Nz{}=={})r   r   r    )r!   r"   r#   r$   r%   )r   formatr   project_nameparsed_versionr!   r"   r#   r$   r)   r   r   r*   satisfied_by)distr,   ireqr-   r-   r.   make_install_req_from_distK   s    r7   c               @   sz   e Zd ZdddZdd Zdd Zdd	 Zed
d Zedd Z	dd Z
dd Zedd Zdd Zdd Zdd ZdS )"_InstallRequirementBackedCandidateNc             C   s(   || _ || _|| _|| _|| _d | _d S )N)r+   _factory_ireq_name_version_dist)selfr+   r6   factorynameversionr-   r-   r.   __init__a   s    	z+_InstallRequirementBackedCandidate.__init__c             C   s   dj | jjt| jdS )Nz{class_name}({link!r}))
class_namer+   )r1   	__class____name__strr+   )r>   r-   r-   r.   __repr__q   s    z+_InstallRequirementBackedCandidate.__repr__c             C   s   t || jr| j|jkS dS )NF)
isinstancerD   r+   )r>   otherr-   r-   r.   __eq__x   s    z)_InstallRequirementBackedCandidate.__eq__c             C   s   |  | S )N)rJ   )r>   rI   r-   r-   r.   __ne__   s    z)_InstallRequirementBackedCandidate.__ne__c             C   s   | j dkrt| jj| _ | j S )z:The normalised name of the project the candidate refers toN)r;   r   r5   r2   )r>   r-   r-   r.   r@      s    
z'_InstallRequirementBackedCandidate.namec             C   s   | j d kr| jj| _ | j S )N)r<   r5   r3   )r>   r-   r-   r.   rA      s    

z*_InstallRequirementBackedCandidate.versionc             C   s   t dd S )NzOverride in subclass)NotImplementedError)r>   r-   r-   r.   _prepare_abstract_distribution   s    zA_InstallRequirementBackedCandidate._prepare_abstract_distributionc             C   s   | j d k	rd S |  }| | _ | j d k	s2td| jd ksh| jt| j jkshtd| jt| j j| jd ks| j| j j	kstd| j| j j	d S )NzDistribution already installedzName mismatch: {!r} vs {!r}zVersion mismatch: {!r} vs {!r})
r=   rM   get_pkg_resources_distributionr'   r;   r   r2   r1   r<   r3   )r>   abstract_distr-   r-   r.   _prepare   s    



z+_InstallRequirementBackedCandidate._preparec             C   s   |    | jS )N)rP   r=   )r>   r-   r-   r.   r5      s    z'_InstallRequirementBackedCandidate.distc          
   C   sZ   t | j}|d krd S yt|}W n2 tk
rT } ztd| j| d S d }~X Y nX |S )Nz-Package %r has an invalid Requires-Python: %s)r
   r5   r   r   loggerwarningr@   )r>   requires_pythonspecer-   r-   r.   _get_requires_python_specifier   s    
zA_InstallRequirementBackedCandidate._get_requires_python_specifierc                s:    fdd j  D } j  }|r6|| |S )Nc                s    g | ]} j t| jqS r-   )r9   make_requirement_from_specrF   r:   ).0r)r>   r-   r.   
<listcomp>   s   zG_InstallRequirementBackedCandidate.get_dependencies.<locals>.<listcomp>)r5   requiresr9   Z make_requires_python_requirementrV   append)r>   depsZ
python_depr-   )r>   r.   get_dependencies   s    


z3_InstallRequirementBackedCandidate.get_dependenciesc             C   s   |    | jS )N)rP   r:   )r>   r-   r-   r.   get_install_requirement   s    z:_InstallRequirementBackedCandidate.get_install_requirement)NN)rE   
__module____qualname__rB   rG   rJ   rK   propertyr@   rA   rM   rP   r5   rV   r^   r_   r-   r-   r-   r.   r8   `   s    

r8   c                   s&   e Zd Zd fdd	Zdd Z  ZS )r   Nc                s$   t t| j|t|||||d d S )N)r+   r6   r?   r@   rA   )superr   rB   r/   )r>   r+   r,   r?   r@   rA   )rD   r-   r.   rB      s    	
zLinkCandidate.__init__c             C   s   | j j| jS )N)r9   preparerprepare_linked_requirementr:   )r>   r-   r-   r.   rM      s    z,LinkCandidate._prepare_abstract_distribution)NN)rE   r`   ra   rB   rM   __classcell__r-   r-   )rD   r.   r      s    r   c                   s&   e Zd Zd fdd	Zdd Z  ZS )r   Nc                s$   t t| j|t|||||d d S )N)r+   r6   r?   r@   rA   )rc   r   rB   r0   )r>   r+   r,   r?   r@   rA   )rD   r-   r.   rB      s    	
zEditableCandidate.__init__c             C   s   | j j| jS )N)r9   rd   prepare_editable_requirementr:   )r>   r-   r-   r.   rM     s    z0EditableCandidate._prepare_abstract_distribution)NN)rE   r`   ra   rB   rM   rf   r-   r-   )rD   r.   r      s    r   c               @   sT   e Zd Zdd Zdd Zdd Zdd Zed	d
 Zedd Z	dd Z
dd ZdS )r   c             C   s0   || _ t||| _|| _d}|j| j| d S )Nzalready satisfied)r5   r7   r:   r9   rd   prepare_installed_requirement)r>   r5   r,   r?   skip_reasonr-   r-   r.   rB   
  s
    z"AlreadyInstalledCandidate.__init__c             C   s   dj | jj| jdS )Nz{class_name}({distribution!r}))rC   distribution)r1   rD   rE   r5   )r>   r-   r-   r.   rG     s    z"AlreadyInstalledCandidate.__repr__c             C   s(   t || jr$| j|jko"| j|jkS dS )NF)rH   rD   r@   rA   )r>   rI   r-   r-   r.   rJ   #  s    z AlreadyInstalledCandidate.__eq__c             C   s   |  | S )N)rJ   )r>   rI   r-   r-   r.   rK   *  s    z AlreadyInstalledCandidate.__ne__c             C   s   t | jjS )N)r   r5   r2   )r>   r-   r-   r.   r@   .  s    zAlreadyInstalledCandidate.namec             C   s   | j jS )N)r5   r3   )r>   r-   r-   r.   rA   3  s    z!AlreadyInstalledCandidate.versionc                s    fdd j  D S )Nc                s    g | ]} j t| jqS r-   )r9   rW   rF   r:   )rX   rY   )r>   r-   r.   rZ   ;  s   z>AlreadyInstalledCandidate.get_dependencies.<locals>.<listcomp>)r5   r[   )r>   r-   )r>   r.   r^   8  s    
z*AlreadyInstalledCandidate.get_dependenciesc             C   s   d S )Nr-   )r>   r-   r-   r.   r_   ?  s    z1AlreadyInstalledCandidate.get_install_requirementN)rE   r`   ra   rB   rG   rJ   rK   rb   r@   rA   r^   r_   r-   r-   r-   r.   r   	  s   r   c               @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	edd Z
dd Zdd ZdS )ExtrasCandidatea  A candidate that has 'extras', indicating additional dependencies.

    Requirements can be for a project with dependencies, something like
    foo[extra].  The extras don't affect the project/version being installed
    directly, but indicate that we need additional dependencies. We model that
    by having an artificial ExtrasCandidate that wraps the "base" candidate.

    The ExtrasCandidate differs from the base in the following ways:

    1. It has a unique name, of the form foo[extra]. This causes the resolver
       to treat it as a separate node in the dependency graph.
    2. When we're getting the candidate's dependencies,
       a) We specify that we want the extra dependencies as well.
       b) We add a dependency on the base candidate (matching the name and
          version).  See below for why this is needed.
    3. We return None for the underlying InstallRequirement, as the base
       candidate will provide it, and we don't want to end up with duplicates.

    The dependency on the base candidate is needed so that the resolver can't
    decide that it should recommend foo[extra1] version 1.0 and foo[extra2]
    version 2.0. Having those candidates depend on foo=1.0 and foo=2.0
    respectively forces the resolver to recognise that this is a conflict.
    c             C   s   || _ || _d S )N)baseextras)r>   rl   rm   r-   r-   r.   rB   \  s    zExtrasCandidate.__init__c             C   s   dj | jj| j| jdS )Nz.{class_name}(base={base!r}, extras={extras!r}))rC   rl   rm   )r1   rD   rE   rl   rm   )r>   r-   r-   r.   rG   e  s    zExtrasCandidate.__repr__c             C   s(   t || jr$| j|jko"| j|jkS dS )NF)rH   rD   rl   rm   )r>   rI   r-   r-   r.   rJ   m  s    zExtrasCandidate.__eq__c             C   s   |  | S )N)rJ   )r>   rI   r-   r-   r.   rK   t  s    zExtrasCandidate.__ne__c             C   s   t | jj| jS )z:The normalised name of the project the candidate refers to)r   rl   r@   rm   )r>   r-   r-   r.   r@   x  s    zExtrasCandidate.namec             C   s   | j jS )N)rl   rA   )r>   r-   r-   r.   rA   ~  s    zExtrasCandidate.versionc                s   j j jj jj}jj jj}|rJtdjd	t
|  fddj j|D }dj jj j}| |j j |S )Nz"Invalid extras specified in %s: %s,c                s    g | ]}  t|jjqS r-   )rW   rF   rl   r:   )rX   rY   )r?   r>   r-   r.   rZ     s   z4ExtrasCandidate.get_dependencies.<locals>.<listcomp>z{}=={})rl   r9   rm   intersectionr5   
differencerQ   rR   r@   joinsortedr[   r1   rA   r\   rW   r:   )r>   Zvalid_extrasZinvalid_extrasr]   rT   r-   )r?   r>   r.   r^     s    z ExtrasCandidate.get_dependenciesc             C   s   d S )Nr-   )r>   r-   r-   r.   r_     s    z'ExtrasCandidate.get_install_requirementN)rE   r`   ra   __doc__rB   rG   rJ   rK   rb   r@   rA   r^   r_   r-   r-   r-   r.   rk   D  s   	rk   c               @   s<   e Zd Zdd Zedd Zedd Zdd Zd	d
 ZdS )RequiresPythonCandidatec             C   s>   |d k	rt |}ntjd d }tddd |D | _d S )N   .c             s   s   | ]}t |V  qd S )N)rF   )rX   cr-   r-   r.   	<genexpr>  s    z3RequiresPythonCandidate.__init__.<locals>.<genexpr>)r	   sysversion_infor   rq   r<   )r>   py_version_inforz   r-   r-   r.   rB     s    
z RequiresPythonCandidate.__init__c             C   s   dS )Nz<Python fom Requires-Python>r-   )r>   r-   r-   r.   r@     s    zRequiresPythonCandidate.namec             C   s   | j S )N)r<   )r>   r-   r-   r.   rA     s    zRequiresPythonCandidate.versionc             C   s   g S )Nr-   )r>   r-   r-   r.   r^     s    z(RequiresPythonCandidate.get_dependenciesc             C   s   d S )Nr-   )r>   r-   r-   r.   r_     s    z/RequiresPythonCandidate.get_install_requirementN)	rE   r`   ra   rB   rb   r@   rA   r^   r_   r-   r-   r-   r.   rt     s
   rt   )5loggingry   Z pip._vendor.packaging.specifiersr   r   pip._vendor.packaging.utilsr   pip._vendor.packaging.versionr   pip._internal.req.constructorsr   r   Zpip._internal.req.req_installr   pip._internal.utils.miscr	   pip._internal.utils.packagingr
   pip._internal.utils.typingr   rl   r   r   typingr   r   r   r   r   r   r   Zpip._vendor.pkg_resourcesr   pip._internal.distributionsr   pip._internal.models.linkr   r   r?   r   ZBaseCandidate	getLoggerrE   rQ   r/   r0   r7   r8   r   r   r   rk   rt   r-   r-   r-   r.   <module>   s<    
{;`