a
    e0hJ                     @   s  d dl Z d dlmZ d dl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 d dlmZ d dl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mZmZm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( erd dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZF ddlmGZGmHZH ddlmIZI e3dZJe*eBeJf ZKe*e7eGf ZLe MeNZOG dd dePZQdS )    N)canonicalize_name)DistributionNotFoundInstallationErrorInstallationSubprocessErrorMetadataInconsistentUnsupportedPythonVersionUnsupportedWheel)Wheel)InstallRequirement)get_supported)Hashes)dist_in_site_packagesdist_in_usersiteget_installed_distributions)MYPY_CHECK_RUNNING)running_under_virtualenv   )
Constraint)AlreadyInstalledCandidateEditableCandidateExtrasCandidateLinkCandidateRequiresPythonCandidate)FoundCandidates)ExplicitRequirementRequiresPythonRequirementSpecifierRequirementUnsatisfiableRequirement)
Dict	FrozenSetIterableIteratorListOptionalSequenceSetTupleTypeVar)SpecifierSet)_BaseVersion)Distribution)ResolutionImpossible)
CacheEntry
WheelCache)PackageFinder)Link)RequirementPreparer)InstallRequirementProvider)	CandidateRequirement)BaseCandidateCc                   @   s   e Zd ZdddZedd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zd ddZdd Zdd Zdd Zdd Zdd ZdS )!FactoryNc
           
      C   sr   || _ || _|| _t|	| _|| _|| _|| _|| _i | _	i | _
i | _i | _|shdd tddD | _ni | _d S )Nc                 S   s   i | ]}t |j|qS  )r   project_name).0distr7   r7   Y/var/www/auris/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py
<dictcomp>k   s   z$Factory.__init__.<locals>.<dictcomp>F)
local_only)_finderpreparer_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_cacher   _installed_dists)
selffinderr?   make_install_reqwheel_cacheuse_user_siteforce_reinstallignore_installedignore_requires_pythonpy_version_infor7   r7   r;   __init__N   s"    

zFactory.__init__c                 C   s   | j S N)rD   )rK   r7   r7   r;   rP   r   s    zFactory.force_reinstallc                 C   sP   z| j |j }W n, ty<   t||| d}|| j |j< Y n0 |rLt||S |S )N)factory)rI   keyKeyErrorr   r   )rK   r:   extrastemplatebaser7   r7   r;   _make_candidate_from_distw   s    
z!Factory._make_candidate_from_distc              
   C   s  || j v rd S |jr|| jvr~zt||| ||d| j|< W nB ttfy| } z&td|| || j |< W Y d }~d S d }~0 0 | j| }nx|| jv rzt	||| ||d| j|< W nD ttf y } z&td|| || j |< W Y d }~d S d }~0 0 | j| }|rt
