o
    hA                     @  s(  d dl mZ d dlZd dlZd dlZd dlmZmZmZ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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l-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZB ddlCmDZDmEZEmFZF ddlGmHZHmIZImJZJmKZKmLZLmMZMmNZN ddlOmPZPmQZQ ddlRmSZSmTZTmUZUmVZVmWZW erG dd deZXeYeZZ[edZ\e]e.e\f Z^G d d! d!eZ_G d"d# d#Z`dS )$    )annotationsN)IterableIteratorMappingSequence)TYPE_CHECKINGCallable
NamedTupleProtocol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 ded< ded< dS )ConflictCauser:   requirementr-   parentN__name__
__module____qualname____annotations__ rF   rF   ^/var/www/html/venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.pyr>   H   s   
 r>   Cc                   @  s&   e Zd ZU ded< ded< ded< dS )CollectedRootRequirementszlist[Requirement]requirementsdict[str, Constraint]constraintszdict[str, int]user_requestedNrA   rF   rF   rF   rG   rI   S   s   
 rI   c                   @  s   e Zd Z	ddddZedddZdddZdddd#d$Zdd*d+Zdd1d2Z	dd4d5Z
dd@dAZddEdFZddKdLZddSdTZddYdZZdd^d_ZddbdcZ	ddddedfZddhdiZddldmZddodpZddtduZddzd{ZdddZdS )FactoryNfinderr   preparerr"   make_install_reqr'   wheel_cacheWheelCache | Noneuse_user_siteboolforce_reinstallignore_installedignore_requires_pythonpy_version_infotuple[int, ...] | NonereturnNonec
                 C  s   || _ || _|| _t|	| _|| _|| _|| _|| _i | _	i | _
i | _i | _i | _t | _|s@t }
dd |
jddD | _d S i | _d S )Nc                 S  s   i | ]}|j |qS rF   )canonical_name).0distrF   rF   rG   
<dictcomp>z   s    z$Factory.__init__.<locals>.<dictcomp>F)
local_only)_finderrP   _wheel_cacher5   _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)selfrO   rP   rQ   rR   rT   rV   rW   rX   rY   envrF   rF   rG   __init__Z   s*   


zFactory.__init__c                 C  s   | j S N)rg   rq   rF   rF   rG   rV      s   zFactory.force_reinstalllinkr    c                 C  s>   |j sd S t|j}|| jj rd S |j d}t|)Nz+ is not a supported wheel on this platform.)is_wheelr!   filename	supportedrb   target_pythonget_unsorted_tagsr   )rq   rv   wheelmsgrF   rF   rG   "_fail_if_link_is_unsupported_wheel   s   
z*Factory._fail_if_link_is_unsupported_wheel
comes_frombaser1   extrasfrozenset[str]r   InstallRequirement | Noner3   c                C  sX   t |tdd |D f}z| j| }W |S  ty+   t|||d}|| j|< Y |S w )Nc                 s  s    | ]}t |V  qd S rt   )r   )r^   erF   rF   rG   	<genexpr>       z1Factory._make_extras_candidate.<locals>.<genexpr>r   )id	frozensetrm   KeyErrorr3   )rq   r   r   r   	cache_key	candidaterF   rF   rG   _make_extras_candidate   s   zFactory._make_extras_candidater_   r   templater%   r-   c                 C  sV   z| j |j }W n ty   t||| d}|| j |j< Y nw |s#|S | j|||dS )N)factoryr   )rl   r]   r   r0   r   )rq   r_   r   r   r   rF   rF   rG   _make_candidate_from_dist   s   z!Factory._make_candidate_from_distnameNormalizedName | NoneversionVersion | NoneCandidate | Nonec                 C  s0   |  ||||}|r|d u r|S | j|||dS )Nr   )_make_base_candidate_from_linkr   )rq   rv   r   r   r   r   r   rF   rF   rG   _make_candidate_from_link   s   z!Factory._make_candidate_from_linkBaseCandidate | Nonec              
   C  s  || j v rd S |jrH|| jvrCzt||| ||d| j|< W n% ttfyB } ztjd||ddid || j |< W Y d }~d S d }~ww | j| S || jvrzt	||| ||d| j|< W n# ty~ } ztjd||ddid || j |< W Y d }~d S d }~ww | j| S )N)r   r   r   z3Discarding [blue underline]%s[/]: [yellow]%s[reset]markupT)extra)
