U ʗReܒ@sjdZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZddlmZddlmZdd lmZmZmZmZdd lmZmZdd l m!Z!dd l"m#Z#dd l$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddle1e?Z@e e de eAeBffZCe eAeAeAee eAeCfZDd4e%e eAeAeAfeEeEdd d!ZFGd"d#d#ejGZHGd$d%d%ZIe e!e5eBe e!d&d'd(ZJGd)d*d*ZKGd+ddZLGd,d-d-ZMGd.ddZNeBeBeAd/d0d1ZOeBeBe eBd/d2d3ZPdS)5z!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_EXTENSIONSrBestCandidateResult PackageFinderF)link version_infoignore_requires_pythonreturncCs~zt|j|d}Wn&tjk r8td|j|YnBX|szdtt|}|sht 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-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_internal/index/package_finder.py_check_link_requires_python3s8  r6c@sDeZdZeZeZeZeZeZ eZ eZ dS)LinkTypeN) __name__ __module__ __qualname__enumauto candidatedifferent_projectyankedformat_unsupportedformat_invalidplatform_mismatchrequires_python_mismatchr%r%r%r5r7bsr7c @sVeZdZdZedZd eeeee e e e ddddZ e eeefddd ZdS) LinkEvaluatorzD Responsible for evaluating links for a particular project. z-py([123]\.?[0-9]?)$N) project_namecanonical_nameformats target_python allow_yankedr(r)cCs4|dkr d}||_||_||_||_||_||_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_pythonrE)selfrErFrGrHrIr(r%r%r5__init__xszLinkEvaluator.__init__)r&r)c CsBd}|jr*|js*|jpd}tjd|fS|jr@|j}|j}n|\}}|sZtjdfS|t krrtjd|fSd|j kr|t krd|j }tj|fSd|j kr|d krtjd fS|t krXzt|j}Wntk rtjd fYSXt|j|jkrd |j d }tj|fS|j}||sRd|}d|d}tj|fS|j}d|j kr|t krd|j }tj|fS|st||j}|sd|j }tj|fS|j|} | r|d| }| !d} | |jj"krtjdfSt#||jj$|j%d} | s*|d|j&}tj'|fSt()d||tj*|fS)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 zyanked for reason: z not a filezunsupported archive format: binaryzNo binaries permitted for macosx10z.zipz macosx10 onezinvalid wheel filenamezwrong project name (not ), znone of the wheel's tags (zB) are compatible (run pip debug --verbose to show compatible tags)sourcezNo sources permitted for zMissing project version for zPython version is incorrect)r'r(z Requires-Python zFound link %s, version: %s)+ is_yankedrJ yanked_reasonr7r? egg_fragmentextsplitextr@r"rMrrEpathrfilenamerrAr namerKr>rNget_tags supportedr/get_formatted_file_tagsrBr4_extract_version_from_fragment_py_version_researchstartgroup py_versionr6py_version_inforLr+rCr-r.r=) rOr&r4reasonegg_inforZwheelsupported_tags file_tagsmatchrgsupports_pythonr%r%r5 evaluate_links                       zLinkEvaluator.evaluate_link)N)r8r9r:__doc__recompilercr1rrboolrrPrrr7rpr%r%r%r5rDls  %rD) candidateshashesrEr)c Cs|stdt||t|Sg}g}d}|D]>}|j}|js@n"|j|drV|d7}n ||q.||q.|rx|}nt|}t|t|krd} n dt|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)rvrVzdiscarding no candidateszdiscarding {} non-matches: {}z css|]}t|jVqdSN)r1r&).0r=r%r%r5 5sz*filter_unallowed_hashes..zPChecked %s links for project %r against %s hashes (%s matches, %s no digest): %s) r-r.lenlistr&has_hashis_hash_allowedappendformatr/ digest_count) rurvrEmatches_or_no_digest non_matches match_countr=r&filtereddiscard_messager%r%r5filter_unallowed_hashessL      rc@s$eZdZdZdeeddddZdS)CandidatePreferenceszk Encapsulates some of the preferences for filtering and sorting InstallationCandidate objects. FN) prefer_binaryallow_all_prereleasesr)cCs||_||_dS)zR :param allow_all_prereleases: Whether to allow all pre-releases. N)rr)rOrrr%r%r5rPMszCandidatePreferences.__init__)FF)r8r9r:rqrtrPr%r%r%r5rFsrc@sTeZdZdZeeeeeeddddZeedddZ eedd 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. N)ruapplicable_candidatesbest_candidater)cCsHt|t|kst|dkr&|r2tn ||ks2t||_||_||_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)setAssertionError_applicable_candidates _candidatesrrOrurrr%r%r5rP`s   zBestCandidateResult.__init__r)cCs t|jS)zIterate through all candidates.)iterrrOr%r%r5iter_allxszBestCandidateResult.iter_allcCs t|jS)z*Iterate through the applicable candidates.)rrrr%r%r5iter_applicable|sz#BestCandidateResult.iter_applicable) r8r9r:rqrrrrPrrrr%r%r%r5r#Ys c @seZdZdZedeeeeeee j ee ddddZ dee ee j eeee dddd Ze ee ed d d Zeed ddZe eeed ddZe eed ddZdS)CandidateEvaluatorzm Responsible for filtering and sorting candidates for installation based on what tags are valid. NF)rErHrr specifierrvr)cCs:|dkrt}|dkrt}|}|||||||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)rErlrrrrv)rr SpecifierSetr_)clsrErHrrrrvrlr%r%r5createszCandidateEvaluator.create)rErlrrrrvr)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%)rxidxtagr%r%r5 sz/CandidateEvaluator.__init__..N)_allow_all_prereleases_hashes_prefer_binary _project_name _specifier_supported_tags enumerate_wheel_tag_preferences)rOrErlrrrrvr%r%r5rPs zCandidateEvaluator.__init__)rur)csd|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%)r1)rxvr%r%r5 sz?CandidateEvaluator.get_applicable_candidates..css|]}t|jVqdSrwr1r4rxcr%r%r5rysz?CandidateEvaluator.get_applicable_candidates..) prereleasescsg|]}t|jkr|qSr%rrversionsr%r5 sz@CandidateEvaluator.get_applicable_candidates..)rurvrEkey)rrfilterrrrsorted _sort_key)rOruallow_prereleasesrrfiltered_applicable_candidatesr%rr5get_applicable_candidatess  z,CandidateEvaluator.get_applicable_candidates)r=r)c Cs|j}t|}d}d}|j}|jrt|j}z|||j }Wn$tk rdt d |jYnX|j rpd}|j dk rt 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.rVNz ^(\d+)(.*)$)rrzr&is_wheelrr]find_most_preferred_tagr ValueErrorrrr build_tagrrrngroupsintr}rrWr4) rOr= valid_tags support_numrbinary_preferencer&rkprirnbuild_tag_groupshas_allowed_hash yank_valuer%r%r5rsF   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)rOrurr%r%r5sort_best_candidate.sz&CandidateEvaluator.sort_best_candidatecCs"||}||}t|||dS)zF Compute and return a `BestCandidateResult` instance. )rr)rrr#rr%r%r5compute_best_candidate;s  z)CandidateEvaluator.compute_best_candidate)NFFNN)FFN)r8r9r:rq classmethodr1rrrtr BaseSpecifierrrrr rPrrCandidateSortingKeyrrr#rr%r%r%r5rsL(  $F rc @s(eZdZdZd=eeeeeee eeddddZ e d>ee eeddddZ eed d d Zeed d d Zejedddd Zeeed ddZeeed ddZeeed ddZeed ddZdd ddZeed ddZdd ddZeed ddZeed d!d"Zee ee d#d$d%Z!e e"edd&d'd(Z#ee ee$d)d*d+Z%eee ee$d,d-d.Z&e eee$d/d0d1Z'e(j)dd2eee$d d3d4Z*d?eee+j,ee-e.d5d6d7Z/e(j)dd2d@eee+j,ee-e0d5d8d9Z1e2eee$d:d;d<Z3dS)Ar$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_collectorrHrIformat_controlcandidate_prefsr(r)cCsP|dkrt}|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) rrrrJ_candidate_prefsrL_link_collectorrNr _logged_links)rOrrHrIrrr(r%r%r5rPTszPackageFinder.__init__)rselection_prefsrHr)cCs8|dkrt}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)rrrHrIrr()rrrrrIrr()rrrrHrr%r%r5r{szPackageFinder.creatercCs|jSrw)rNrr%r%r5rHszPackageFinder.target_pythoncCs|jjSrwr search_scoperr%r%r5rszPackageFinder.search_scope)rr)cCs ||j_dSrwr)rOrr%r%r5rscCs|jjSrw)r find_linksrr%r%r5rszPackageFinder.find_linkscCs|jjSrw)r index_urlsrr%r%r5rszPackageFinder.index_urlsccs|jjjD]}t|Vq dSrw)rsessionpip_trusted_originsr )rO host_portr%r%r5 trusted_hostsszPackageFinder.trusted_hostscCs|jjSrwrrrr%r%r5rsz#PackageFinder.allow_all_prereleasescCs d|j_dSNTrrr%r%r5set_allow_all_prereleasessz'PackageFinder.set_allow_all_prereleasescCs|jjSrwrrrr%r%r5rszPackageFinder.prefer_binarycCs d|j_dSrrrr%r%r5set_prefer_binaryszPackageFinder.set_prefer_binarycCsdd|jD}t|S)NcSs h|]\}}}|tjkr|qSr%)r7rC)rx_resultdetailr%r%r5rs z@PackageFinder.requires_python_skipped_reasons..)rr)rOreasonsr%r%r5requires_python_skipped_reasonssz-PackageFinder.requires_python_skipped_reasons)rEr)cCs.t|}|j|}t||||j|j|jdS)N)rErFrGrHrIr()r rget_allowed_formatsrDrNrJrL)rOrErFrGr%r%r5make_link_evaluators z!PackageFinder.make_link_evaluator)linksr)cCsPgg}}t}|D]2}||kr|||jr<||q||q||S)z Returns elements of links in order, non-egg links first, egg links second, while eliminating duplicates )raddrYr~)rOreggsno_eggsseenr&r%r%r5 _sort_linkss    zPackageFinder._sort_links)r&rrr)cCs2|||f}||jkr.td|||j|dS)NzSkipping link: %s: %s)rr-r.r)rOr&rrentryr%r%r5_log_skipped_links  zPackageFinder._log_skipped_link)link_evaluatorr&r)cCs:||\}}|tjkr*||||dSt|j||dS)z If the link is a candidate for install, convert it to an InstallationCandidate and return it. Otherwise, return None. N)r^r&r4)rpr7r=rrrE)rOrr&rrr%r%r5get_install_candidates z#PackageFinder.get_install_candidate)rrr)cCs6g}||D]"}|||}|dk r||q|S)zU Convert links that are candidates to InstallationCandidate objects. N)rrr~)rOrrrur&r=r%r%r5evaluate_linkss   zPackageFinder.evaluate_links) project_urlrr)c CsTtd||j|}|dkr$gStt|}t|j||d}W5QRX|S)Nz-Fetching project page and analyzing links: %s)r)r-r.rfetch_responser{rrr)rOrrindex_response page_links package_linksr%r%r5process_project_urls  z!PackageFinder.process_project_url)maxsizec Cs||}|jj|tj|j|dd}tjdd|D}t |}tjdd|D}| |t |dd}t tjr|rg}|D]F} | jjstz|| jjWqtk r|| jjYqXqt dd |||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)rEcandidates_from_pagecss(|] }|D]}|dk r |Vq qdSrw)page_candidatesrxsourcesrUr%r%r5ry8s z4PackageFinder.find_all_candidates..css(|] }|D]}|dk r |Vq qdSrw) file_linksrr%r%r5ry@s T)reversezLocal files found: %srT)rrcollect_sources functoolspartialr itertoolschain from_iterabler{rrr- isEnabledForloggingDEBUGr&urlrr~ file_path Exceptionr.r/) rOrErcollected_sourcespage_candidates_itr file_links_itfile_candidatespathsr=r%r%r5find_all_candidates$s:     z!PackageFinder.find_all_candidates)rErrvr)cCs"|j}tj||j|j|j||dS)z*Create a CandidateEvaluator object to use.)rErHrrrrv)rrrrNrr)rOrErrvrr%r%r5make_candidate_evaluatorYsz&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. )rErrv)rrr)rOrErrvrucandidate_evaluatorr%r%r5find_best_candidatejs z!PackageFinder.find_best_candidate)requpgrader)c Cs|jdd}|j|j|j|d}|j}d}|jdk r<|jj}ttt ddd}|dkr|dkrt d||| t d |d}|r|dks|j|krd }|s|dk r|rt d |nt d ||jdS|rt 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)rrvN) cand_iterr)cSs dtdd|DtdpdS)NrTcSsh|]}t|jqSr%rrr%r%r5rszKPackageFinder.find_requirement.._format_versions..rnone)r/r parse_version)rr%r%r5_format_versionss 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))rvrr^rr satisfied_byr4rrr1r-criticalrrrr.rr) rOrrrvbest_candidate_resultrinstalled_versionrbest_installedr%r%r5find_requirementsh      zPackageFinder.find_requirement)NNN)N)NN)NN)4r8r9r:rqrrrtrrrrPrrrpropertyrHrrsetterrr1rrrrrrrrrrDrrrr7rrrrrr lru_cacherr rrrrr#rrrr%r%r%r5r$Ms  '      7  )fragmentrFr)cCsNt|D].\}}|dkrqt|d||kr|Sqt|d|dS)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)r#rFirr%r%r5_find_name_version_seps  r&cCsBzt||d}Wntk r(YdSX||d}|s>dS|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. rVN)r&r)r#rF version_startr4r%r%r5rbs rb)F)Qrqr;rrrrrtypingrrrrrrrZpip._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"__all__r8r-rr1BuildTagrrtr6Enumr7rDrrr#rr$r&rbr%r%r%r5sr$                       /  J(M