o
    g}”el%  ã                   @   s„  d dl Z d dlZd dlZd dl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 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m Z  d dl!m"Z" d dl#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z* er‰d dl+m,Z- e-e(e'e.f Z,e /e0¡Z1G dd„ deƒZddde2deee. e2f fdd„Z3de	e.ef deee. e2f de	e2e.f fdd„Z4dS )é    N)ÚTYPE_CHECKINGÚDictÚListÚOptionalÚSetÚTupleÚcast©Úcanonicalize_name)ÚBaseReporterÚResolutionImpossible)ÚResolver)ÚDirectedGraph)Ú
WheelCache)ÚPackageFinder)ÚRequirementPreparer)ÚInstallRequirement)ÚRequirementSet)ÚBaseResolverÚInstallRequirementProvider)ÚPipProvider)ÚPipDebuggingReporterÚPipReporteré   )Ú	CandidateÚRequirement)ÚFactory)ÚResultc                       s–   e Zd Zh d£Z	ddededee dede	de	d	e	d
e	de	de
deeedf  f‡ fdd„Zdee de	defdd„Zdedee fdd„Z‡  ZS )r   >   zonly-if-neededzto-satisfy-onlyÚeagerNÚpreparerÚfinderÚwheel_cacheÚmake_install_reqÚuse_user_siteÚignore_dependenciesÚignore_installedÚignore_requires_pythonÚforce_reinstallÚupgrade_strategyÚpy_version_info.c                    sJ   t ƒ  ¡  |
| jv sJ ‚t||||||	|||d�	| _|| _|
| _d | _d S )N)	r    r   r"   r!   r#   r'   r%   r&   r)   )ÚsuperÚ__init__Ú_allowed_strategiesr   Úfactoryr$   r(   Ú_result)Úselfr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   ©Ú	__class__© úu/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.pyr+   &   s    
÷
zResolver.__init__Ú	root_reqsÚcheck_supported_wheelsÚreturnc              
   C   s¦  | j  |¡}t| j |j| j| j|jd�}dtjv rt	ƒ }nt
ƒ }t||ƒ}zd}|j|j|d� }| _W n tyN }	 z| j  td|	ƒ|j¡}
|
|	‚d }	~	ww t|d�}|j ¡ D ]m}| ¡ }|d u rdqY| j  |¡}|d u rrd|_n4| j jrzd|_n,|j|jkr„d|_n"|jsŠ|jrŽd|_n|jr¥|jjr¥|jjr¡t  d	|j!¡ qYd|_nqY|j}|rÁ|j"rÁd
j#|j!|j||j$p¹dd�}t %|¡ | &|¡ qY|j'}| j j( )|¡ |S )N)r-   Úconstraintsr$   r(   Úuser_requestedZPIP_RESOLVER_DEBUGi€„ )Z
max_roundsz,ResolutionImpossible[Requirement, Candidate])r5   FTz�%s is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.z–The candidate selected for download or install is a yanked version: {name!r} candidate (version {version} at {link})
Reason for being yanked: {reason}z<none given>)ÚnameÚversionÚlinkÚreason)*r-   Zcollect_root_requirementsr   r7   r$   r(   r8   ÚosÚenvironr   r   Ú
RLResolverÚresolveÚrequirementsr.   r   Zget_installation_errorr   r   ÚmappingÚvaluesZget_install_requirementZget_dist_to_uninstallÚshould_reinstallr'   r:   Úis_editableÚeditableZsource_linkÚis_fileÚis_wheelÚloggerÚinfor9   Ú	is_yankedÚformatÚyanked_reasonÚwarningÚadd_named_requirementÚall_requirementsr   Ú prepare_linked_requirements_more)r/   r4   r5   Z	collectedZproviderZreporterÚresolverZ try_to_avoid_resolution_too_deepÚresultÚeÚerrorÚreq_setÚ	candidateÚireqÚinstalled_distr;   ÚmsgÚreqsr2   r2   r3   r@   F   s‚   û
þÿþ€û
ü
ø

zResolver.resolverV   c                 C   s^   | j dus	J dƒ‚| j j}t|t| j jƒd d�}t|j ¡ 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() firstr   )Úexpected_node_count)ÚweightsT)ÚkeyÚreversec                 S   s   g | ]\}}|‘qS r2   r2   )Ú.0Ú_rX   r2   r2   r3   Ú
<listcomp>¿   s    z3Resolver.get_installation_order.<locals>.<listcomp>)r.   ÚgraphÚget_topological_weightsÚlenrB   ÚsortedrA   ÚitemsÚ	functoolsÚpartialÚ_req_set_item_sorter)r/   rV   rc   r]   Zsorted_itemsr2   r2   r3   Úget_installation_order¤   s   þýzResolver.get_installation_order)N)Ú__name__Ú
__module__Ú__qualname__r,   r   r   r   r   r   ÚboolÚstrr   Úintr+   r   r   r   r@   rk   Ú__classcell__r2   r2   r0   r3   r   #   sL    ôþýüûúùø	÷
öõô ÿÿ
þ^ÿþr   rc   zDirectedGraph[Optional[str]]r\   r6   c                    sV   t ƒ ‰i ‰dtt ddf‡ ‡‡‡fdd„‰ˆdƒ ˆd dks!J ‚tˆƒ|ks)J ‚ˆ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.
    Únoder6   Nc                    sZ   | ˆv rd S ˆ  | ¡ ˆ  | ¡D ]}ˆ|ƒ qˆ | ¡ ˆ | d¡}t|tˆƒƒˆ| < d S )Nr   )ÚaddZiter_childrenÚremoveÚgetÚmaxre   )rs   ÚchildZlast_known_parent_count©rc   ÚpathÚvisitr]   r2   r3   r{   Ø   s   


z&get_topological_weights.<locals>.visitr   )Úsetr   rp   re   )rc   r\   r2   ry   r3   rd   Â   s    rd   Úitemr]   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	   )r}   r]   r9   r2   r2   r3   rj   ð   s   
rj   )5rh   Úloggingr=   Útypingr   r   r   r   r   r   r   Úpip._vendor.packaging.utilsr
   Zpip._vendor.resolvelibr   r   r   r?   Zpip._vendor.resolvelib.structsr   Úpip._internal.cacher   Ú"pip._internal.index.package_finderr   Ú pip._internal.operations.preparer   Zpip._internal.req.req_installr   Zpip._internal.req.req_setr   Úpip._internal.resolution.baser   r   Z,pip._internal.resolution.resolvelib.providerr   Z,pip._internal.resolution.resolvelib.reporterr   r   Úbaser   r   r-   r   Z pip._vendor.resolvelib.resolversr   ZRLResultrp   Ú	getLoggerrl   rI   rq   rd   rj   r2   r2   r2   r3   Ú<module>   sL    $
  ÿÿ
þ.
ÿþ
ý