
    iQ                       d dl mZ d dlZd dlZd dlmZ d dl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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!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, erddl-m.Z.  ej^                  e0      Z1e	d   Z2 e
ed      Z3d%dZ4	 d&	 	 	 	 	 	 	 d'dZ5	 	 	 	 	 	 d(dZ6	 	 	 	 	 	 d)dZ7 G d de*      Z8 G d de8      Z9 G d de8      Z: G d d e*      Z; G d! d"e*      Z< G d# d$e*      Z=y)*    )annotationsN)Iterable)TYPE_CHECKINGAnyUnioncast)InvalidRequirement)NormalizedNamecanonicalize_name)Version)FailedToPrepareCandidate	HashErrorInstallationSubprocessErrorInvalidInstalledPackageMetadataInconsistentMetadataInvalid)BaseDistribution)Linklinks_equivalent)Wheel)install_req_from_editableinstall_req_from_line)InstallRequirement)direct_url_from_link)normalize_version_info   )	CandidateRequirementformat_name)Factory)AlreadyInstalledCandidateEditableCandidateLinkCandidatez<Python from Requires-Python>c                B    t         t        t        f}t        | |      r| S y)z%The runtime version of BaseCandidate.N)r!   r"   r#   
isinstance)	candidatebase_candidate_classess     a/root/searxng-venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.pyas_base_candidater)   0   s+     	"
 )34    c           	        |j                   rJ d       |4|j                  r(|j                  r|j                  j                   d| }n.|j                  rt	        |j                        }n| j
                  }t        ||j                  |j                  |j                  |j                  |j                  |j                        }|j                  |_        | |_        |j                  |_        |S )Nztemplate is editable==user_supplied
comes_fromisolated
constrainthash_optionsconfig_settings)editablereqr2   namestrurlr   r.   r/   r0   r1   r3   original_linklinkextras)r:   templateversionlineireqs        r(   make_install_req_from_linkr@   <   s    
   8"88 x||0E0E ,,##$Bwi0	8<< xx ,,&&""&&** 00D "//DDI//DKKr*   c           
     h   |j                   sJ d       |j                  r|j                   d| j                   }n| j                  }t        ||j                  |j
                  |j                  |j                  |j                  |j                  |j                        }|j                  |_        |S )Nztemplate not editable @ )r.   r/   r0   r1   permit_editable_wheelsr2   r3   )r4   r6   r8   r   r.   r/   r0   r1   rC   r2   r3   r;   )r:   r<   