ri   editablerk   r2   r   r   loggerinforj   r4   )rq   rv   r   r   r   r   rF   rF   rG   r      sZ   








	z&Factory._make_base_candidate_from_linkireqsSequence[InstallRequirement]	specifierr   hashesr)   prefers_installedincompatible_idsset[int]Iterable[Candidate]c           	        s   |sdS |d j sJ dtj jt  |D ]}|j s#J d|j jM |jddM  t|jO  qd fdd	}d fdd}t|| |S )NrF   r   z)Candidates found on index must be PEP 508F)trust_internetr[   r   c               
     s   j rdS zj } W n
 ty   Y dS w zj| jdds#W dS W n ty6 } zt| |dd}~ww j|  d}t|v rGdS |S )z6Get the candidate for the currently-installed version.NT)prereleases)r_   invalid_exc)r_   r   r   )	rg   rp   r   containsr   r   r   r   r   )installed_distr   r   )r   r   r   rq   r   r   rF   rG   _get_installed_candidate  s.   z@Factory._iter_found_candidates.<locals>._get_installed_candidateIterator[IndexCandidateInfo]c               	   3  s    j jd} | j}tdd |D }ddd	}|}t|D ]}|r)|s.|jjr.q#tjj	|j |j
d
}|j
|fV  q#d S )N)project_namer   r   c                 s  s    | ]}|j jV  qd S rt   )rv   	is_yanked)r^   icanrF   rF   rG   r   6  r   zUFactory._iter_found_candidates.<locals>.iter_index_candidate_infos.<locals>.<genexpr>r   r   r[   rU   c                 S  s<   | D ]}|j dkr dS |j dkrq|jdrq dS dS )Nz===T==z.*F)operatorr   endswith)r   sprF   rF   rG   	is_pinned8  s   

zUFactory._iter_found_candidates.<locals>.iter_index_candidate_infos.<locals>.is_pinned)rv   r   r   r   r   )r   r   r[   rU   )rb   find_best_candidateapplicable_candidatesallreversedrv   r   	functoolspartialr   r   )resulticans
all_yankedr   pinnedr   func)r   r   r   rq   r   r   rF   rG   iter_index_candidate_infos+  s.   
zBFactory._iter_found_candidates.<locals>.iter_index_candidate_infos)r[   r   )r[   r   )reqr   r   r   r   r   r   r7   )	rq   r   r   r   r   r   ireqr   r   rF   )r   r   r   r   rq   r   r   rG   _iter_found_candidates   s&   (zFactory._iter_found_candidatesbase_requirementsIterable[Requirement]Iterator[Candidate]c                 c  sL    |D ] }|  \}}|du rqt|}|dusJ 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_lookupr6   r   )rq   r   r   r   lookup_cand_	base_candrF   rF   rG   #_iter_explicit_candidates_from_baseZ  s   z+Factory._iter_explicit_candidates_from_base
identifierstr
constraintr.   c                 c  sB    |j D ]}| | | 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   )rq   r   r   r   rv   r   rF   rF   rG   !_iter_candidates_from_constraintsp  s   

z)Factory._iter_candidates_from_constraintsrJ   #Mapping[str, Iterable[Requirement]]incompatibilities!Mapping[str, Iterator[Candidate]]is_satisfied_by(Callable[[Requirement, Candidate], bool]c              	     sZ  t  }g } D ]}	|	 \}
}|
d ur||
 |d ur#|| q	tt; t}|jkr]|	| 
