
    vgӓ              	          d Z ddlZ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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mZ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/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> erddl?m@Z@ g dZA e2eB      ZCeed   eeDeEf   f   ZFeeDeDeDeeeD   eFf   ZG	 d6de&deeDeDeDf   deHd eHfd!ZI G d" d#ej                        ZK G d$ d%      ZLd&e
e"   d'ee6   d(eEd e
e"   fd)ZM G d* d+      ZN G d, d-      ZO G d. d/      ZP G d0 d1      ZQd2eEd3eEd eDfd4ZRd2eEd3eEd eeE   fd5ZSy)7z!Routines related to PyPI, indexes    N)TYPE_CHECKING	FrozenSetIterableListOptionalSetTupleUnion)
specifiers)Tag)canonicalize_name)_BaseVersion)parse)BestVersionAlreadyInstalledDistributionNotFoundInvalidWheelFilenameUnsupportedWheel)LinkCollectorparse_links)InstallationCandidate)FormatControl)Link)SearchScope)SelectionPreferences)TargetPython)Wheel)InstallRequirement)	getLogger)WHEEL_EXTENSION)Hashes)
indent_log)build_netloc)check_requires_python)SUPPORTED_EXTENSIONS)	TypeGuard)r   BestCandidateResultPackageFinder linkversion_infoignore_requires_pythonreturnc                 x   	 t        | j                  |      }|sfdj                  t        t        |            }|s#t
        j                  d|| j                  |        yt
        j                  d|| j                  |        y# t        j                  $ r$ t
        j                  d| j                  |        Y yw xY w)aa  
    Return whether the given Python version is compatible with a link's
    "Requires-Python" value.

    :param version_info: A 3-tuple of ints representing the Python
        major-minor-micro version to check.
    :param ignore_requires_python: Whether to ignore the "Requires-Python"
        value if the given Python version isn't compatible.
    )r*   .z4Link requires a different Python (%s not in: %r): %sFzBIgnoring failed Requires-Python check (%s not in: %r) for link: %sz2Ignoring invalid Requires-Python (%r) for link: %sT)
r#   requires_pythonjoinmapstrloggerverbosedebugr   InvalidSpecifier)r)   r*   r+   is_compatibleversions        g/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/pip/_internal/index/package_finder.py_check_link_requires_pythonr:   3   s    -  %
 hhs356G)J((	 LLT$$	 3 && 
@  	
0 3
s   B 4B98B9c                       e Zd Z ej                         Z ej                         Z ej                         Z ej                         Z ej                         Z	 ej                         Z
 ej                         Zy)LinkTypeN)__name__
