o ai @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!requires_pythonr InvalidSpecifierloggerdebugjoinmapstrverbose)r'r(r) is_compatibleversionr&r&/builddir/build/BUILDROOT/alt-python310-pip-21.3.1-5.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/index/package_finder.py_check_link_requires_python3s< r7c@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_pythonr9)selfr9r:r;r<r=r)r&r&r6__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: binaryzNo binaries permitted for {}macosx10z.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> yanked_reason egg_fragmentextsplitextr"rArformatr9pathrfilenamerr namer?rBget_tags supportedget_formatted_file_tagsr0r5_extract_version_from_fragment_py_version_researchstartgroup py_versionr7py_version_infor@r.r/) rCr'r5reasonegg_inforMwheelsupported_tags file_tagsmatchr[supports_pythonr&r&r6 evaluate_links|             zLinkEvaluator.evaluate_linkN)__name__ __module__ __qualname____doc__recompilerWr2rrboolrrDrrrdr&r&r&r6r8bs(   "%r8 candidateshashesr9c 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)rnrIzdiscarding no candidateszdiscarding {} non-matches: {}z cs|]}t|jVqdSre)r2r').0 candidater&r&r6 $z*filter_unallowed_hashes..zPChecked %s links for project %r against %s hashes (%s matches, %s no digest): %s) r.r/lenlistr'has_hashis_hash_allowedappendrOr0 digest_count) rmrnr9matches_or_no_digest non_matches match_countrqr'filtereddiscard_messager&r&r6filter_unallowed_hashessL      rc@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)rr)rCrrr&r&r6rD<s zCandidatePreferences.__init__)FF)rfrgrhrirlrDr&r&r&r6r5src@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. rmapplicable_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 _candidatesrrCrmrrr&r&r6rDOs    zBestCandidateResult.__init__cC t|jS)zIterate through all candidates.)iterrrCr&r&r6iter_allg zBestCandidateResult.iter_allcCr)z*Iterate through the applicable candidates.)rrrr&r&r6iter_applicablekrz#BestCandidateResult.iter_applicable) rfrgrhrirrrrDrrrr&r&r&r6r$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. NFr9r<rr specifierrnr*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)r9r`rrrrn)rr SpecifierSetrS)clsr9r<rrrrnr`r&r&r6createwszCandidateEvaluator.creater`cCs<||_||_||_||_||_||_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&)rpidxtagr&r&r6 s z/CandidateEvaluator.__init__..N)_allow_all_prereleases_hashes_prefer_binary _project_name _specifier_supported_tags enumerate_wheel_tag_preferences)rCr9r`rrrrnr&r&r6rDs  zCandidateEvaluator.__init__rmcsd|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&)r2)rpvr&r&r6 sz?CandidateEvaluator.get_applicable_candidates..csrorer2r5rpcr&r&r6rrrsz?CandidateEvaluator.get_applicable_candidates..) prereleasescsg|] }t|jvr|qSr&rrversionsr&r6 sz@CandidateEvaluator.get_applicable_candidates..)rmrnr9key)rrfilterrrrsorted _sort_key)rCrmallow_prereleasesrrfiltered_applicable_candidatesr&rr6get_applicable_candidatess  z,CandidateEvaluator.get_applicable_candidatesrqc 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.rINz ^(\d+)(.*)$)rrtr'is_wheelrrQfind_most_preferred_tagr ValueErrorrrOr build_tagrjrbgroupsintrwrrJr5) rCrq valid_tags support_numrbinary_preferencer'r_prirbbuild_tag_groupshas_allowed_hash yank_valuer&r&r6rsF   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)rCrmrr&r&r6sort_best_candidatesz&CandidateEvaluator.sort_best_candidatecCs"||}||}t|||dS)zF Compute and return a `BestCandidateResult` instance. )rr)rrr$rr&r&r6compute_best_candidate*s  z)CandidateEvaluator.compute_best_candidate)NFFNN)FFN)rfrgrhri classmethodr2rrrlr BaseSpecifierrrrr rDrrCandidateSortingKeyrrr$rr&r&r&r6rpsr (  $D  rc@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_collectorr<r=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) rrrr>_candidate_prefsr@_link_collectorrBr _logged_links)rCrr<r=rrr)r&r&r6rDCs 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)rr)rrr<r=rr))rrrrr=rr))rrrr<rr&r&r6rjszPackageFinder.createcCs|jSre)rBrr&r&r6r<szPackageFinder.target_pythoncC|jjSrer search_scoperr&r&r6rzPackageFinder.search_scopercCs ||j_dSrer)rCrr&r&r6rs cCrre)r find_linksrr&r&r6rrzPackageFinder.find_linkscCrre)r index_urlsrr&r&r6rrzPackageFinder.index_urlsccs |jjjD]}t|VqdSre)rsessionpip_trusted_originsr )rC host_portr&r&r6 trusted_hostss zPackageFinder.trusted_hostscCrrerrrr&r&r6rrz#PackageFinder.allow_all_prereleasescC d|j_dSNTrrr&r&r6set_allow_all_prereleases z'PackageFinder.set_allow_all_prereleasescCrrerrrr&r&r6rrzPackageFinder.prefer_binarycCrrrrr&r&r6set_prefer_binaryrzPackageFinder.set_prefer_binaryr9cCs.t|}|j|}t||||j|j|jdS)N)r9r:r;r<r=r))r rget_allowed_formatsr8rBr>r@)rCr9r:r;r&r&r6make_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 )raddrLrx)rCreggsno_eggsseenr'r&r&r6 _sort_linkss    zPackageFinder._sort_linksr'r]cCs,||jvrtd|||j|dSdS)NzSkipping link: %s: %s)rr.r/r)rCr'r]r&r&r6_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. )r]N)rRr'r5)rdrrr9)rCrr' is_candidateresultr&r&r6get_install_candidatesz#PackageFinder.get_install_candidatecCs6g}||D]}|||}|dur||q|S)zU Convert links that are candidates to InstallationCandidate objects. N)rrrx)rCrrrmr'rqr&r&r6evaluate_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/r fetch_pagerurrr)rCrr html_page page_links package_linksr&r&r6process_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)r9candidates_from_pagecs*|]}|D] }|dur|VqqdSre)page_candidatesrpsourcesrHr&r&r6rrz4PackageFinder.find_all_candidates..csrre) file_linksrr&r&r6rr'rT)reversecSsg|]}t|jjqSr&)r#r'urlrr&r&r6r3sz5PackageFinder.find_all_candidates..zLocal files found: %srG)rrcollect_sources functoolspartialr itertoolschain from_iterablerurrr. isEnabledForloggingDEBUGr/r0) rCr9rcollected_sourcespage_candidates_itr file_links_itfile_candidatespathsr&r&r6find_all_candidates s.    z!PackageFinder.find_all_candidatesrrncCs"|j}tj||j|j|j||dS)z*Create a CandidateEvaluator object to use.)r9r<rrrrn)rrrrBrr)rCr9rrnrr&r&r6make_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. )r9rrn)rr r)rCr9rrnrmcandidate_evaluatorr&r&r6find_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)trust_internet)rrnN cand_iterr*cSs dtdd|DtdpdS)NrGcSsh|]}t|jqSr&rrr&r&r6r~szKPackageFinder.find_requirement.._format_versions..rnone)r0r parse_version)rr&r&r6_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))rnr rRrr satisfied_byrr5rrr2r.criticalrrrOr/rr) rCr r rnbest_candidate_resultrinstalled_versionrbest_installedr&r&r6find_requirementasd        zPackageFinder.find_requirement)NNNre)r*N)NN)2rfrgrhrirrrlrrrrDrrrpropertyr<rrsetterrr2rrrrrrrrr8rrrrrrrrr lru_cacherr rrrr r$r rrr&r&r&r6r%<s  '       0  r%fragmentr:cCsJt|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)rr:irr&r&r6_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. rIN)rr)rr: version_startr5r&r&r6rVs  rV)F)PrirrrrjtypingrrrrrrrZpip._vendor.packagingr Zpip._vendor.packaging.tagsr pip._vendor.packaging.utilsr Zpip._vendor.packaging.versionr r rpip._internal.exceptionsrrrrpip._internal.index.collectorrrpip._internal.models.candidater#pip._internal.models.format_controlrpip._internal.models.linkr!pip._internal.models.search_scoper$pip._internal.models.selection_prefsr"pip._internal.models.target_pythonrpip._internal.models.wheelrpip._internal.reqrZpip._internal.utils._logrpip._internal.utils.filetypesrpip._internal.utils.hashesrpip._internal.utils.loggingrpip._internal.utils.miscr pip._internal.utils.packagingr!pip._internal.utils.unpackingr"pip._internal.utils.urlsr#__all__rfr.rr2BuildTagrrlr7r8rrr$rr%rrVr&r&r&r6s~$                       /  J(M~