|jdt|j |jg D ]}	|	 \}}|d ur\|| qKW d    n1 sgw   Y  |rz|	| j |d d W n
 ty   Y dS w dd |dD |s| | j j|S  fdd|D S )NrF   r   )r   c                 S  s   h | ]}t |qS rF   )r   )r^   crF   rF   rG   	<setcomp>      z*Factory.find_candidates.<locals>.<setcomp>c                 3  sF    | ] t  vr rt fd d D r V  qdS )c                 3  s    | ]}| V  qd S rt   rF   )r^   r   )r   r   rF   rG   r     s    z4Factory.find_candidates.<locals>.<genexpr>.<genexpr>N)r   r   r   )r^   r   r   incompat_idsr   rJ   )r   rG   r     s    z*Factory.find_candidates.<locals>.<genexpr>)setr   addappend
contextlibsuppressr   r*   r   updater   getr   r   r   r   r   r   r   )rq   r   rJ   r   r   r   r   explicit_candidatesr   r   candr   parsed_requirementr   rF   r   rG   find_candidates  s`   




zFactory.find_candidatesr   requested_extrasIterable[str]Iterator[Requirement]c                 c  s    | |std|j|j dS |js,|jr%|jdur%|jjr%t	|V  t
|V  dS | |j | j|j|jr=t|n||jrFt|jnddd}|du rb|jsX| j|j tt|jV  dS | |V  |jrz| | |t|jV  dS 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   markersrv   r   r   r   r<   r;   r~   r   r#   r   ri   r=   make_requirement_from_candidater   r   )rq   r   r   r   rF   rF   rG   #_make_requirements_from_install_req  s8   


z+Factory._make_requirements_from_install_req
root_ireqslist[InstallRequirement]rI   c           	      C  s   t g i i }t|D ]_\}}|jrDt|}|rt|| s q
|js'J dt|j}||jv r;|j|  |M  < q
t	
||j|< q
t| j|dd}|sPq
|d }|jrc|j|jvrc||j|j< |j| q
|jjdd d |S )NzConstraint must be namedrF   )r   r   c                 S  s   | j | jkS rt   )r   r   )rrF   rF   rG   <lambda>.  s    z3Factory.collect_root_requirements.<locals>.<lambda>)key)rI   	enumerater   r&   r   r   r   r   rL   r.   	from_ireqlistr   user_suppliedrM   rJ   extendsort)	rq   r   	collectedir   problemr   reqsr   rF   rF   rG   collect_root_requirements  s6   

	z!Factory.collect_root_requirementsr   r9   c                 C  s   t |S rt   )r9   )rq   r   rF   rF   rG   r   1  s   z'Factory.make_requirement_from_candidaterF   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.
        )re   r   )rq   r   r   r   r   rF   rF   rG   make_requirements_from_spec6  s   z#Factory.make_requirements_from_specRequirement | Nonec                 C  s"   | j rd S t|sd S t|| jS rt   )rh   r   r:   rd   )rq   r   rF   rF   rG    make_requires_python_requirementH  s
   z(Factory.make_requires_python_requirement
str | NoneCacheEntry | Nonec                 C  s"   | j du 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)rv   package_namesupported_tags)rc   get_cache_entryrn   )rq   rv   r   rF   rF   rG   get_wheel_cache_entryS  s   
	zFactory.get_wheel_cache_entryBaseDistribution | Nonec                 C  sZ   | j |j}|d u rd S | js|S |jr|S t r+|jr+d|j d|j }t	|d S )NzNWill not install to the user site because it will lack sys.path precedence to z in )
rp   r   r   rf   in_usersiter+   in_site_packagesraw_namelocationr   )rq   r   r_   messagerF   rF   rG   get_dist_to_uninstalld  s    zFactory.get_dist_to_uninstallcausesSequence[ConflictCause]r   c                 C  s   |sJ d| j j}t|dkr+t|d jj}d|d jjd| d|}t|S d| d}|D ]}|j	 }t|jj}|d	|d
| d7 }q3t|S )Nz,Requires-Python error reported with no causer,   r   zPackage z requires a different Python: z not in z%Packages require a different Python. z not in:
z (required by ))
rd   r   lenr   r?   r   r@   r   r   format_for_error)rq   r  r   r   r  causepackagerF   rF   rG   _report_requires_python_error  s"   
z%Factory._report_requires_python_errorr   r/   r@   r   c                 C  s  |d u r	t |}n	| d|j d}| j|j}| j }t }t }|D ]}|jr/|jjnd}	|	r:|	|j
 q&|	|j
 q&dd t|D }
dd t|D }|r`tdd|p^d	 |rmtd
d|pkd	 td|d|
pwd	 t |dkrtd td| S )Nz (from r  Fc                 S     g | ]}t |qS rF   r   r^   vrF   rF   rG   
<listcomp>  r   z?Factory._report_single_requirement_conflict.<locals>.<listcomp>c                 S  r  rF   r  r  rF   rF   rG   r    r   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 )r   r   rb   find_all_candidatesr   requires_python_skipped_reasonsr   rv   r   r   r   sortedr   criticaljoinr   r   )rq   r   r@   req_dispcandsskipped_by_requires_pythonversions_setyanked_versions_setr   r   versionsyanked_versionsrF   rF   rG   #_report_single_requirement_conflict  sD   