__module____qualname__enumauto	candidatedifferent_projectyankedformat_unsupportedformat_invalidplatform_mismatchrequires_python_mismatchr(       r9   r<   r<   b   sa    		I!		TYY[F"TYY[N!		(tyy{rI   r<   c                       e Zd ZdZ ej
                  d      Z	 ddededee   de	de
d	ee
   d
dfdZded
eeef   fdZy)LinkEvaluatorzD
    Responsible for evaluating links for a particular project.
    z-py([123]\.?[0-9]?)$Nproject_namecanonical_nameformatstarget_pythonallow_yankedr+   r,   c                 `    |d}|| _         || _        || _        || _        || _        || _        y)a  
        :param project_name: The user supplied package name.
        :param canonical_name: The canonical package name.
        :param formats: The formats allowed for this package. Should be a set
            with 'binary' or 'source' or both in it.
        :param target_python: The target Python interpreter to use when
            evaluating link compatibility. This is used, for example, to
            check wheel compatibility, as well as when checking the Python
            version, e.g. the Python version embedded in a link filename
            (or egg fragment) and against an HTML link's optional PEP 503
            "data-requires-python" attribute.
        :param allow_yanked: Whether files marked as yanked (in the sense
            of PEP 592) are permitted to be candidates for install.
        :param ignore_requires_python: Whether to ignore incompatible
            PEP 503 "data-requires-python" values in HTML links. Defaults
            to False.
        NF)_allow_yanked_canonical_name_ignore_requires_python_formats_target_pythonrL   )selfrL   rM   rN   rO   rP   r+   s          r9   __init__zLinkEvaluator.__init__x   s?    4 ")%*")-'=$+(rI   r)   c                    d}|j                   r1| j                  s%|j                  xs d}t        j                  d| fS |j
                  r|j
                  }|j                  }nr|j                         \  }}|st        j                  dfS |t        vrt        j                  d| fS d| j                  vr*|t        k(  r!d| j                   }t        j                  |fS d|j                  v r|d	k(  rt        j                  d
fS |t        k(  r	 t        |j                        }t%        |j&                        | j(                  k7  r"d| j                   d}t        j*                  |fS | j,                  j/                         }|j1                  |      s7dj3                  |j5                               }d| d}t        j6                  |fS |j8                  }d| j                  vr*|t        k7  r!d| j                   }t        j                  |fS |st;        || j(                        }|s!d| j                   }t        j"                  |fS | j<                  j?                  |      }	|	rO|d|	jA                          }|	jC                  d      }
|
| j,                  jD                  k7  rt        j6                  dfS tG        || j,                  jH                  | jJ                        }|s#| d|jL                   }t        jN                  |fS tP        jS                  d||       t        jT                  |fS # t         $ r t        j"                  dfcY S w xY w)a  
        Determine whether a link is a candidate for installation.

        :return: A tuple (result, detail), where *result* is an enum
            representing whether the evaluation found a candidate, or the reason
            why one is not found. If a candidate is found, *detail* will be the
            candidate's version string; if one is not found, it contains the
            reason the link fails to qualify.
        Nz<none given>zyanked for reason: z
not a filezunsupported archive format: binaryzNo binaries permitted for macosx10z.zipzmacosx10 onezinvalid wheel filenamezwrong project name (not ), znone of the wheel's tags (zB) are compatible (run pip debug --verbose to show compatible tags)sourcezNo sources permitted for zMissing project version for    zPython version is incorrect)r*   r+   z Requires-Python zFound link %s, version: %s)+	is_yankedrR   yanked_reasonr<   rD   egg_fragmentextsplitextrE   r$   rU   r   rL   pathr   filenamer   rF   r   namerS   rC   rV   get_unsorted_tags	supportedr0   get_formatted_file_tagsrG   r8   _extract_version_from_fragment_py_version_researchstartgroup
py_versionr:   py_version_inforT   r/   rH   r3   r5   rB   )rW   r)   r8   reasonegg_inforc   wheelsupported_tags	file_tagsmatchrp   supports_pythons               r9   evaluate_linkzLinkEvaluator.evaluate_link   sE    >>$"4"4''9>FOO':6(%CDD((H((C MMOMHc 33\BB..//23%8  t}},1G5d6G6G5HI 33V<<TYY&3&= 33^DDo%!$--0E %UZZ0D4H4HH78I8I7J!LF$66??!%!4!4!F!F!H~6 !%		%*G*G*I JI4YK @L M  %66??-- 4==(SO-C01B1B0CDF//884$$G 3D4E4E3FGF++V44##**73o.GQJT00;;;..1 
 6,,<<#'#?#?

 y 1$2F2F1GHF55v>>14A""G,,s ,  //0 s   L1 1MMN)r=   r>   r?   __doc__recompilerl   r2   r   r   boolr   rX   r   r	   r<   ry   r(   rI   r9   rK   rK   l   s      RZZ 78N 26#)#) #) 3	#)
 $#) #) !)#) 
#)J\-$ \-53+? \-rI   rK   
candidateshashesrL   c           
      L   |s+t         j                  dt        |       |       t        |       S g }g }d}| D ]V  }|j                  }|j
                  sn*|j                  |      r|dz  }n|j                  |       F|j                  |       X |r|}nt        |       }t        |      t        |       k(  rd}	n1dj                  t        |      dj                  d |D                    }	t         j                  d	t        |       ||j                  |t        |      |z
  |	       |S )
a  
    Filter out candidates whose hashes aren't allowed, and return a new
    list of candidates.

    If at least one candidate has an allowed hash, then all candidates with
    either an allowed hash or no hash specified are returned.  Otherwise,
    the given candidates are returned.

    Including the candidates with no hash specified when there is a match
    allows a warning to be logged if there is a more preferred candidate
    with no hash specified.  Returning all candidates in the case of no
    matches lets pip report the hash of the candidate that would otherwise
    have been installed (e.g. permitting the user to more easily update
    their requirements file with the desired hash).
    zJGiven no hashes to check %s links for project %r: discarding no candidatesr   )r   r_   zdiscarding no candidateszdiscarding {} non-matches:
  {}z
  c              3   F   K   | ]  }t        |j                          y wrz   )r2   r)   ).0rB   s     r9   	<genexpr>z*filter_unallowed_hashes.<locals>.<genexpr>5  s     I	INN+I   !zPChecked %s links for project %r against %s hashes (%s matches, %s no digest): %s)r3   r5   lenlistr)   has_hashis_hash_allowedappendformatr0   digest_count)
r   r   rL   matches_or_no_digestnon_matchesmatch_countrB   r)   filtereddiscard_messages
             r9   filter_unallowed_hashesr      s1   ( '
O		
 JKK 
/	~~}}!!!01Ky)##I.
/ ' 
#
8}J'4<CCKKI[II

 LL	)J !K/	 OrI   c                   *    e Zd ZdZ	 	 ddededdfdZy)CandidatePreferenceszk
    Encapsulates some of the preferences for filtering and sorting
    InstallationCandidate objects.
    prefer_binaryallow_all_prereleasesr,   Nc                      || _         || _        y)zR
        :param allow_all_prereleases: Whether to allow all pre-releases.
        N)r   r   )rW   r   r   s      r9   rX   zCandidatePreferences.__init__M  s     &;"*rI   )FF)r=   r>   r?   r{   r~   rX   r(   rI   r9   r   r   F  s0     $&+	+	+  $	+ 
		+rI   r   c                   ^    e Zd ZdZdee   dee   dee   ddfdZdee   fdZ	dee   fd	Z
y)
r&   zA collection of candidates, returned by `PackageFinder.find_best_candidate`.

    This class is only intended to be instantiated by CandidateEvaluator's
    `compute_best_candidate()` method.
    r   applicable_candidatesbest_candidater,   Nc                 x    t        |      t        |      k  sJ ||rJ ||v sJ || _        || _        || _        y)a  
        :param candidates: A sequence of all available candidates found.
        :param applicable_candidates: The applicable candidates.
        :param best_candidate: The most preferred candidate found, or None
            if no applicable candidates were found.
        N)set_applicable_candidates_candidatesr   rW   r   r   r   s       r9   rX   zBestCandidateResult.__init__`  sR     ()S_<<<!,,,!%::::&;#%,rI   c                 ,    t        | j                        S )zIterate through all candidates.)iterr   rW   s    r9   iter_allzBestCandidateResult.iter_allx  s    D$$%%rI   c                 ,    t        | j                        S )z*Iterate through the applicable candidates.)r   r   r   s    r9   iter_applicablez#BestCandidateResult.iter_applicable|  s    D//00rI   )r=   r>   r?   r{   r   r   r   rX   r   r   r   r(   rI   r9   r&   r&   Y  sh    -./-  $$9:- !!67	-
 
-0&(#89 &1*?!@ 1rI   r&   c                      e Zd ZdZe	 	 	 	 	 ddedee   dededee	j                     dee   d	d fd
       Z	 	 	 ddedee   de	j                  dededee   d	dfdZdee   d	ee   fdZded	efdZdee   d	ee   fdZdee   d	efdZy)CandidateEvaluatorzm
    Responsible for filtering and sorting candidates for installation based
    on what tags are valid.
    NrL   rO   r   r   	specifierr   r,   c                     |
t               }|t        j                         }|j                         } | ||||||      S )a  Create a CandidateEvaluator object.

        :param target_python: The target Python interpreter to use when
            checking compatibility. If None (the default), a TargetPython
            object will be constructed from the running Python.
        :param specifier: An optional object implementing `filter`
            (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
            versions.
        :param hashes: An optional collection of allowed hashes.
        )rL   ru   r   r   r   r   )r   r   SpecifierSetget_sorted_tags)clsrL   rO   r   r   r   r   ru   s           r9   createzCandidateEvaluator.create  sR    (  (NM"//1I&668%)'"7
 	
rI   ru   c                     || _         || _        || _        || _        || _        || _        t        |      D ci c]  \  }}||
 c}}| _        yc c}}w )z
        :param supported_tags: The PEP 425 tags supported by the target
            Python in order of preference (most preferred first).
        N)_allow_all_prereleases_hashes_prefer_binary_project_name
