U
    cUh                     @   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
mZmZmZ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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%m&Z&m'Z'm(Z(m)Z)m*Z* d d
l+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA d dlBmCZC d dlDmEZE ddlFmGZGmHZHmIZI ddlJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ ddlRmSZSmTZT ddlUmVZVmWZWmXZXmYZYmZZZ erG dd deZ[e\e]Z^edZ_ee1e_f Z`G dd deZaG d d! d!ZbdS )"    N)TYPE_CHECKINGCallableDict	FrozenSetIterableIteratorListMapping
NamedTupleOptionalProtocolSequenceSetTupleTypeVarcast)InvalidRequirement)SpecifierSet)NormalizedNamecanonicalize_name)InvalidVersionVersion)ResolutionImpossible)
CacheEntry
WheelCache)DistributionNotFoundInstallationErrorInvalidInstalledPackageMetadataInconsistentMetadataInvalidUnsupportedPythonVersionUnsupportedWheel)PackageFinder)BaseDistributionget_default_environment)Link)Wheel)RequirementPreparer)install_req_drop_extrasinstall_req_from_link_and_ireq)InstallRequirementcheck_invalid_constraint_type)InstallRequirementProvider)get_supported)Hashes)get_requirement)running_under_virtualenv   )	Candidate
ConstraintRequirement)AlreadyInstalledCandidateBaseCandidateEditableCandidateExtrasCandidateLinkCandidateRequiresPythonCandidateas_base_candidate)FoundCandidatesIndexCandidateInfo)ExplicitRequirementRequiresPythonRequirementSpecifierRequirement!SpecifierWithoutExtrasRequirementUnsatisfiableRequirementc                   @   s   e Zd ZU eed< eed< dS )ConflictCauserequirementparentN)__name__
__module____qualname__r?   __annotations__r2    rJ   rJ   k/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/factory.pyrC   O   s   
rC   Cc                   @   s:   e Zd ZU ee ed< eeef ed< eee	f ed< dS )CollectedRootRequirementsrequirementsconstraintsuser_requestedN)
rF   rG   rH   r   r4   rI   r   strr3   intrJ   rJ   rJ   rK   rM   Z   s   
rM   c                   @   sf  e Zd ZdEeeeee eeeeee	e
df  dd
ddZeedddZedd	d
dZddeee ee edddZeee eedddZeee eee ee ee dddZeeee ee ee dddZee eeee e
 e!e dddZ"e!e# ee e$e dddZ%ee&ee$e dd d!Z'ee(ee!e# f e(ee$e f e&ee)e#egef e!e d"d#d$Z*ee!e e$e# d%d&d'Z+e,e e-d(d)d*Z.ee/d+d,d-Z0dFeee e!e e$e# d/d0d1Z1eee# d2d3d4Z2eee ee3 d5d6d7Z4eee d+d8d9Z5ed: e6d;d<d=Z7e#ee e8d>d?d@Z9dAe:ee&f e;dBdCdDZ<dS )GFactoryN.)
finderpreparermake_install_reqwheel_cacheuse_user_siteforce_reinstallignore_installedignore_requires_pythonpy_version_inforeturnc
                 C   s   || _ || _|| _t|	| _|| _|| _|| _|| _i | _	i | _
i | _i | _i | _t | _|s~t }
dd |
jddD | _ni | _d S )Nc                 S   s   i | ]}|j |qS rJ   )canonical_name).0distrJ   rJ   rK   
<dictcomp>   s    z$Factory.__init__.<locals>.<dictcomp>F)
local_only)_finderrU   _wheel_cacher:   _python_candidate_make_install_req_from_spec_use_user_site_force_reinstall_ignore_requires_python_build_failures_link_candidate_cache_editable_candidate_cache_installed_candidate_cache_extras_candidate_cacher-   _supported_tags_cacher$   iter_installed_distributions_installed_dists)selfrT   rU   rV   rW   rX   rY   rZ   r[   r\   envrJ   rJ   rK   __init__a   s*    


zFactory.__init__r]   c                 C   s   | j S N)rh   rr   rJ   rJ   rK   rY      s    zFactory.force_reinstall)linkr]   c                 C   sB   |j s
d S t|j}|| jj r*d S |j d}t|d S )Nz+ is not a supported wheel on this platform.)is_wheelr&   filename	supportedrc   target_pythonget_unsorted_tagsr!   )rr   rx   wheelmsgrJ   rJ   rK   "_fail_if_link_is_unsupported_wheel   s    
z*Factory._fail_if_link_is_unsupported_wheel
comes_from)baseextrasr   r]   c                C   sZ   t |tdd |D f}z| j| }W n, tk
rT   t|||d}|| j|< Y nX |S )Nc                 s   s   | ]}t |V  qd S rv   )r   )r_   erJ   rJ   rK   	<genexpr>   s     z1Factory._make_extras_candidate.<locals>.<genexpr>r   )id	frozensetrn   KeyErrorr8   )rr   r   r   r   Z	cache_key	candidaterJ   rJ   rK   _make_extras_candidate   s    zFactory._make_extras_candidate)r`   r   templater]   c                 C   sX   z| j |j }W n. tk
r>   t||| d}|| j |j< Y nX |sH|S | j|||dS )N)factoryr   )rm   r^   r   r5   r   )rr   r`   r   r   r   rJ   rJ   rK   _make_candidate_from_dist   s    z!Factory._make_candidate_from_dist)rx   r   r   nameversionr]   c                 C   s0   |  ||||}|r|d kr |S | j|||dS )Nr   )_make_base_candidate_from_linkr   )rr   rx   r   r   r   r   r   rJ   rJ   rK   _make_candidate_from_link   s       z!Factory._make_candidate_from_link)rx   r   r   r   r]   c              
   C   s  || j krd S |jr|| jkrzt||| ||d| j|< W nL ttfk
r } z*tjd||ddid || j |< W Y d S d }~X Y nX | j| S || jkrzt	||| ||d| j|< W nJ tk
r } z*tjd||ddid || j |< W Y d S d }~X Y nX | j| S d S )N)r   r   r   z3Discarding [blue underline]%s[/]: [yellow]%s[reset]markupT)extra)
rj   editablerl   r7   r   r   loggerinfork   r9   )rr   rx   r   r   r   r   rJ   rJ   rK   r      sR    





z&Factory._make_base_candidate_from_link)ireqs	specifierhashesprefers_installedincompatible_idsr]   c           	         s   |sdS |d j stdtj jt  |D ]<}|j sFtd|j jM |jddM  t|jO  q4tt	 d fdd}t
t d fd	d
}t|| |S )NrJ   r   z)Candidates found on index must be PEP 508F)trust_internetru   c               
      s   j r
dS zj } W n tk
r.   Y dS X zj| jddsHW dS W n. tk
rx } zt| |dW 5 d}~X Y nX j|  d}t|krdS |S )z6Get the candidate for the currently-installed version.NT)prereleases)r`   invalid_exc)r`   r   r   )	rh   rq   r   containsr   r   r   r   r   )installed_distr   r   )r   r   r   rr   r   r   rJ   rK   _get_installed_candidate  s&    
z@Factory._iter_found_candidates.<locals>._get_installed_candidatec               	   3   s   j jd} | j}tdd |D }ttddd}|}t|D ]>}|rV|s`|jjr`qJt	j
j|j |jd}|j|fV  qJd S )N)project_namer   r   c                 s   s   | ]}|j jV  qd S rv   )rx   	is_yanked)r_   icanrJ   rJ   rK   r   =  s     zUFactory._iter_found_candidates.<locals>.iter_index_candidate_infos.<locals>.<genexpr>r   r]   c                 S   s<   | D ]2}|j dkr dS |j dkr$q|jdr2q dS dS )Nz===T==z.*F)operatorr   endswith)r   sprJ   rJ   rK   	is_pinned?  s    

zUFactory._iter_found_candidates.<locals>.iter_index_candidate_infos.<locals>.is_pinned)rx   r   r   r   r   )rc   find_best_candidateapplicable_candidatesallr   boolreversedrx   r   	functoolspartialr   r   )resultZicansZ
all_yankedr   pinnedr   func)r   r   r   rr   r   r   rJ   rK   iter_index_candidate_infos2  s*    zBFactory._iter_found_candidates.<locals>.iter_index_candidate_infos)reqAssertionErrorr   r   r   r   r   r   r   r2   r   r=   r<   )	rr   r   r   r   r   r   ireqr   r   rJ   )r   r   r   r   rr   r   r   rK   _iter_found_candidates   s&      (zFactory._iter_found_candidates)base_requirementsr   r]   c                 c   sJ   |D ]@}|  \}}|dkrqt|}|dk	s6td| ||V  qdS )a8  Produce explicit candidates from the base given an extra-ed package.

        :param base_requirements: Requirements known to the resolver. The
            requirements are guaranteed to not have extras.
        :param extras: The extras to inject into the explicit requirements'
            candidates.
        Nzno extras here)get_candidate_lookupr;   r   r   )rr   r   r   r   Zlookup_cand_Z	base_candrJ   rJ   rK   #_iter_explicit_candidates_from_basea  s    z+Factory._iter_explicit_candidates_from_base)
identifier
constraintr   r]   c                 c   s@   |j D ]4}| | | j|t||t|dd}|r|V  qdS )zProduce explicit candidates from constraints.

        This creates "fake" InstallRequirement objects that are basically clones
        of what "should" be the template, but with original_link set to link.
        Nr   r   r   )linksr   r   r)   r   )rr   r   r   r   rx   r   rJ   rJ   rK   !_iter_candidates_from_constraintsw  s    

z)Factory._iter_candidates_from_constraints)r   rN   incompatibilitiesr   r   is_satisfied_byr]   c              	      sN  t  }g } D ]4}	|	 \}
}|
d k	r4||
 |d k	r|| qttl t}|jkr|	| 
|jdt|j |jg D ]"}	|	 \}}|d k	r|| qW 5 Q R X |rz|	| j |d d W n tk
r    Y dS X dd |dD |s4| | j j|S  fdd|D S )NrJ   r   )r   c                 S   s   h | ]}t |qS rJ   )r   )r_   crJ   rJ   rK   	<setcomp>  s     z*Factory.find_candidates.<locals>.<setcomp>c                 3   sD   | ]< t  kr rt fd d D r V  qdS )c                 3   s   | ]}| V  qd S rv   rJ   )r_   r   )r   r   rJ   rK   r     s     z4Factory.find_candidates.<locals>.<genexpr>.<genexpr>N)r   r   r   )r_   r   r   Zincompat_idsr   rN   )r   rK   r     s
   
z*Factory.find_candidates.<locals>.<genexpr>)setr   addappend
contextlibsuppressr   r/   r   updater   getr   r   r   r!   r   r   r   )rr   r   rN   r   r   r   r   Zexplicit_candidatesr   r   candr   Zparsed_requirementr   rJ   r   rK   find_candidates  sX    


zFactory.find_candidates)r   requested_extrasr]   c                 c   s   | |std|j|j n|jsR|jrF|jdk	rF|jjrFt	|V  t
|V  n| |j | j|j|jrtt|n||jrt|jnddd}|dkr|js| j|j tt|jV  n,| |V  |jr| | |t|jV  dS )aW  
        Returns requirement objects associated with the given InstallRequirement. In
        most cases this will be a single object but the following special cases exist:
            - the InstallRequirement has markers that do not apply -> result is empty
            - the InstallRequirement has both a constraint (or link) and extras
                -> result is split in two requirement objects: one with the constraint
                (or link) and one with the extra. This allows centralized constraint
                handling for the base, resulting in fewer candidate rejections.
        z6Ignoring %s: markers '%s' don't match your environmentNr   )match_markersr   r   r   markersrx   r   r   r   rA   r@   r   r   r(   r   rj   rB   make_requirement_from_candidater   r   )rr   r   r   r   rJ   rJ   rK   #_make_requirements_from_install_req  s4    

z+Factory._make_requirements_from_install_req)
root_ireqsr]   c           	      C   s   t g i i }t|D ]\}}|jrt|}|r6t|| s@q|jsNtdt|j}||j	krv|j	|  |M  < qt
||j	|< qt| j|dd}|sq|d }|jr|j|jkr||j|j< |j| q|jjdd d |S )NzConstraint must be namedrJ   )r   r   c                 S   s   | j | jkS rv   )r   r   )rrJ   rJ   rK   <lambda>5      z3Factory.collect_root_requirements.<locals>.<lambda>)key)rM   	enumerater   r+   r   r   r   r   r   rO   r3   	from_ireqlistr   user_suppliedrP   rN   extendsort)	rr   r   	collectedir   problemr   reqsr   rJ   rJ   rK   collect_root_requirements  s6    

	z!Factory.collect_root_requirements)r   r]   c                 C   s   t |S rv   )r>   )rr   r   rJ   rJ   rK   r   8  s    z'Factory.make_requirement_from_candidaterJ   )r   r   r   r]   c                 C   s   |  ||}| ||S )a(  
        Returns requirement objects associated with the given specifier. In most cases
        this will be a single object but the following special cases exist:
            - the specifier has markers that do not apply -> result is empty
            - the specifier has both a constraint and extras -> result is split
                in two requirement objects: one with the constraint and one with the
                extra. This allows centralized constraint handling for the base,
                resulting in fewer candidate rejections.
        )rf   r   )rr   r   r   r   r   rJ   rJ   rK   make_requirements_from_spec=  s    z#Factory.make_requirements_from_specr   c                 C   s"   | j r
d S t|sd S t|| jS rv   )ri   rQ   r?   re   )rr   r   rJ   rJ   rK    make_requires_python_requirementO  s
    z(Factory.make_requires_python_requirement)rx   r   r]   c                 C   s"   | j dkrdS | j j||| jdS )a  Look up the link in the wheel cache.

        If ``preparer.require_hashes`` is True, don't use the wheel cache,
        because cached wheels, always built locally, have different hashes
        than the files downloaded from the index server and thus throw false
        hash mismatches. Furthermore, cached wheels at present have
        nondeterministic contents due to file modification times.
        N)rx   package_namesupported_tags)rd   get_cache_entryro   )rr   rx   r   rJ   rJ   rK   get_wheel_cache_entryZ  s    
zFactory.get_wheel_cache_entryc                 C   sZ   | j |j}|d krd S | js$|S |jr.|S t rV|jrVd|j d|j }t	|d S )NzNWill not install to the user site because it will lack sys.path precedence to z in )
rq   r   r   rg   in_usersiter0   in_site_packagesraw_namelocationr   )rr   r   r`   messagerJ   rJ   rK   get_dist_to_uninstallm  s    zFactory.get_dist_to_uninstallrC   )causesr]   c                 C   s   |st d| jj}t|dkrVt|d jj}d|d jjd| d|}t	|S d| d}|D ]0}|j
 }t|jj}|d	|d