z+Factory._report_single_requirement_conflictr   ,ResolutionImpossible[Requirement, Candidate]rL   rK   r   c                   s  |j sJ d fdd|j D }|r td|S t|j dkr6tt|j \}}|j|vr6 ||S dd
d}d dd}t }|j D ]\}}|d u rS|	 }	n||}	|
|	 qF|rf|t|}
nd}
d|
 d}t| d}t }|j D ],\}}|j|v r|
|j |d }|r||j d|j d }n|d }||	  }q{|D ]}|| j}|d| | 7 }q|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 rF   )
isinstancer?   r:   r   rd   )r^   r  ru   rF   rG   r    s    
z2Factory.get_installation_error.<locals>.<listcomp>r  r,   parts	list[str]r[   r   c                 S  s2   t | dkr
| d S d| d d d | d  S )Nr,   r   r  z and )r  r"  )r-  rF   rF   rG   	text_join  s   z1Factory.get_installation_error.<locals>.text_joinr@   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%   r   )r@   r   rF   rF   rG   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   )r  r  r   r  nextiterr   r*  r   r  r   r   r   r!  r   r   r   r   )rq   r   rL   requires_python_causesr   r@   r0  r2  triggerstriggerr   r}   relevant_constraintsr   specrF   ru   rG   get_installation_error  sn   
	








	zFactory.get_installation_errorrt   )rO   r   rP   r"   rQ   r'   rR   rS   rT   rU   rV   rU   rW   rU   rX   rU   rY   rZ   r[   r\   )r[   rU   )rv   r    r[   r\   )r   r1   r   r   r   r   r[   r3   )r_   r   r   r   r   r%   r[   r-   )rv   r    r   r   r   r%   r   r   r   r   r[   r   )
rv   r    r   r%   r   r   r   r   r[   r   )r   r   r   r   r   r)   r   rU   r   r   r[   r   )r   r   r   r   r[   r   )r   r   r   r.   r   r%   r[   r   )r   r   rJ   r   r   r   r   r.   r   rU   r   r   r[   r   )r   r%   r   r   r[   r   )r   r   r[   rI   )r   r-   r[   r9   )rF   )r   r   r   r   r   r   r[   r   )r   r   r[   r   )rv   r    r   r  r[   r  )r   r-   r[   r  )r  r  r[   r   )r   r/   r@   r   r[   r   )r   r+  rL   rK   r[   r   )rB   rC   rD   rs   propertyrV   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r*  r;  rF   rF   rF   rG   rN   Y   s4    '




9
f


L
5
*	




4rN   )a
__future__r   r   r   loggingcollections.abcr   r   r   r   typingr   r   r	   r
   r   r   "pip._vendor.packaging.requirementsr    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.virtualenvr+   r   r-   r.   r/   
candidatesr0   r1   r2   r3   r4   r5   r6   found_candidatesr7   r8   rJ   r9   r:   r;   r<   r=   r>   	getLoggerrB   r   rH   dictCacherI   rN   rF   rF   rF   rG   <module>   sH     	$	$	
