o Ec @spdZddlZddlZddlZddlZddlmZmZmZm Z m Z m Z m Z ddl mZddlmZddlmZddlmZddlmZdd lmZmZmZmZdd lmZmZdd lm Z dd l!m"Z"dd l#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ>gdZ?e0e@ZAe e de eBeCffZDe eBeBeBee eBeDfZE d9de$de eBeBeBfd eFd!eFfd"d#ZGGd$d%d%ZHd&ee d'e4d(eCd!ee fd)d*ZIGd+d,d,ZJGd-d.d.ZKGd/d0d0ZLGd1d2d2ZMd3eCd4eCd!eBfd5d6ZNd3eCd4eCd!e eCfd7d8ZOdS):z!Routines related to PyPI, indexesN) FrozenSetIterableListOptionalSetTupleUnion) specifiers)Tag)canonicalize_name) _BaseVersion)parse)BestVersionAlreadyInstalledDistributionNotFoundInvalidWheelFilenameUnsupportedWheel) LinkCollector parse_links)InstallationCandidate) FormatControl)Link) SearchScope)SelectionPreferences) TargetPython)Wheel)InstallRequirement) getLogger)WHEEL_EXTENSION)Hashes) indent_log) build_netloc)check_requires_python)SUPPORTED_EXTENSIONS) url_to_path)rBestCandidateResult PackageFinderFlink version_infoignore_requires_pythonreturncCs~z t|j|d}Wntjytd|j|YdSw|s=dtt|}|s4t d||j|dStd||j|dS)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(z2Ignoring invalid Requires-Python (%r) for link: %s.z4Link requires a different Python (%s not in: %r): %sFzBIgnoring failed Requires-Python check (%s not in: %r) for link: %sT) r!Zrequires_pythonr ZInvalidSpecifierloggerdebugjoinmapstrverbose)r'r(r)Z is_compatibleversionr&r&U/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/index/package_finder.py_check_link_requires_python3s< r4c@sjeZdZdZedZ ddededeede de d e e d dfd d Z d e d ee e effddZdS) LinkEvaluatorzD Responsible for evaluating links for a particular project. z-py([123]\.?[0-9]?)$N project_namecanonical_nameformats target_python allow_yankedr)r*cCs4|durd}||_||_||_||_||_||_dS)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_pythonr6)selfr6r7r8r9r:r)r&r&r3__init__ns zLinkEvaluator.__init__r'c Csd}|jr|js|jp d}dd|fS|jr|j}|j}nx|\}}|s(dS|tvr3dd|fSd|jvrF|tkrFd |j }d|fSd |j vrQ|d krQd S|tkrzt |j }Wn tyfYd Swt|j|jkryd |j }d|fS|j}||s|}d d|}d|fS|j}d|jvr|tkrd|j }d|fS|st||j}|sd|j }d|fS|j|} | r|d| }| d} | |jjkrdSt||jj|j d} | sdSt!"d||d|fS)aG Determine whether a link is a candidate for installation. :return: A tuple (is_candidate, result), where `result` is (1) a version string if `is_candidate` is True, and (2) if `is_candidate` is False, an optional string to log the reason the link fails to qualify. Nz Fzyanked for reason: )Fz not a filezunsupported archive format: ZbinaryzNo binaries permitted for {}Zmacosx10z.zip)Fz macosx10 one)Fzinvalid wheel filenamezwrong project name (not {})z^none of the wheel's tags ({}) are compatible (run pip debug --verbose to show compatible tags), sourcezNo sources permitted for zMissing project version for )FzPython version is incorrect)r(r))FNzFound link %s, version: %sT)# is_yankedr;Z yanked_reason egg_fragmentextsplitextr"r>rformatr6pathrfilenamerr namer<r?get_tagsZ supportedZget_formatted_file_tagsr.r2_extract_version_from_fragment_py_version_researchstartgroup py_versionr4Zpy_version_infor=r,r-) r@r'r2reasonZegg_inforGwheelsupported_tagsZ file_tagsmatchrSZsupports_pythonr&r&r3 evaluate_links|             zLinkEvaluator.evaluate_linkN)__name__ __module__ __qualname____doc__recompilerOr0rrboolrrArrrXr&r&r&r3r5bs(   "%r5 candidateshashesr6c Cs|stdt||t|Sg}g}d}|D]}|j}|js n|j|dr+|d7}n||q||q|r<|}nt|}t|t|krKd} ndt|d dd |D} td t|||j |t||| |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)rbrDzdiscarding no candidateszdiscarding {} non-matches: {}z cs|]}t|jVqdSrY)r0r').0 candidater&r&r3 $z*filter_unallowed_hashes..zPChecked %s links for project %r against %s hashes (%s matches, %s no digest): %s) r,r-lenlistr'Zhas_hashis_hash_allowedappendrIr.Z digest_count) rarbr6Zmatches_or_no_digestZ non_matchesZ match_countrer'ZfilteredZdiscard_messager&r&r3filter_unallowed_hashessL      rlc@s,eZdZdZ  d dededdfddZdS) CandidatePreferenceszk Encapsulates some of the preferences for filtering and sorting InstallationCandidate objects. F prefer_binaryallow_all_prereleasesr*NcCs||_||_dS)zR :param allow_all_prereleases: Whether to allow all pre-releases. N)rorn)r@rnror&r&r3rA<s zCandidatePreferences.__init__)FF)rZr[r\r]r`rAr&r&r&r3rm5srmc@sZeZdZdZdeedeedeeddfddZdeefd d Z deefd d Z dS) 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. raapplicable_candidatesbest_candidater*NcCsHt|t|ks J|dur|rJn||vsJ||_||_||_dS)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 _candidatesrqr@rarprqr&r&r3rAOs    zBestCandidateResult.__init__cC t|jS)zIterate through all candidates.)iterrtr@r&r&r3iter_allg zBestCandidateResult.iter_allcCrv)z*Iterate through the applicable candidates.)rwrsrxr&r&r3iter_applicablekrzz#BestCandidateResult.iter_applicable) rZr[r\r]rrrrArryr{r&r&r&r3r$Hs r$c@seZdZdZe     ddedeedededee j d ee d dfd d Z   dded e ede j deded ee d dfddZde ed e efddZded efddZde ed eefddZde ed efddZdS)CandidateEvaluatorzm Responsible for filtering and sorting candidates for installation based on what tags are valid. NFr6r9rnro specifierrbr*cCs:|durt}|durt}|}|||||||dS)aCreate 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. N)r6rVr}rnrorb)rr Z SpecifierSetrM)clsr6r9rnror}rbrVr&r&r3createwszCandidateEvaluator.createrVcCs<||_||_||_||_||_||_ddt|D|_dS)z :param supported_tags: The PEP 425 tags supported by the target Python in order of preference (most preferred first). cSsi|]\}}||qSr&r&)rdidxtagr&r&r3 s z/CandidateEvaluator.__init__..N)_allow_all_prereleases_hashes_prefer_binary _project_name _specifier_supported_tags enumerate_wheel_tag_preferences)r@r6rVr}rnrorbr&r&r3rAs  zCandidateEvaluator.__init__racsd|jpd}|j}dd|jdd|D|dDfdd|D}t||j|jd }t||jd S) zM Return the applicable candidates from a list of candidates. NcSsh|]}t|qSr&)r0)rdvr&r&r3 sz?CandidateEvaluator.get_applicable_candidates..csrcrYr0r2rdcr&r&r3rfrgz?CandidateEvaluator.get_applicable_candidates..)Z prereleasescsg|] }t|jvr|qSr&rrZversionsr&r3 sz@CandidateEvaluator.get_applicable_candidates..)rarbr6key)rrfilterrlrrsorted _sort_key)r@raZallow_prereleasesr}rpZfiltered_applicable_candidatesr&rr3get_applicable_candidatess  z,CandidateEvaluator.get_applicable_candidatesrec Cs|j}t|}d}d}|j}|jrPt|j}z |||j }Wnty/t d |jw|j r5d}|j durOt d|j } | } t| d| df}n| }t||j} dt|j} | | ||j||fS)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&rzB{} is not a supported wheel for this platform. It can't be sorted.rDNz ^(\d+)(.*)$)rrhr'Zis_wheelrrKZfind_most_preferred_tagr ValueErrorrrIr build_tagr^rWgroupsintrjrrEr2) r@reZ valid_tagsZ support_numrZbinary_preferencer'rUZprirWZbuild_tag_groupsZhas_allowed_hashZ yank_valuer&r&r3rsF   zCandidateEvaluator._sort_keycCs|sdSt||jd}|S)zy Return the best candidate per the instance's sort order, or None if no candidate is acceptable. Nr)maxr)r@rarqr&r&r3sort_best_candidatesz&CandidateEvaluator.sort_best_candidatecCs"||}||}t|||dS)zF Compute and return a `BestCandidateResult` instance. )rprq)rrr$rur&r&r3compute_best_candidate*s  z)CandidateEvaluator.compute_best_candidate)NFFNN)FFN)rZr[r\r] classmethodr0rrr`r BaseSpecifierrrrr rArrCandidateSortingKeyrrr$rr&r&r&r3r|psr (  $D  r|c@sVeZdZdZ   dBdedededeedee deed dfd d Z e dCded e deed dfd dZ ed efddZed efddZejded dfddZed eefddZed eefddZed eefddZed efddZdDddZed efdd ZdDd!d"Zd#ed efd$d%Zd&eed eefd'd(Z d)ed*ed dfd+d,Z!d-ed)ed ee"fd.d/Z#d-ed&eed ee"fd0d1Z$d2ed-ed ee"fd3d4Z%e&j'dd5d#ed ee"fd6d7Z(  dEd#ed8ee)j*d9ee+d e,fd:d;Z-e&j'dd5  dEd#ed8ee)j*d9ee+d e.fde0d?ed ee"fd@dAZ1dS)Fr%zThis finds packages. This is meant to match easy_install's technique for looking for packages, by reading pages and looking for appropriate links. Nlink_collectorr9r:format_controlcandidate_prefsr)r*cCsP|durt}|pttt}||_||_||_||_||_||_t|_ dS)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) rmrrrr;_candidate_prefsr=_link_collectorr?r _logged_links)r@rr9r:rrr)r&r&r3rACs zPackageFinder.__init__selection_prefscCs8|durt}t|j|jd}|||||j|j|jdS)afCreate 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. N)rnro)rrr9r:rr))rrmrnror:rr))r~rrr9rr&r&r3rjszPackageFinder.createcCs|jSrY)r?rxr&r&r3r9szPackageFinder.target_pythoncC|jjSrYr search_scoperxr&r&r3rzPackageFinder.search_scopercCs ||j_dSrYr)r@rr&r&r3rs cCrrY)r find_linksrxr&r&r3rrzPackageFinder.find_linkscCrrY)r index_urlsrxr&r&r3rrzPackageFinder.index_urlsccs |jjjD]}t|VqdSrY)rZsessionZpip_trusted_originsr )r@ host_portr&r&r3 trusted_hostss zPackageFinder.trusted_hostscCrrYrrorxr&r&r3rorz#PackageFinder.allow_all_prereleasescC d|j_dSNTrrxr&r&r3set_allow_all_prereleases z'PackageFinder.set_allow_all_prereleasescCrrYrrnrxr&r&r3rnrzPackageFinder.prefer_binarycCrrrrxr&r&r3set_prefer_binaryrzPackageFinder.set_prefer_binaryr6cCs.t|}|j|}t||||j|j|jdS)N)r6r7r8r9r:r))r rZget_allowed_formatsr5r?r;r=)r@r6r7r8r&r&r3make_link_evaluators z!PackageFinder.make_link_evaluatorlinkscCsPgg}}t}|D]}||vr#|||jr||q ||q ||S)z Returns elements of links in order, non-egg links first, egg links second, while eliminating duplicates )rraddrFrk)r@rZeggsZno_eggsseenr'r&r&r3 _sort_linkss    zPackageFinder._sort_linksr'rTcCs,||jvrtd|||j|dSdS)NzSkipping link: %s: %s)rr,r-r)r@r'rTr&r&r3_log_skipped_links zPackageFinder._log_skipped_linklink_evaluatorcCs8||\}}|s|r|j||ddSt|j||dS)z If the link is a candidate for install, convert it to an InstallationCandidate and return it. Otherwise, return None. )rTN)rLr'r2)rXrrr6)r@rr'Z is_candidateresultr&r&r3get_install_candidatesz#PackageFinder.get_install_candidatecCs6g}||D]}|||}|dur||q|S)zU Convert links that are candidates to InstallationCandidate objects. N)rrrk)r@rrrar'rer&r&r3evaluate_linkss  zPackageFinder.evaluate_links project_urlcCsjtd||j|}|durgStt|}t|j||d}Wd|S1s.wY|S)Nz-Fetching project page and analyzing links: %s)r)r,r-rZ fetch_pagerirrr)r@rrZ html_pageZ page_linksZ package_linksr&r&r3process_project_urls"   z!PackageFinder.process_project_url)maxsizec Cs||}|jj|tj|j|dd}tjdd|D}t |}tjdd|D}| |t |dd}t tjrO|rOdd |D}t d d |||S) aFind 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)r6Zcandidates_from_pagecs*|]}|D] }|dur|VqqdSrY)page_candidatesrdZsourcesrCr&r&r3rf z4PackageFinder.find_all_candidates..csrrY)Z file_linksrr&r&r3rf'rT)reversecSsg|]}t|jjqSr&)r#r'urlrr&r&r3r3sz5PackageFinder.find_all_candidates..zLocal files found: %srB)rrZcollect_sources functoolspartialr itertoolschain from_iterablerirrr,Z isEnabledForloggingDEBUGr-r.) r@r6rZcollected_sourcesZpage_candidates_itrZ file_links_itZfile_candidatespathsr&r&r3find_all_candidates s.    z!PackageFinder.find_all_candidatesr}rbcCs"|j}tj||j|j|j||dS)z*Create a CandidateEvaluator object to use.)r6r9rnror}rb)rr|rr?rnro)r@r6r}rbrr&r&r3make_candidate_evaluator9sz&PackageFinder.make_candidate_evaluatorcCs$||}|j|||d}||S)aFind 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. )r6r}rb)rrr)r@r6r}rbraZcandidate_evaluatorr&r&r3find_best_candidateJs  z!PackageFinder.find_best_candidaterequpgradec Cs|jdd}|j|j|j|d}|j}d}|jdur t|jj}dtt dt fdd}|durE|durEt d ||| td |d}|rT|dusR|j|krTd }|sn|durn|rdt d |dSt d ||jdS|r}t d|||tt d|j|||S)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)Ztrust_internet)r}rbN cand_iterr*cSs dtdd|DtdpdS)NrBcSsh|]}t|jqSr&rrr&r&r3r~szKPackageFinder.find_requirement.._format_versions..rZnone)r.r parse_version)rr&r&r3_format_versionsvs z8PackageFinder.find_requirement.._format_versionszNCould not find a version that satisfies the requirement %s (from versions: %s)z%No matching distribution found for {}TzLExisting installed version (%s) is most up-to-date and satisfies requirementzUExisting installed version (%s) satisfies requirement (most up-to-date version is %s)z=Installed version (%s) is most up-to-date (past versions: %s)z)Using version %s (newest of versions: %s))rbrrLr}rqZ satisfied_byrr2rrr0r,ZcriticalryrrIr-r{r) r@rrrbZbest_candidate_resultrqZinstalled_versionrZbest_installedr&r&r3find_requirementasj        zPackageFinder.find_requirement)NNNrY)r*N)NN)2rZr[r\r]rrr`rrrmrArrrpropertyr9rrsetterrr0rrrrrorrnrr5rrrrrrrrr lru_cacherr rrr|rr$rrrr&r&r&r3r%<s  '       0  r%fragmentr7cCsJt|D]\}}|dkr qt|d||kr|Sqt|d|)aFind the separator's index based on the package's canonical name. :param fragment: A + 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 )rr r)rr7irr&r&r3_find_name_version_sepsrcCs@z t||d}Wn tyYdSw||d}|sdS|S)zParse the version string from a + 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. rDN)rr)rr7Z version_startr2r&r&r3rNs  rN)F)Pr]rrrr^typingrrrrrrrZpip._vendor.packagingr Zpip._vendor.packaging.tagsr Zpip._vendor.packaging.utilsr Zpip._vendor.packaging.versionr r rZpip._internal.exceptionsrrrrZpip._internal.index.collectorrrZpip._internal.models.candidaterZ#pip._internal.models.format_controlrZpip._internal.models.linkrZ!pip._internal.models.search_scoperZ$pip._internal.models.selection_prefsrZ"pip._internal.models.target_pythonrZpip._internal.models.wheelrZpip._internal.reqrZpip._internal.utils._logrZpip._internal.utils.filetypesrZpip._internal.utils.hashesrZpip._internal.utils.loggingrZpip._internal.utils.miscr Zpip._internal.utils.packagingr!Zpip._internal.utils.unpackingr"Zpip._internal.utils.urlsr#__all__rZr,rr0ZBuildTagrr`r4r5rlrmr$r|r%rrNr&r&r&r3s~$                       /  J(M~