
0c@_¥'  ã               @   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 d  d l m Z d d l m Z e rŒd  d l 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, d  d l m- Z- d  d l m. Z. e j/ e0 ƒ Z1 Gd d „  d e ƒ Z	 d d „  Z2 d d „  Z3 d S)é    N)Úsix)Úcanonicalize_name)ÚBaseReporterÚResolutionImpossible)ÚResolver)ÚInstallationError)Úcheck_invalid_constraint_type)ÚRequirementSet)ÚBaseResolver)ÚPipProvider)Údist_is_editable)ÚMYPY_CHECK_RUNNINGé   )ÚFactory)ÚDictÚListÚOptionalÚSetÚTuple)ÚSpecifierSet)ÚResult)ÚGraph)Ú
WheelCache)ÚPackageFinder)ÚRequirementPreparer)ÚInstallRequirement)ÚInstallRequirementProviderc                   sO   e  Z d  Z d d d h Z d d ‡  f d d † Z d d	 „  Z d
 d „  Z ‡  S)r   Zeagerzonly-if-neededzto-satisfy-onlyNFc                s¢   t  t |  ƒ j ƒ  | r& t j d ƒ |
 |  j k s; t ‚ t d | d | d | d | d | d |	 d | d	 | d
 | d | ƒ 
|  _ | |  _	 |
 |  _
 d  |  _ d  S)NzÊpip is using lazily downloaded wheels using HTTP range requests to obtain dependency information. This experimental feature is enabled through --use-feature=fast-deps and it is not ready for production.ÚfinderÚpreparerÚmake_install_reqÚwheel_cacheÚuse_user_siteÚforce_reinstallÚignore_installedÚignore_requires_pythonÚpy_version_infoÚ
lazy_wheel)Úsuperr   Ú__init__ÚloggerÚwarningÚ_allowed_strategiesÚAssertionErrorr   ÚfactoryÚignore_dependenciesÚupgrade_strategyÚ_result)Úselfr   r   r    r   r!   r.   r#   r$   r"   r/   r%   r&   )Ú	__class__© úK/tmp/pip-build-jynh7p1z/pip/pip/_internal/resolution/resolvelib/resolver.pyr(   '   s&    		zResolver.__init__c             C   sà  i  } t  ƒ  } g  } xà | D]Ø } | j r› t | ƒ } | rI t | ƒ ‚ | j ƒ  sX q t | j ƒ } | | k r‹ | | | j @| | <qô | j | | <q | j rÃ | j rÃ | j	 t | j ƒ ƒ |  j
 j | d f  ƒ}	 |	 d  k	 r | j |	 ƒ q Wt d |  j
 d | d |  j d |  j d | ƒ }
 t ƒ  } t |
 | ƒ } y" d } | j | d | ƒ|  _ WnG t k
 r«} z' |  j
 j | ƒ } t j | | ƒ WYd  d  } ~ Xn Xt d	 | ƒ } x|  j j j ƒ  D]
} | j ƒ  } | d  k rïqÎ|  j
 j | ƒ } | d  k rd
 | _ nZ |  j
 j r1d | _ nB | j | j  k rOd | _ n$ t! | ƒ | j" k rÎd | _ n qÎ| j# } | rË| j$ rËd j% d | j d | j  d | d | j& p¸d ƒ } t' j( | ƒ | j) | ƒ qÎW| S)NZrequested_extrasr-   Úconstraintsr.   r/   Úuser_requestedi€„ Z