| d7 }qft	|S )Nz,Requires-Python error reported with no causer1   r   zPackage z requires a different Python: z not in z%Packages require a different Python. z not in:
z (required by ))r   re   r   lenrQ   rD   r   rE   r   r    format_for_error)rr   r   r   r   r   causepackagerJ   rJ   rK   _report_requires_python_error  s    
z%Factory._report_requires_python_error)r   rE   r]   c                 C   s  |d krt |}n| d|j d}| j|j}| j }t }t }|D ]4}|jr^|jjnd}	|	rt|	|j
 qL|	|j
 qLdd t|D }
dd t|D }|rtdd|pd	 |rtd
d|pd	 td|d|
pd	 t |dkr
td td| S )Nz (from r   Fc                 S   s   g | ]}t |qS rJ   rQ   r_   vrJ   rJ   rK   
<listcomp>  s     z?Factory._report_single_requirement_conflict.<locals>.<listcomp>c                 S   s   g | ]}t |qS rJ   r   r   rJ   rJ   rK   r     s     z)Ignored the following yanked versions: %s, nonezJIgnored the following versions that require a different python version: %sz; zNCould not find a version that satisfies the requirement %s (from versions: %s)zrequirements.txtzHINT: You are attempting to install a package literally named "requirements.txt" (which cannot exist). Consider using the '-r' flag to install the packages listed in requirements.txtz#No matching distribution found for )rQ   r   rc   find_all_candidatesr   requires_python_skipped_reasonsr   rx   r   r   r   sortedr   criticaljoinr   r   )rr   r   rE   Zreq_dispZcandsZskipped_by_requires_pythonZversions_setZyanked_versions_setr   r   versionsZyanked_versionsrJ   rJ   rK   #_report_single_requirement_conflict  sD    

