B
    `d                 @   s  d dl Z d dl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 d d
lmZ ddlmZ erd dl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'e(Z)G dd deZ	dd Z*dS )    N)six)canonicalize_name)BaseReporterResolutionImpossible)Resolver)InstallationError)RequirementSet)BaseResolver)PipProvider)MYPY_CHECK_RUNNING   )Factory)DictListOptionalTuple)Result)
WheelCache)PackageFinder)RequirementPreparer)InstallRequirement)InstallRequirementProviderc                   s.   e Zd Zd fdd	Zdd Zdd Z  ZS )	r   Nc          	      s6   t t|   t||||	|||d| _|| _d | _d S )N)finderpreparermake_install_reqforce_reinstallignore_installedignore_requires_pythonpy_version_info)superr   __init__r   factoryignore_dependencies_result)selfr   r   wheel_cacher   use_user_siter"   r   r   r   upgrade_strategyr   )	__class__ P/tmp/pip-unpacked-wheel-hu9qqap1/pip/_internal/resolution/resolvelib/resolver.pyr    !   s    
zResolver.__init__c          
      sP  t dd |D rtdt j jd}t }t||} fdd|D }y|| _W n t	k
r } z~ j
|}|sx<|jD ]2\}	}
tdt|	 |
d krdn
d	|
j  qW td
ddd |jD   t|| W d d }~X Y nX t|d}xF jj D ]6}||}|d kr.q j||_|| qW |S )Nc             s   s   | ]}|j V  qd S )N)
constraint).0rr)   r)   r*   	<genexpr>@   s    z#Resolver.resolve.<locals>.<genexpr>z"Constraints are not yet supported.)r!   r"   c                s   g | ]} j |qS r)   )r!   Z!make_requirement_from_install_req)r,   r-   )r$   r)   r*   
<listcomp>K   s   z$Resolver.resolve.<locals>.<listcomp>z8Could not find a version that satisfies the requirement  z
 (from {})z#No matching distribution found for z, c             S   s   g | ]\}}|j qS r)   )name)r,   r-   _r)   r)   r*   r/   d   s    )check_supported_wheels)anyr   r
   r!   r"   r   
RLResolverresolver#   r   Zget_installation_errorZcausesloggercriticalstrformatr1   joinr   
raise_fromr   mappingvaluesZget_install_requirementshould_reinstalladd_named_requirement)r$   	root_reqsr3   ZproviderZreporterresolverrequirementseerrorreqparentreq_set	candidateireqr)   )r$   r*   r6   <   s@    






zResolver.resolvec       	         s   | j dk	stdi  | j j}t| j jd }xt |k rd}xl|D ]d}| krTqFt||}t fdd|D szqF|rt fdd|D d }nd}| |< d	}qFW |s0t	d
q0W t
|j tjt dd	d}dd |D S )a  Create a list that orders given requirements for installation.

        The returned list should contain all requirements in ``req_set``,
        so the caller can loop through it and have a requirement installed
        before the requiring thing.

        The current implementation walks the resolved dependency graph, and
        make sure every node has a greater "weight" than all its parents.
        Nzmust call resolve() firstr   Fc             3   s   | ]}| kV  qd S )Nr)   )r,   p)weightsr)   r*   r.      s    z2Resolver.get_installation_order.<locals>.<genexpr>c             3   s   | ]} | V  qd S )Nr)   )r,   rK   )rL   r)   r*   r.      s    r   TzACould not determine installation order due to cicular dependency.)rL   )keyreversec             S   s   g | ]\}}|qS r)   r)   )r,   r2   rJ   r)   r)   r*   r/      s    z3Resolver.get_installation_order.<locals>.<listcomp>)r#   AssertionErrorgraphlenr=   listZiter_parentsallmaxr   sortedrC   items	functoolspartial_req_set_item_sorter)	r$   rH   rP   Z	key_countZ
progressedrM   parentsZweightZsorted_itemsr)   )rL   r*   get_installation_orders   s2    

zResolver.get_installation_order)N)__name__
__module____qualname__r    r6   r[   __classcell__r)   r)   )r(   r*   r       s   7r   c             C   s   t | d }|| |fS )a)  Key function used to sort install requirements for installation.

    Based on the "weight" mapping calculated in ``get_installation_order()``.
    The canonical package name is returned as the second member as a tie-
    breaker to ensure the result is predictable, which is useful in tests.
    r   )r   )itemrL   r1   r)   r)   r*   rY      s    rY   )+rW   loggingpip._vendorr   pip._vendor.packaging.utilsr   Zpip._vendor.resolvelibr   r   r   r5   pip._internal.exceptionsr   Zpip._internal.req.req_setr   pip._internal.resolution.baser	   Z,pip._internal.resolution.resolvelib.providerr
   pip._internal.utils.typingr   r!   r   typingr   r   r   r   Z pip._vendor.resolvelib.resolversr   pip._internal.cacher   "pip._internal.index.package_finderr    pip._internal.operations.preparer   Zpip._internal.req.req_installr   r   	getLoggerr\   r7   rY   r)   r)   r)   r*   <module>   s.   
 