max_roundsÚcheck_supported_wheelsFTz–The candidate selected for download or install is a yanked version: {name!r} candidate (version {version} at {link})
Reason for being yanked: {reason}ÚnameÚversionÚlinkÚreasonz<none given>)*ÚsetÚ
constraintr   r   Úmatch_markersr   r8   Ú	specifierZuser_suppliedÚaddr-   Z!make_requirement_from_install_reqÚappendr   r.   r/   r   Ú
RLResolverÚresolver0   r   Zget_installation_errorr   Ú
raise_fromr	   ÚmappingÚvaluesZget_install_requirementZget_dist_to_uninstallZshould_reinstallr"   Úparsed_versionr9   r   Zis_editableZsource_linkZ	is_yankedÚformatZyanked_reasonr)   r*   Zadd_named_requirement)r1   Ú	root_reqsr7   r5   r6   ÚrequirementsÚreqZproblemr8   ÚrZproviderZreporterÚresolverZ try_to_avoid_resolution_too_deepÚeÚerrorÚreq_setÚ	candidateÚireqZinstalled_distr:   Úmsgr3   r3   r4   rC   Q   sx    								#
				zResolver.resolvec             C   st   |  j  d k	 s t d ƒ ‚ |  j  j } t | ƒ } t | j j ƒ  d t j t	 d | ƒd d ƒ} d d „  | Dƒ S)	a  Get order for installation of requirements in RequirementSet.

        The returned list contains a requirement before another that depends on
        it. This helps ensure that the environment is kept consistent as they
        get installed one-by-one.

        The current implementation creates a topological ordering of the
        dependency graph, while breaking any cycles in the graph at arbitrary
        points. We make no guarantees about where the cycle would be broken,
        other than they would be broken.
        Nzmust call resolve() firstÚkeyÚweightsÚreverseTc             S   s   g  |  ] \ } } | ‘ q Sr3   r3   )Ú.0Ú_rR   r3   r3   r4   ú
<listcomp>Æ   s   	 z3Resolver.get_installation_order.<locals>.<listcomp>)
r0   r,   ÚgraphÚget_topological_weightsÚsortedrJ   ÚitemsÚ	functoolsÚpartialÚ_req_set_item_sorter)r1   rP   rZ   rU   Úsorted_itemsr3   r3   r4   Úget_installation_order¯   s    	zResolver.get_installation_order)Ú__name__Ú
__module__Ú__qualname__r+   r(   rC   rb   r3   r3   )r2   r4   r   $   s
   ^r   c                sl   t  ƒ  ‰ i  ‰ ‡  ‡ ‡ ‡ f d d †  ‰ ˆ d ƒ ˆ d d k sJ t ‚ t ˆ ƒ t ˆ  ƒ k sh t ‚ ˆ S)aŸ  Assign weights to each node based on how "deep" they are.

    This implementation may change at any point in the future without prior
    notice.

    We take the length for the longest path to any node from root, ignoring any
    paths that contain a single node twice (i.e. cycles). This is done through
    a depth-first search through the graph, while keeping track of the path to
    the node.

    Cycles in the graph result would result in node being revisited while also
    being it's own path. In this case, take no action. This helps ensure we
    don't get stuck in a cycle.

    When assigning weight, the longer path (i.e. larger length) is preferred.
    c                s}   |  ˆ k r d  Sˆ j  |  ƒ x! ˆ  j |  ƒ D] } ˆ | ƒ q- Wˆ j |  ƒ ˆ j |  d ƒ } t | t ˆ ƒ ƒ ˆ |  <d  S)Nr   )r@   Ziter_childrenÚremoveÚgetÚmaxÚlen)ÚnodeÚchildZlast_known_parent_count)rZ   ÚpathÚvisitrU   r3   r4   rm   Þ   s    z&get_topological_weights.<locals>.visitNr   )r<   r,   ri   )rZ   r3   )rZ   rl   rm   rU   r4   r[   É   s    	
r[   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   )ÚitemrU   r8   r3   r3   r4   r`   ÷   s    r`   )4r^   ÚloggingZpip._vendorr   Úpip._vendor.packaging.utilsr   Zpip._vendor.resolvelibr   r   r   rB   Zpip._internal.exceptionsr   Zpip._internal.req.req_installr   Zpip._internal.req.req_setr	   Zpip._internal.resolution.baser
   Z,pip._internal.resolution.resolvelib.providerr   Zpip._internal.utils.miscr   Zpip._internal.utils.typingr   r-   r   Ztypingr   r   r   r   r   Z pip._vendor.packaging.specifiersr   Z pip._vendor.resolvelib.resolversr   Zpip._vendor.resolvelib.structsr   Zpip._internal.cacher   Z"pip._internal.index.package_finderr   Z pip._internal.operations.preparer   r   r   Ú	getLoggerrc   r)   r[   r`   r3   r3   r3   r4   Ú<module>   s6   (¥.