z+Factory._report_single_requirement_conflictz,ResolutionImpossible[Requirement, Candidate])r   rO   r]   c                    s  |j std fdd|j D }|r6 td|S t|j dkrh|j d \}}|j|krh ||S tt tddd	}t	td
dd}t
 }|j D ],\}}|d kr| }	n||}	||	 q|r|t|}
nd}
d|
 d}t| d}t
 }|j D ]^\}}|j|kr"||j |d }|rJ||j d|j d }n|d }||  }q|D ]"}|| j}|d| | 7 }qf|d d d d d }t| tdS )Nz)Installation error reported with no causec                    s*   g | ]"}t |jtr|j js|qS rJ   )
isinstancerD   r?   r   re   )r_   r   rw   rJ   rK   r     s   z2Factory.get_installation_error.<locals>.<listcomp>zSequence[ConflictCause]r1   r   )partsr]   c                 S   s2   t | dkr| d S d| d d d | d  S )Nr1   r   r   z and )r   r  )r	  rJ   rJ   rK   	text_join  s    z1Factory.get_installation_error.<locals>.text_join)rE   r]   c                 S   sF   |   }|r|js$| j d| j S t|jtr<t|jjS t|jS )Nr   )get_install_requirementr   r   r   r  r*   rQ   )rE   r   rJ   rJ   rK   describe_trigger  s    
z8Factory.get_installation_error.<locals>.describe_triggerzthe requested packageszCannot install z> because these package versions have conflicting dependencies.z
The conflict is caused by:z
     z depends on zThe user requested z%
    The user requested (constraint) z