||S |S )N)rV   nameversionzDiscarding %s. %s)rF   editablerH   r   r   r   loggerwarningrG   r   r   )rK   linkrY   rZ   r]   r^   er[   r7   r7   r;   _make_candidate_from_link   s8    





z!Factory._make_candidate_from_linkc           	         s   |sdS |d t jjt  |D ].}|jjM |jddM  t|jO  q&d }jsjv rj }j	|j
ddrj| d} fdd	}t|||S )
Nr7   r   F)trust_internetT)prereleases)r:   rY   rZ   c                  3   s   j jd} t|  }tdd |D }t }t|D ]R}|sP|jjrPq>|j	|v r\q>j
|j |j	d}|d u r~q>|V  ||j	 q>d S )N)r8   	specifierhashesc                 s   s   | ]}|j jV  qd S rU   )rb   	is_yanked)r9   icanr7   r7   r;   	<genexpr>       zPFactory._iter_found_candidates.<locals>.iter_index_candidates.<locals>.<genexpr>)rb   rY   rZ   r]   r^   )r>   find_best_candidatelistiter_applicableallsetreversedrb   ri   r^   rd   add)resulticans
all_yankedversions_foundrj   	candidaterY   rh   r]   rK   rg   rZ   r7   r;   iter_index_candidates   s0    
z=Factory._iter_found_candidates.<locals>.iter_index_candidates)r   reqr]   	frozensetrg   rh   rY   rD   rJ   containsr^   r\   r   )	rK   ireqsrg   rh   prefers_installedireqinstalled_candidateinstalled_distrz   r7   ry   r;   _iter_found_candidates   s0    
!zFactory._iter_found_candidatesc           	         sp   t  }g }D ]4}| \}}|d ur0|| |d ur|| q|s\| | j j|S  fdd|D S )Nc                 3   s2   | ]*   rt fd dD r V  qdS )c                 3   s   | ]}|  V  qd S rU   )is_satisfied_by)r9   r{   cr7   r;   rk     rl   z4Factory.find_candidates.<locals>.<genexpr>.<genexpr>N)r   rp   )r9   
constraintrequirementsr   r;   rk     s   
z*Factory.find_candidates.<locals>.<genexpr>)rq   get_candidate_lookuprs   appendr   rg   rh   )	rK   r   r   r   explicit_candidatesr~   r{   candr   r7   r   r;   find_candidates  s$    
zFactory.find_candidatesc                 C   s   | |s td|j|j d S |js.t|S |jjrht|jj	}|
| jj shd|j	}t|| j|jt|j||jrt|jnd d d}|d u r|js| j|j tt|jS | |S )Nz6Ignoring %s: markers '%s' don't match your environmentz-{} is not a supported wheel on this platform.)rY   rZ   r]   r^   )match_markersr`   infor]   markersrb   r   is_wheelr	   filename	supportedr>   target_pythonget_tagsformatr   rd   r|   rY   r   rF   r   make_requirement_from_candidate)rK   r   requested_extraswheelmsgr   r7   r7   r;   !make_requirement_from_install_req!  s6    
z)Factory.make_requirement_from_install_reqc                 C   s   t |S rU   )r   )rK   rx   r7   r7   r;   r   E  s    z'Factory.make_requirement_from_candidater7   c                 C   s   |  ||}| ||S rU   )rB   r   )rK   rg   
comes_fromr   r   r7   r7   r;   make_requirement_from_specI  s    z"Factory.make_requirement_from_specc                 C   s   | j s|d u rd S t|| jS rU   )rE   r   rA   )rK   rg   r7   r7   r;    make_requires_python_requirementS  s    z(Factory.make_requires_python_requirementc                 C   s*   | j du s| jjrdS | j j||t 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)rb   package_namesupported_tags)r@   r?   require_hashesget_cache_entryr   )rK   rb   r]   r7   r7   r;   get_wheel_cache_entryY  s    
zFactory.get_wheel_cache_entryc                 C   sV   | j |j}|d u rd S | js$|S t|r0|S t rRt|rRtd|j	|j
d S )NzVWill not install to the user site because it will lack sys.path precedence to {} in {})rJ   getr]   rC   r   r   r   r   r   r8   location)rK   rx   r:   r7   r7   r;   get_dist_to_uninstallk  s    zFactory.get_dist_to_uninstallc                 C   s(   d}|j |j| jjt|jd}t|S )NzOPackage {package!r} requires a different Python: {version} not in {specifier!r})packager^   rg   )r   r]   rA   r^   strrg   r   )rK   requirementrZ   message_formatmessager7   r7   r;   _report_requires_python_error  s    z%Factory._report_requires_python_errorc                 C   s|  |j sJ d|j D ]$}t|jtr| |j|j  S qt|j dkr|j d \}}|d u rht|}nd||j	}t
d| td|S dd }d	d
 }t }|j D ],\}}|d u r| }	n||}	||	 q|r|t|}
nd}
d|
}t
| d}|j D ]B\}}|d }|r:|d|j	|j }n|d }||  }q|d d d d d }t
| tdS )Nz)Installation error reported with no causer   r   z{} (from {})z:Could not find a version that satisfies the requirement %sz%No matching distribution found for {}c                 S   s2   t | dkr| d S d| d d d | d  S )Nr   r   z, z and )lenjoin)partsr7   r7   r;   	text_join  s    z1Factory.get_installation_error.<locals>.text_joinc                 S   sD   |   }|r|js"d| j| jS t|jtr:t|jjS t|jS )Nz{}=={})get_install_requirementr   r   r]   r^   
isinstancer
   r   )parentr   r7   r7   r;   describe_trigger  s    
z8Factory.get_installation_error.<locals>.describe_triggerzthe requested packageszOCannot install {} because these package versions have conflicting dependencies.z
The conflict is caused by:z
    z{} {} depends on zThe user requested z

zTo fix this you could try to:
z91. loosen the range of package versions you've specified
z92. remove package versions to allow pip attempt to solve zthe dependency conflict
znResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies)causesr   r   r   r   r   r   r   r   r]   r`   criticalr   rq   format_for_errorrs   sortedr^   r   )rK   rc   causer{   r   req_dispr   r   triggerstriggerr   r   r7   r7   r;   get_installation_error  sr    



	


zFactory.get_installation_error)N)r7   )__name__
__module____qualname__rT   propertyrP   r\   rd   r   r   r   r   r   r   r   r   r   r   r7   r7   r7   r;   r6   M   s"    
$
.L $ 

r6   )Rloggingpip._vendor.packaging.utilsr   pip._internal.exceptionsr   r   r   r   r   r   pip._internal.models.wheelr	   Zpip._internal.req.req_installr
   &pip._internal.utils.compatibility_tagsr   pip._internal.utils.hashesr   pip._internal.utils.miscr   r   r   pip._internal.utils.typingr   pip._internal.utils.virtualenvr   r[   r   
candidatesr   r   r   r   r   found_candidatesr   r   r   r   r   r   typingr   r   r    r!   r"   r#   r$   r%   r&   r'   Z pip._vendor.packaging.specifiersr(   Zpip._vendor.packaging.versionr)   Zpip._vendor.pkg_resourcesr*   Zpip._vendor.resolvelibr+   pip._internal.cacher,   r-   "pip._internal.index.package_finderr.   pip._internal.models.linkr/    pip._internal.operations.preparer0   pip._internal.resolution.baser1   r2   r3   r4   r5   CacheZVersionCandidates	getLoggerr   r`   objectr6   r7   r7   r7   r;   <module>   s>    0