_specifier_supported_tags	enumerate_wheel_tag_preferences)	rW   rL   ru   r   r   r   r   idxtags	            r9   rX   zCandidateEvaluator.__init__  s^     '<#+)#-
 &/~%>'
!cCH'
# '
s   Ar   c                 n   | j                   xs d}| j                  }|j                  d |D        |      D ch c]  }t        |       }}|D cg c]  }t        |j                        |v s| }}t        || j                  | j                        }t        || j                        S c c}w c c}w )zM
        Return the applicable candidates from a list of candidates.
        Nc              3   F   K   | ]  }t        |j                          y wrz   )r2   r8   )r   cs     r9   r   z?CandidateEvaluator.get_applicable_candidates.<locals>.<genexpr>  s     4AQYY4r   )prereleases)r   r   rL   key)
r   r   filterr2   r8   r   r   r   sorted	_sort_key)	rW   r   allow_prereleasesr   vversionsr   r   filtered_applicable_candidatess	            r9   get_applicable_candidatesz,CandidateEvaluator.get_applicable_candidates  s     !77?4OO	 %% 54- & 

 F
 
  -7 Uq#aii.H:T U U)@,<<++*
& 4$..II1
  !Vs   B-B2.B2rB   c                    | j                   }t        |      }d}d}|j                  }|j                  rt	        |j
                        }	 |j                  || j                         }| j                  rd}|j                  Pt        j                  d|j                        }	|	J d       |	j                         }