zTo fix this you could try to:
z91. loosen the range of package versions you've specified
z<2. remove package versions to allow pip to attempt to solve zthe dependency conflict
zResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts)r   r   r   r   r   r   r  r   rQ   r2   r   r   r   r  r   r  r   r   r   r   )rr   r   rO   Zrequires_python_causesr   rE   r  r  ZtriggersZtriggerr   r   Zrelevant_constraintsr   specrJ   rw   rK   get_installation_error  sn    
	




	
zFactory.get_installation_error)N)rJ   )=rF   rG   rH   r"   r'   r,   r   r   r   r   rR   rt   propertyrY   r%   r   r6   r   rQ   r*   r8   r   r#   r2   r   r   r   r   r   r   r   r.   r   r   r   r4   r   r   r3   r   r	   r   r   r   r   rM   r   r>   r   r   r   r   r   r   r    r   r   r  r   r   r  rJ   rJ   rJ   rK   rS   `   s    ';hM 6+	   6
rS   )cr   r   loggingtypingr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   "pip._vendor.packaging.requirementsr   Z pip._vendor.packaging.specifiersr   pip._vendor.packaging.utilsr   r   pip._vendor.packaging.versionr   r   pip._vendor.resolvelibr   pip._internal.cacher   r   pip._internal.exceptionsr   r   r   r   r   r    r!   "pip._internal.index.package_finderr"   pip._internal.metadatar#   r$   pip._internal.models.linkr%   pip._internal.models.wheelr&    pip._internal.operations.preparer'   pip._internal.req.constructorsr(   r)   pip._internal.req.req_installr*   r+   pip._internal.resolution.baser,   &pip._internal.utils.compatibility_tagsr-   pip._internal.utils.hashesr.   pip._internal.utils.packagingr/   pip._internal.utils.virtualenvr0   r   r2   r3   r4   
candidatesr5   r6   r7   r8   r9   r:   r;   Zfound_candidatesr<   r=   rN   r>   r?   r@   rA   rB   rC   	getLoggerrF   r   rL   CacherM   rS   rJ   rJ   rJ   rK   <module>   sB   H$	$	