req_stringr?   s       r(   make_install_req_from_editablerE   Z   s     555}} c$((4
XX
$,,&&""&&'>>** 00	D //DKKr*   c           	        |j                   rt        |j                         }nM|j                  r&| j                   d|j                  j                   }n| j                   d| j
                   }t        ||j                  |j                  |j                  |j                  |j                  |j                        }| |_        |S )NrB   r,   r-   )r5   r7   r:   canonical_namer8   r=   r   r.   r/   r0   r1   r2   r3   satisfied_by)distr<   r>   r?   s       r(   _make_install_req_from_distrJ   p   s     ||8<< 	%%&c(--*;*;)<=%%&b7 ,,&&""&&** 00D DKr*   c                      e Zd ZU dZded<   dZ	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZdd	Z	dd
Z
edd       Zedd       Ze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y)!"_InstallRequirementBackedCandidatea  A candidate backed by an ``InstallRequirement``.

    This represents a package request with the target not being already
    in the environment, and needs to be fetched and installed. The backing
    ``InstallRequirement`` is responsible for most of the leg work; this
    class exposes appropriate information to the resolver.

    :param link: The link passed to the ``InstallRequirement``. The backing
        ``InstallRequirement`` will use this link to fetch the distribution.
    :param source_link: The link this candidate "originates" from. This is
        different from ``link`` when the link is found in the wheel cache.
        ``link`` would point to the wheel cache, while this points to the
        found remote link (e.g. from pypi.org).
    r   rI   FNc                    || _         || _        || _        || _        || _        || _        | j                         | _        d | _        y N)	_link_source_link_factory_ireq_name_version_preparerI   _hash)selfr:   source_linkr?   factoryr6   r=   s          r(   __init__z+_InstallRequirementBackedCandidate.__init__   sC     
'

MMO	!%
r*   c                8    | j                    d| j                   S )N r6   r=   rW   s    r(   __str__z*_InstallRequirementBackedCandidate.__str__   s    ))Adll^,,r*   c                `    | j                   j                   dt        | j                        dS N())	__class____name__r7   rO   r^   s    r(   __repr__z+_InstallRequirementBackedCandidate.__repr__   s)    ..))*!C

O+>a@@r*   c                    | j                   | j                   S t        | j                  | j                  f      | _         | j                   S rN   )rV   hashrd   rO   r^   s    r(   __hash__z+_InstallRequirementBackedCandidate.__hash__   s9    ::!::4>>4::67
zzr*   c                p    t        || j                        r t        | j                  |j                        S yNF)r%   rd   r   rO   rW   others     r(   __eq__z)_InstallRequirementBackedCandidate.__eq__   s(    eT^^,#DJJ<<r*   c                    | j                   S rN   )rP   r^   s    r(   rX   z._InstallRequirementBackedCandidate.source_link          r*   c                h    | j                   | j                  j                  | _         | j                   S z:The normalised name of the project the candidate refers to)rS   rI   rG   r^   s    r(   project_namez/_InstallRequirementBackedCandidate.project_name   s)     ::11DJzzr*   c                    | j                   S rN   rs   r^   s    r(   r6   z'_InstallRequirementBackedCandidate.name   rp   r*   c                h    | j                   | j                  j                  | _         | j                   S rN   rT   rI   r=   r^   s    r(   r=   z*_InstallRequirementBackedCandidate.version   '    ==  II--DM}}r*   c                    | j                    d| j                   d| j                  rdnd | j                  j                  r| j                  j
                   dS | j                   dS )Nr\   z (from z	editable  rc   )r6   r=   is_editablerO   is_file	file_pathr^   s    r(   format_for_errorz3_InstallRequirementBackedCandidate.format_for_error   sn    yyk4<<. )$($4$4["='+zz'9'9tzz##J!M	
 @DzzJ!M	
r*   c                    t        d      )NzOverride in subclass)NotImplementedErrorr^   s    r(   _prepare_distributionz8_InstallRequirementBackedCandidate._prepare_distribution   s    !"899r*   c                0   | j                   E| j                   |j                  k7  r,t        | j                  d| j                   |j                        | j                  W| j                  |j
                  k7  r>t        | j                  dt        | j                        t        |j
                              	 t        |j                  t        |j                                            y# t        $ r$}t        | j                  t        |            d}~ww xY w)z:Check for consistency of project name and version of dist.Nr6   r=   )rS   rG   r   rR   rT   r=   r7   listiter_dependenciesiter_provided_extrasr	   r   )rW   rI   es      r(   _check_metadata_consistencyz>_InstallRequirementBackedCandidate._check_metadata_consistency   s    ::!djjD4G4G&G&



##	  ==$$,,)F&

DMM"DLL!	 	6''T-F-F-H(IJK! 	6!$**c!f55	6s   61C( (	D1DDc                   	 | j                         }| j                  |       |S # t        $ r}| j                  |_         d }~wt        $ r}t        | j                  j                  t              r%| j                  j                  j                         }n| j                  j                  }|d}t        | j                  j                  xs t        | j                        ||j                        d }~ww xY w)Nzdirectly requested)package_namerequirement_chainfailed_step)r   r   rR   r5   r   r%   r/   r   	from_pathr   r6   r7   rO   command_descriptionr   )rW   rI   r   excrequest_chains        r(   rU   z+_InstallRequirementBackedCandidate._prepare   s    	--/D, 	((.-  	 JJAE* 	$**//1CD $

 5 5 ? ? A $

 5 5$ 4*!ZZ__?DJJ"/33 	s!   % 	C7A  C7B&C22C7c              #  *  K   | j                   j                  | j                  j                         |r| j                  j	                         nd}|D ]9  }| j                   j                  t        |      | j                        E d {    ; y 7 wN )rQ    make_requires_python_requirementrI   requires_pythonr   make_requirements_from_specr7   rR   )rW   with_requiresrequiresrs       r(   r   z4_InstallRequirementBackedCandidate.iter_dependencies  ss      mm<<TYY=V=VWW4A499..0r 	UA}}@@QTTT	UTs   BB	B
Bc                    | j                   S rN   )rR   r^   s    r(   get_install_requirementz:_InstallRequirementBackedCandidate.get_install_requirement  s    zzr*   NN)r:   r   rX   r   r?   r   rY   r    r6   NormalizedName | Noner=   Version | NonereturnNoner   r7   r   intrm   r   r   boolr   zLink | Noner   r
   r   r   r   r   )rI   r   r   r   r   r   r   zIterable[Requirement | None]r   InstallRequirement | None)re   
__module____qualname____doc____annotations__is_installedrZ   r_   rf   ri   rn   propertyrX   rs   r6   r=   r~   r   r   rU   r   r   r   r*   r(   rL   rL      s     L '+"&&& & !	&
 & $&  & 
&$-A
 ! !   ! !  

:606Ur*   rL   c                  H     e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 	 	 d fdZddZ xZS )r#   Fc                H   |}|j                  ||      }|,t        j                  d|j                         |j                  }t	        |||      }|j                  |k(  sJ |j                  j
                  r~|j                  j                  sht        |j                  j                        }	|	j                  }
||
k(  sJ |d|
d       |)t        |	j                        }||k(  sJ |d|d|        ||j                  j
                  sJ |j                  j                  sJ |j                  r|j                  |j                  u r||_        |j                  |j                  |_        nt#        ||j                        |_        t$        | M  ||||||       y )NzUsing cached wheel link: %sr=   z != z
 for wheelz for wheel )link_is_in_wheel_cacher:   rX   r?   rY   r6   r=   )get_wheel_cache_entryloggerdebugr:   r@   is_wheelr|   r   filenamer6   r   r=   
persistentr9   cached_wheel_source_linkorigindownload_infor   superrZ   )rW   r:   r<   rY   r6   r=   rX   cache_entryr?   wheel
wheel_namewheel_versionrd   s               r(   rZ   zLinkCandidate.__init__  s    33KF"LL68H8HI##D)$'JyyD   99dii&7&7$)),,-EJ:%N$j^:'NN%" ' 6},H[]$5[GH, "99%%%%99$$$$%%(--8;Q;Q*Q0;-!!-%0%7%7" &:8N8N&" 	# 	 	
r*   c                h    | j                   j                  }|j                  | j                  d      S )NT)parallel_builds)rQ   preparerprepare_linked_requirementrR   )rW   r   s     r(   r   z#LinkCandidate._prepare_distributionO  s+    ==))224::t2TTr*   r   r:   r   r<   r   rY   r    r6   r   r=   r   r   r   r   re   r   r   r{   rZ   r   __classcell__rd   s   @r(   r#   r#     sV    K '+"&/
/
 %/
 	/

 $/
  /
 
/
bUr*   r#   c                  H     e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 	 	 d fdZddZ xZS )r"   Tc                D    t         |   ||t        ||      |||       y )Nr   )r   rZ   rE   )rW   r:   r<   rY   r6   r=   rd   s         r(   rZ   zEditableCandidate.__init__W  s0     	/h? 	 	
r*   c                `    | j                   j                  j                  | j                        S rN   )rQ   r   prepare_editable_requirementrR   r^   s    r(   r   z'EditableCandidate._prepare_distributionh  s!    }}%%BB4::NNr*   r   r   r   r   r   s   @r(   r"   r"   T  sU    K '+"&

 %
 	

 $
  
 

"Or*   r"   c                      e Zd ZdZdZ	 	 	 	 	 	 	 	 ddZddZddZddZddZ	e
dd       Ze
dd	       Ze
dd
       Ze
dd       ZddZddZddZy)r!   TNc                    || _         t        ||      | _        || _        d | _        d}|j
                  j                  | j                  |       y )Nzalready satisfied)rI   rJ   rR   rQ   rT   r   prepare_installed_requirement)rW   rI   r<   rY   skip_reasons        r(   rZ   z"AlreadyInstalledCandidate.__init__p  sH     	0x@
 *66tzz;Or*   c                ,    t        | j                        S rN   )r7   rI   r^   s    r(   r_   z!AlreadyInstalledCandidate.__str__  s    499~r*   c                N    | j                   j                   d| j                  dS ra   )rd   re   rI   r^   s    r(   rf   z"AlreadyInstalledCandidate.__repr__  s$    ..))*!DII=::r*   c                    t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S rN   )r%   r!   NotImplementedr6   r=   rl   s     r(   rn   z AlreadyInstalledCandidate.__eq__  s8    %!:;!!yyEJJ&H4<<5==+HHr*   c                D    t        | j                  | j                  f      S rN   )rh   r6   r=   r^   s    r(   ri   z"AlreadyInstalledCandidate.__hash__  s    TYY-..r*   c                .    | j                   j                  S rN   )rI   rG   r^   s    r(   rs   z&AlreadyInstalledCandidate.project_name  s    yy'''r*   c                    | j                   S rN   ru   r^   s    r(   r6   zAlreadyInstalledCandidate.name  rp   r*   c                h    | j                   | j                  j                  | _         | j                   S rN   rw   r^   s    r(   r=   z!AlreadyInstalledCandidate.version  rx   r*   c                .    | j                   j                  S rN   )rI   r4   r^   s    r(   r{   z%AlreadyInstalledCandidate.is_editable  s    yy!!!r*   c                :    | j                    d| j                   dS )Nr\   z (Installed)r]   r^   s    r(   r~   z*AlreadyInstalledCandidate.format_for_error  s    ))Adll^<88r*   c              #    K   |sy 	 | j                   j                         D ]9  }| j                  j                  t	        |      | j
                        E d {    ; y 7 # t        $ r}t        | j                   |      d d }~ww xY ww)N)rI   invalid_exc)rI   r   rQ   r   r7   rR   r	   r   )rW   r   r   r   s       r(   r   z+AlreadyInstalledCandidate.iter_dependencies  sz     	UYY002 Y==DDSVTZZXXXYX! 	U)tyycJPTT	Us;   B	AA  AA  B	A   	B)BBB	c                     y rN   r   r^   s    r(   r   z1AlreadyInstalledCandidate.get_install_requirement      r*   )rI   r   r<   r   rY   r    r   r   r   )rm   objectr   r   r   r   r   r   r   r   r   )re   r   r   r   rX   rZ   r_   rf   rn   ri   r   rs   r6   r=   r{   r~   r   r   r   r*   r(   r!   r!   l  s    LKPP %P 	P
 
P$;I
/ ( ( ! !  
 " "9Ur*   r!   c                      e Zd ZdZdd	 	 	 	 	 	 	 ddZddZddZddZddZe	dd	       Z
e	dd
       Ze	dd       ZddZe	dd       Ze	dd       Ze	dd       ZddZddZy)ExtrasCandidatea  A candidate that has 'extras', indicating additional dependencies.

    Requirements can be for a project with dependencies, something like
    foo[extra].  The extras don't affect the project/version being installed
    directly, but indicate that we need additional dependencies. We model that
    by having an artificial ExtrasCandidate that wraps the "base" candidate.

    The ExtrasCandidate differs from the base in the following ways:

    1. It has a unique name, of the form foo[extra]. This causes the resolver
       to treat it as a separate node in the dependency graph.
    2. When we're getting the candidate's dependencies,
       a) We specify that we want the extra dependencies as well.
       b) We add a dependency on the base candidate.
          See below for why this is needed.
    3. We return None for the underlying InstallRequirement, as the base
       candidate will provide it, and we don't want to end up with duplicates.

    The dependency on the base candidate is needed so that the resolver can't
    decide that it should recommend foo[extra1] version 1.0 and foo[extra2]
    version 2.0. Having those candidates depend on foo=1.0 and foo=2.0
    respectively forces the resolver to recognise that this is a conflict.
    N)r/   c                   || _         t        d |D              | _        ||| _        y| j                   j                  | _        y)a  
        :param comes_from: the InstallRequirement that led to this candidate if it
            differs from the base's InstallRequirement. This will often be the
            case in the sense that this candidate's requirement has the extras
            while the base's does not. Unlike the InstallRequirement backed
            candidates, this requirement is used solely for reporting purposes,
            it does not do any leg work.
        c              3  2   K   | ]  }t        |        y wrN   )r   ).0r   s     r(   	<genexpr>z+ExtrasCandidate.__init__.<locals>.<genexpr>  s     E 1! 4E   N)base	frozensetr;   rR   _comes_from)rW   r   r;   r/   s       r(   rZ   zExtrasCandidate.__init__  s9     	EfEE)3)?:TYY__r*   c                    t        | j                        j                  dd      \  }}dj                  |dj	                  | j
                        |      S )Nr\   r   z	{}[{}] {},)r7   r   splitformatjoinr;   )rW   r6   rests      r(   r_   zExtrasCandidate.__str__  sB    ^))#q1
d!!$(=tDDr*   c                h    | j                   j                   d| j                  d| j                  dS )Nz(base=z	, extras=rc   )rd   re   r   r;   r^   s    r(   rf   zExtrasCandidate.__repr__  s/    ..))*&Yt{{oUVWWr*   c                D    t        | j                  | j                  f      S rN   )rh   r   r;   r^   s    r(   ri   zExtrasCandidate.__hash__  s    TYY,--r*   c                    t        || j                        r4| j                  |j                  k(  xr | j                  |j                  k(  S yrk   )r%   rd   r   r;   rl   s     r(   rn   zExtrasCandidate.__eq__  s8    eT^^,99

*Jt{{ell/JJr*   c                .    | j                   j                  S rN   )r   rs   r^   s    r(   rs   zExtrasCandidate.project_name      yy%%%r*   c                V    t        | j                  j                  | j                        S rr   )r   r   rs   r;   r^   s    r(   r6   zExtrasCandidate.name  s     499114;;??r*   c                .    | j                   j                  S rN   )r   r=   r^   s    r(   r=   zExtrasCandidate.version  s    yy   r*   c                    dj                  | j                  j                         dj                  t	        | j
                                    S )Nz{} [{}]z, )r   r   r~   r   sortedr;   r^   s    r(   r~   z ExtrasCandidate.format_for_error  s9    II&&($))F4;;4G*H
 	
r*   c                .    | j                   j                  S rN   )r   r   r^   s    r(   r   zExtrasCandidate.is_installed   r   r*   c                .    | j                   j                  S rN   )r   r{   r^   s    r(   r{   zExtrasCandidate.is_editable      yy$$$r*   c                .    | j                   j                  S rN   )r   rX   r^   s    r(   rX   zExtrasCandidate.source_link  r   r*   c              #    K   | j                   j                  }|j                  | j                          |sy | j                  j	                  | j                   j
                  j                               }| j                  j                  | j                   j
                  j                               }t        |      D ]8  }t        j                  d| j                   j                  | j                  |       : | j                   j
                  j                  |      D ]0  }|j                  t        |      | j                   |      E d {    2 y 7 w)Nz%%s %s does not provide the extra '%s')r   rQ   make_requirement_from_candidater;   intersectionrI   r   
differencer   r   warningr6   r=   r   r   r7   r   )rW   r   rY   valid_extrasinvalid_extrasextrar   s          r(   r   z!ExtrasCandidate.iter_dependencies  s
    ))$$ 55dii@@ {{//		0S0S0UV//		0S0S0UVN+ 	ENN7				 11,? 	A::A    	s   EE
EEc                     y rN   r   r^   s    r(   r   z'ExtrasCandidate.get_install_requirement(  s     r*   )r   BaseCandidater;   zfrozenset[str]r/   r   r   r   r   r   r   r   r   r   r   r   r   )re   r   r   r   rZ   r_   rf   ri   rn   r   rs   r6   r=   r~   r   r{   rX   r   r   r   r*   r(   r   r     s    : 15UU U
 .U 
U&EX.
 & & @ @ ! !

 & & % % % %8r*   r   c                  z    e Zd ZdZdZddZddZddZedd       Z	edd       Z
edd       Zdd	Zdd
ZddZy)RequiresPythonCandidateFNc                    |t        |      }nt        j                  d d }t        dj	                  d |D                    | _        y )N   .c              3  2   K   | ]  }t        |        y wrN   )r7   )r   cs     r(   r   z3RequiresPythonCandidate.__init__.<locals>.<genexpr>8  s     (FAQ(Fr   )r   sysversion_infor   r   rT   )rW   py_version_infor  s      r(   rZ   z RequiresPythonCandidate.__init__3  s?    &1/BL++BQ/L(F(F FGr*   c                     d| j                    S NzPython rT   r^   s    r(   r_   zRequiresPythonCandidate.__str__>  s    ((r*   c                N    | j                   j                   d| j                  dS ra   )rd   re   rT   r^   s    r(   rf   z RequiresPythonCandidate.__repr__A  s%    ..))*!DMM+<A>>r*   c                    t         S rN   REQUIRES_PYTHON_IDENTIFIERr^   s    r(   rs   z$RequiresPythonCandidate.project_nameD      ))r*   c                    t         S rN   r  r^   s    r(   r6   zRequiresPythonCandidate.nameH  r  r*   c                    | j                   S rN   r  r^   s    r(   r=   zRequiresPythonCandidate.versionL  s    }}r*   c                     d| j                    S r  r   r^   s    r(   r~   z(RequiresPythonCandidate.format_for_errorP  s    ''r*   c                     yr   r   )rW   r   s     r(   r   z)RequiresPythonCandidate.iter_dependenciesS  s    r*   c                     y rN   r   r^   s    r(   r   z/RequiresPythonCandidate.get_install_requirementV  r   r*   )r  ztuple[int, ...] | Noner   r   r   r   r   r   r   )re   r   r   r   rX   rZ   r_   rf   r   rs   r6   r=   r~   r   r   r   r*   r(   r  r  /  sg    LKH)? * * * *  (r*   r  )r&   r   r   zBaseCandidate | NonerN   )r:   r   r<   r   r=   r   r   r   )r:   r   r<   r   r   r   )rI   r   r<   r   r   r   )>
__future__r   loggingr  collections.abcr   typingr   r   r   r   "pip._vendor.packaging.requirementsr	   pip._vendor.packaging.utilsr
   r   pip._vendor.packaging.versionr   pip._internal.exceptionsr   r   r   r   r   r   pip._internal.metadatar   pip._internal.models.linkr   r   pip._internal.models.wheelr   pip._internal.req.constructorsr   r   pip._internal.req.req_installr   &pip._internal.utils.direct_url_helpersr   pip._internal.utils.miscr   r   r   r   r   rY   r    	getLoggerre   r   r  r  r)   r@   rE   rJ   rL   r#   r"   r!   r   r  r   r*   r(   <module>r3     sG   "  
 $ 2 2 A I 1  4 < , = G ; 5 5 			8	$ ".2QR 	 #
   	<
,,
&8,R Rj6U6 6UrO: O0D	 DNyi yx(i (r*   