t        |
d         |
d   f}n| }t        |j!                  | j"                              }dt        |j$                        z  }||||j&                  ||fS # t        $ r t        |j
                   d      w xY w)a)  
        Function to pass as the `key` argument to a call to sorted() to sort
        InstallationCandidates by preference.

        Returns a tuple such that tuples sorting as greater using Python's
        default comparison operator are more preferred.

        The preference is as follows:

        First and foremost, candidates with allowed (matching) hashes are
        always preferred over candidates without matching hashes. This is
        because e.g. if the only candidate with an allowed hash is yanked,
        we still want to use that candidate.

        Second, excepting hash considerations, candidates that have been
        yanked (in the sense of PEP 592) are always less preferred than
        candidates that haven't been yanked. Then:

        If not finding wheels, they are sorted by version only.
        If finding wheels, then the sort order is by version, then:
          1. existing installs
          2. wheels ordered via Wheel.support_index_min(self._supported_tags)
          3. source archives
        If prefer_binary was set, then all wheels are sorted above sources.

        Note: it was considered to embed this logic into the Link
              comparison operators, but then different sdist links
              with the same version, would have to be considered equal
        r(   r   z@ is not a supported wheel for this platform. It can't be sorted.r_   z^(\d+)(.*)$z!guaranteed by filename validation)r   r   r)   is_wheelr   rf   find_most_preferred_tagr   
ValueErrorr   r   	build_tagr|   rw   groupsintr   r   r`   r8   )rW   rB   
valid_tagssupport_numr   binary_preferencer)   rt   prirw   build_tag_groupshas_allowed_hash
yank_values                r9   r   zCandidateEvaluator._sort_key  sV   < ))
*o 	~~==$--(E
11"D$?$? ""$%!*A(M*MM(#(<<>  !1!!457G7JK	.Ct33DLLAB#dnn--

 	
!  &~~& '' ' s   
D "Ec                 :    |syt        || j                        }|S )zy
        Return the best candidate per the instance's sort order, or None if
        no candidate is acceptable.
        Nr   )maxr   )rW   r   r   s      r9   sort_best_candidatez&CandidateEvaluator.sort_best_candidate/  s      ZT^^<rI   c                 b    | j                  |      }| j                  |      }t        |||      S )zF
        Compute and return a `BestCandidateResult` instance.
        )r   r   )r   r   r&   r   s       r9   compute_best_candidatez)CandidateEvaluator.compute_best_candidate<  s<     !% > >z J112GH""7)
 	
rI   )NFFNN)FFN)r=   r>   r?   r{   classmethodr2   r   r   r~   r   BaseSpecifierr    r   r   r   rX   r   r   CandidateSortingKeyr   r   r&   r   r(   rI   r9   r   r     si   
  15#&+8<#'!
!
  -!
 	!

  $!
 J445!
  !
 
!
 !
P $&+#'

 S	
 ++	

 
  $
  
 

4"J./"J 
#	$"JHC
#8 C
=P C
J./ 
'	(
./
 

rI   r   c                      e Zd ZdZ	 	 	 d/dedededee   dee	   dee   d	dfd
Z
e	 d0dededee   d	d fd       Zed	efd       Zed	efd       Zej$                  ded	dfd       Zed	ee   fd       Zed	ee   fd       Zed	ee   fd       Zed	efd       Zd1dZed	efd       Zd1dZd	ee   fdZded	efdZdee    d	ee    fdZ!de de"ded	dfd Z#d!ede d	ee$   fd"Z%d!edee    d	ee$   fd#Z&d$e d!ed	ee$   fd%Z' e(jR                  d&      ded	ee$   fd'       Z*	 	 d2ded(ee+jX                     d)ee-   d	e.fd*Z/ e(jR                  d&      	 	 d2ded(ee+jX                     d)ee-   d	e0fd+       Z1d,e2d-ed	ee$   fd.Z3y)3r'   zThis finds packages.

    This is meant to match easy_install's technique for looking for
    packages, by reading pages and looking for appropriate links.
    Nlink_collectorrO   rP   format_controlcandidate_prefsr+   r,   c                     |
t               }|xs t        t               t                     }|| _        || _        || _        || _        || _        || _        t               | _	        y)a  
        This constructor is primarily meant to be used by the create() class
        method and from tests.

        :param format_control: A FormatControl object, used to control
            the selection of source packages / binary packages when consulting
            the index and links.
        :param candidate_prefs: Options to use when creating a
            CandidateEvaluator object.
        N)
r   r   r   rR   _candidate_prefsrT   _link_collectorrV   r   _logged_links)rW   r   rO   rP   r   r   r+   s          r9   rX   zPackageFinder.__init__U  sd    & "24O'F=+F) /'=$-+, ?BerI   selection_prefsc                     |
t               }t        |j                  |j                        } | ||||j                  |j
                  |j                        S )af  Create a PackageFinder.

        :param selection_prefs: The candidate selection preferences, as a
            SelectionPreferences object.
        :param target_python: The target Python interpreter to use when
            checking compatibility. If None (the default), a TargetPython
            object will be constructed from the running Python.
        )r   r   )r   r   rO   rP   r   r+   )r   r   r   r   rP   r   r+   )r   r   r   rO   r   s        r9   r   zPackageFinder.create|  s`      (NM.)77"1"G"G

 +)'(55*99#2#I#I
 	
