U
    cUh01                     @   s  d dl Z 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  d dl!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,m-Z- ddl.m/Z/ er4d dl0m1Z2 e2e-e,e3f Z1e4e5Z6G dd de"Zde	e3 eee3 e7f dddZ8e
e3ef eee3 e7f e
e7e3f dddZ9dS )    N)TYPE_CHECKINGDictListOptionalSetTuplecastcanonicalize_name)BaseReporterResolutionImpossible)Resolver)DirectedGraph)
WheelCache)PackageFinder)RequirementPreparer)install_req_extend_extras)InstallRequirement)RequirementSet)BaseResolverInstallRequirementProvider)PipProvider)PipDebuggingReporterPipReporter)get_requirement   )	CandidateRequirement)Factory)Resultc                       s|   e Zd ZdddhZdeeee ee	e	e	e	e	e
eeedf  d fddZee e	ed	d
dZeee dddZ  ZS )r   eagerzonly-if-neededzto-satisfy-onlyN.)preparerfinderwheel_cachemake_install_requse_user_siteignore_dependenciesignore_installedignore_requires_pythonforce_reinstallupgrade_strategypy_version_infoc                    sJ   t    |
| jkstt||||||	|||d	| _|| _|
| _d | _d S )N)	r"   r!   r$   r#   r%   r)   r'   r(   r+   )	super__init___allowed_strategiesAssertionErrorr   factoryr&   r*   _result)selfr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   	__class__ l/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/resolver.pyr-   )   s     
zResolver.__init__)	root_reqscheck_supported_wheelsreturnc              
   C   s0  | j |}t| j |j| j| j|jd}dtjkr:t	 }nt
 }t||}zd}|j|j|d }| _W n> tk
r }	 z | j td|	|j}
|
|	W 5 d }	~	X Y nX t|d}t|j dd d	D ]4}| }|d kr(|j|jkrtt* ||j}|t|t|jj W 5 Q R X q| j  |}|d krFd
|_!nr| j j"rXd|_!n`|j#|j#krnd|_!nJ|j$s~|j%rd|_!n2|j&r|j&j'r|j&j(rt)*d|j qd|_!nq|j&}|r|j+rdj,|j|j#||j-pdd}t).| || q|j/}| j j01| |D ]}d|_2d
|_3q|S )N)r0   constraintsr&   r*   user_requestedZPIP_RESOLVER_DEBUGi@ )Z
max_roundsz,ResolutionImpossible[Requirement, Candidate])r8   c                 S   s   | j | jkS )N)nameproject_name)cr5   r5   r6   <lambda>p       z"Resolver.resolve.<locals>.<lambda>)keyFTz%s is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.zThe 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>)r<   versionlinkreason)4r0   Zcollect_root_requirementsr   r:   r&   r*   r;   osenvironr   r   
RLResolverresolverequirementsr1   r   Zget_installation_errorr   r   sortedmappingvaluesZget_install_requirementr<   r=   
contextlibsuppressKeyErrorr   add_named_requirementr   extrasZget_dist_to_uninstallshould_reinstallr)   rB   is_editableeditableZsource_linkis_fileis_wheelloggerinfo	is_yankedformatyanked_reasonwarningall_requirementsr!    prepare_linked_requirements_morepreparedneeds_more_preparation)r2   r7   r8   Z	collectedproviderZreporterresolverZ#limit_how_complex_resolution_can_beresulteerrorreq_set	candidateireqreqinstalled_distrC   msgreqsr5   r5   r6   rH   I   s    
 
 
 







zResolver.resolve)rf   r9   c                 C   sd   | j dk	std|jsg S | j j}t|t|j }t|j t	j
t|ddd}dd |D S )aZ  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, giving more weight to packages with less
        or no dependencies, while breaking any cycles in the graph at
        arbitrary points. We make no guarantees about where the cycle
        would be broken, other than it *would* be broken.
        Nzmust call resolve() first)weightsT)rA   reversec                 S   s   g | ]\}}|qS r5   r5   ).0_rh   r5   r5   r6   
<listcomp>   s     z3Resolver.get_installation_order.<locals>.<listcomp>)r1   r/   rI   graphget_topological_weightssetkeysrJ   items	functoolspartial_req_set_item_sorter)r2   rf   rr   rm   Zsorted_itemsr5   r5   r6   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   rH   rz   __classcell__r5   r5   r3   r6   r   &   s,   
 ! qr   zDirectedGraph[Optional[str]])rr   requirement_keysr9   c                    s   t  i tt dd fddt  } D ],}|dkrBq4 |D ]} q4qL|| q4|shqt d }|D ]}|krqx||< qx|D ]} | qq*d t  }|rt	|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 first simplify the dependency graph by pruning any leaves and giving them
    the highest weight: a package without any dependencies should be installed
    first. This is done again and again in the same way, giving ever less weight
    to the newly found leaves. The loop stops when no leaves are left: all
    remaining packages have at least one dependency left in the graph.

    Then we continue with the remaining graph, by taking 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 on its 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.

    We are only interested in the weights of packages that are in the
    requirement_keys.
    N)noder9   c                    sf   | krd S  |   | D ]}| q |  | krDd S | d}t|t| < d S )Nr   )additer_childrenremovegetmaxlen)r   childZlast_known_parent_countrr   pathr   visitrm   r5   r6   r      s    


z&get_topological_weights.<locals>.visitr   )
rt   r   r   r   r   r   r   ru   
differencer/   )rr   r   leavesrA   Z_childZweightZleafr   r5   r   r6   rs      s.     
rs   )itemrm   r9   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   rm   r<   r5   r5   r6   ry   2  s    
ry   ):rM   rw   loggingrE   typingr   r   r   r   r   r   r   Zpip._vendor.packaging.utilsr
   Zpip._vendor.resolvelibr   r   r   rG   Zpip._vendor.resolvelib.structsr   pip._internal.cacher   "pip._internal.index.package_finderr    pip._internal.operations.preparer   pip._internal.req.constructorsr   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   pip._internal.utils.packagingr   baser   r   r0   r   Z pip._vendor.resolvelib.resolversr   ZRLResultr   	getLoggerr{   rW   r   rs   ry   r5   r5   r5   r6   <module>   sD   $
 5 Z