rI   c                     | j                   S rz   )rV   r   s    r9   rO   zPackageFinder.target_python  s    """rI   c                 .    | j                   j                  S rz   r   search_scoper   s    r9   r   zPackageFinder.search_scope  s    ##000rI   r   c                 &    || j                   _        y rz   r   )rW   r   s     r9   r   zPackageFinder.search_scope  s    ,8)rI   c                 .    | j                   j                  S rz   )r   
find_linksr   s    r9   r   zPackageFinder.find_links  s    ##...rI   c                 .    | j                   j                  S rz   )r   
index_urlsr   s    r9   r   zPackageFinder.index_urls  s      +++rI   c              #   j   K   | j                   j                  j                  D ]  }t        |   y wrz   )r   sessionpip_trusted_originsr"   )rW   	host_ports     r9   trusted_hostszPackageFinder.trusted_hosts  s2     --55II 	+I	**	+s   13c                 .    | j                   j                  S rz   r   r   r   s    r9   r   z#PackageFinder.allow_all_prereleases  s    $$:::rI   c                 &    d| j                   _        y NTr   r   s    r9   set_allow_all_prereleasesz'PackageFinder.set_allow_all_prereleases  s    6:3rI   c                 .    | j                   j                  S rz   r   r   r   s    r9   r   zPackageFinder.prefer_binary  s    $$222rI   c                 &    d| j                   _        y r   r   r   s    r9   set_prefer_binaryzPackageFinder.set_prefer_binary  s    .2+rI   c                     | j                   D ch c]  \  }}}|t        j                  k(  r| }}}}t        |      S c c}}}w rz   )r   r<   rH   r   )rW   _resultdetailreasonss        r9   requires_python_skipped_reasonsz-PackageFinder.requires_python_skipped_reasons  sQ     &*%7%7
 
!66::: 
 

 g
s    A rL   c                     t        |      }| j                  j                  |      }t        |||| j                  | j
                  | j                        S )N)rL   rM   rN   rO   rP   r+   )r   r   get_allowed_formatsrK   rV   rR   rT   )rW   rL   rM   rN   s       r9   make_link_evaluatorz!PackageFinder.make_link_evaluator  sS    *<8%%99.I%)--++#'#?#?
 	
rI   linksc                     g g }}t               }|D ]G  }||vs|j                  |       |j                  r|j                  |       7|j                  |       I ||z   S )z
        Returns elements of links in order, non-egg links first, egg links
        second, while eliminating duplicates
        )r   addrb   r   )rW   r  eggsno_eggsseenr)   s         r9   _sort_linkszPackageFinder._sort_links  sc    
 Bg% 	)D4$$KK%NN4(	) ~rI   r)   r  r  c                     |||f}|| j                   vr3t        j                  d||       | j                   j                  |       y y )NzSkipping link: %s: %s)r   r3   r5   r
  )rW   r)   r  r  entrys        r9   _log_skipped_linkzPackageFinder._log_skipped_link  sH    vv&*** LL0&$?""5)	 +rI   link_evaluatorc                     |j                  |      \  }}|t        j                  k7  r| j                  |||       yt	        |j
                  ||      S )z
        If the link is a candidate for install, convert it to an
        InstallationCandidate and return it. Otherwise, return None.
        N)rg   r)   r8   )ry   r<   rB   r  r   rL   )rW   r  r)   r  r  s        r9   get_install_candidatez#PackageFinder.get_install_candidate  sW     (55d;X'''""48$,,
 	
rI   c                     g }| j                  |      D ](  }| j                  ||      }||j                  |       * |S )zU
        Convert links that are candidates to InstallationCandidate objects.
        )r  r  r   )rW   r  r  r   r)   rB   s         r9   evaluate_linkszPackageFinder.evaluate_links  sQ     
$$U+ 	-D22>4HI$!!),	-
 rI   project_urlc                     t         j                  d|       | j                  j                  |      }|g S t	        t        |            }t               5  | j                  ||      }d d d        |S # 1 sw Y   S xY w)Nz-Fetching project page and analyzing links: %s)r  )r3   r5   r   fetch_responser   r   r!   r  )rW   r  r  index_response
page_linkspackage_linkss         r9   process_project_urlz!PackageFinder.process_project_url  s     	;	
 --<<[I!I+n56
\ 	 //  0 M	 	 s   A22A<)maxsizec                    | j                  |      }| j                  j                  |t        j                  | j
                  |            }t        j                  j                  d |D              }t        |      }t        j                  j                  d |D              }| j                  |t        |d            }t        j                  t        j                        rn|rlg }|D ]@  }	|	j                   j"                  sJ 	 |j%                  |	j                   j&                         B t        j+                  ddj-                  |             ||z   S # t(        $ r( |j%                  |	j                   j"                         Y w xY w)	a  Find all available InstallationCandidate for project_name

        This checks index_urls and find_links.
        All versions found are returned as an InstallationCandidate list.

        See LinkEvaluator.evaluate_link() for details on which files
        are accepted.
        )r  )rL   candidates_from_pagec              3   N   K   | ]  }|D ]  }||j                            y wrz   )page_candidatesr   sourcesr^   s      r9   r   z4PackageFinder.find_all_candidates.<locals>.<genexpr>9  s<      ;
!;
 ! ""$;
$;
   #%c              3   N   K   | ]  }|D ]  }||j                            y wrz   )
file_linksr#  s      r9   r   z4PackageFinder.find_all_candidates.<locals>.<genexpr>A  s<      6
!6
 ! 6
6
r%  T)reversezLocal files found: %sr]   )r  r   collect_sources	functoolspartialr  	itertoolschainfrom_iterabler   r  r   r3   isEnabledForloggingDEBUGr)   urlr   	file_path	Exceptionr5   r0   )
rW   rL   r  collected_sourcespage_candidates_itr"  file_links_itfile_candidatespathsrB   s
             r9   find_all_candidatesz!PackageFinder.find_all_candidates%  se    11,? 00@@%!*!2!2((-" A 
 '__:: ;
,;
 
 12!55 6
,6
 
 --=$/

 w}}-/E, 5	 ~~))))5LL!9!9:5 LL0$))E2BC 00 ! 5LL!3!345s   %E.F	F	r   r   c                     | j                   }t        j                  || j                  |j                  |j
                  ||      S )z*Create a CandidateEvaluator object to use.)rL   rO   r   r   r   r   )r   r   r   rV   r   r   )rW   rL   r   r   r   s        r9   make_candidate_evaluatorz&PackageFinder.make_candidate_evaluatorZ  sK     //!((%--)77"1"G"G ) 
 	
rI   c                 n    | j                  |      }| j                  |||      }|j                  |      S )a  Find matches for the given project and specifier.

        :param specifier: An optional object implementing `filter`
            (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
            versions.

        :return: A `BestCandidateResult` instance.
        )rL   r   r   )r:  r<  r   )rW   rL   r   r   r   candidate_evaluators         r9   find_best_candidatez!PackageFinder.find_best_candidatek  sF     --l;
";;% < 

 #99*EErI   requpgradec                    |j                  d      }| j                  |j                  |j                  |      }|j                  d|j
                  |j
                  j                  dt        t           dt        fd};9t        j                  d| ||j                                      t        d	|       d
t        t           ddffd}|sCA |      r"t        j                  dj                         yt        j                  d       y |      r7t        j                  dj                   ||j!                                      S t        j                  d ||j!                                      t"        )zTry to find a Link matching req

        Expects req, an InstallRequirement and upgrade, a boolean
        Returns a InstallationCandidate if found,
        Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise
        F)trust_internet)r   r   N	cand_iterr,   c           
          dj                  t        | D ch c]  }t        |j                         c}t                    xs dS c c}w )Nr]   r   none)r0   r   r2   r8   parse_version)rD  r   s     r9   _format_versionsz8PackageFinder.find_requirement.<locals>._format_versions  sE     		1:;AQYY;)   <s   AzNCould not find a version that satisfies the requirement %s (from versions: %s)z#No matching distribution found for rB   z TypeGuard[InstallationCandidate]c                 .    yyj                   kD  S )NTF)r8   )rB   r   installed_versions    r9   _should_install_candidatezAPackageFinder.find_requirement.<locals>._should_install_candidate  s)     !(%!)),===rI   zUExisting installed version (%s) satisfies requirement (most up-to-date version is %s)zLExisting installed version (%s) is most up-to-date and satisfies requirementz)Using version %s (newest of versions: %s)z=Installed version (%s) is most up-to-date (past versions: %s))r   r?  rg   r   r   satisfied_byr8   r   r   r2   r3   criticalr   r   r   r5   r   r   )	rW   r@  rA  r   best_candidate_resultrH  rK  r   rJ  s	          @@r9   find_requirementzPackageFinder.find_requirement  s    51 $ 8 8HHmm !9 !

 /==48' # 0 0 8 8	1F(G 	C 	 $)?OO& !6!?!?!AB	 ')LSE'RSS	> 56	>/	> ,8(86%"**	  ,%
 $^4LL;&& !6!F!F!HI
 "! 	K2BBDE	

 *)rI   )NNNrz   )r,   N)NN)4r=   r>   r?   r{   r   r   r~   r   r   r   rX   r   r   r   propertyrO   r   r   setterr   r2   r   r   r   r   r   r   r   r   r  rK   r  r   r  r<   r  r   r  r  r  r*  	lru_cacher:  r   r   r    r   r<  r&   r?  r   rO  r(   rI   r9   r'   r'   N  s    37:>15!D%!D $!D 	!D
 !/!D ""67!D !)!D 
!DN 
 15	
%
 .
  -	

 

 
> #| # # 1k 1 1 9 9 9 9 /DI / / ,DI , , +x} + + ;t ; ;; 3t 3 33c 
 
 
$ DJ  *d *H *c *d *
+
37
	'	(
$+4<TN	#	$1>	#	$* Y&21 21=R8S 21 '21n 9=#'	

 J445
  	

 

" Y& 9=#'	FF J445F  	F
 
F 'F,U*%U*04U*	'	(U*rI   r'   fragmentrM   c                 ~    t        |       D ]   \  }}|dk7  rt        | d|       |k(  s|c S  t        |  d|       )a  Find the separator's index based on the package's canonical name.

    :param fragment: A <package>+<version> filename "fragment" (stem) or
        egg fragment.
    :param canonical_name: The package's canonical name.

    This function is needed since the canonicalized name does not necessarily
    have the same length as the egg info's name part. An example::

    >>> fragment = 'foo__bar-1.0'
    >>> canonical_name = 'foo-bar'
    >>> _find_name_version_sep(fragment, canonical_name)
    8
    -Nz does not match )r   r   r   )rS  rM   ir   s       r9   _find_name_version_seprW    sX    $ (# 18Xbq\*n<H	
 z!1.1AB
CCrI   c                 T    	 t        | |      dz   }| |d }|sy|S # t        $ r Y yw xY w)zParse the version string from a <package>+<version> filename
    "fragment" (stem) or egg fragment.

    :param fragment: The string to parse. E.g. foo-2.1
    :param canonical_name: The canonicalized name of the package this
        belongs to.
    r_   N)rW  r   )rS  rM   version_startr8   s       r9   rk   rk     sE    .xH1L }~&GN  s    	'')F)Tr{   r@   r*  r,  r0  r|   typingr   r   r   r   r   r   r	   r
   pip._vendor.packagingr   pip._vendor.packaging.tagsr   pip._vendor.packaging.utilsr   pip._vendor.packaging.versionr   r   rG  pip._internal.exceptionsr   r   r   r   pip._internal.index.collectorr   r   pip._internal.models.candidater   #pip._internal.models.format_controlr   pip._internal.models.linkr   !pip._internal.models.search_scoper   $pip._internal.models.selection_prefsr   "pip._internal.models.target_pythonr   pip._internal.models.wheelr   pip._internal.reqr   pip._internal.utils._logr   pip._internal.utils.filetypesr   pip._internal.utils.hashesr    pip._internal.utils.loggingr!   pip._internal.utils.miscr"   pip._internal.utils.packagingr#   pip._internal.utils.unpackingr$   pip._vendor.typing_extensionsr%   __all__r=   r3   r   r2   BuildTagr   r~   r:   Enumr<   rK   r   r   r&   r   r'   rW  rk   r(   rI   r9   <module>rt     s   '     	 X X X , * 9 6 @  E @ = * 9 E ; , 0 . 9 - 2 1 ? >7
C 
8	rE#s(O+,Cc<#PQ  $),
,S#&, !, 
	,^+tyy +M- M-`G*+GVG G 

 	GT+ +&%1 %1PJ
 J
ZI* I*XDS D# D# D4S # (SV- rI   