ReB@sdZddlmZddlZddlZddlmZddlmZddl m Z ddl m Z mZmZmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.e*rNddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9ddl m:Z:ddlm;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAe7e6fe6eBeCffZDe6eBeBeBe:eDe3eBfZEddd gZFejGeHZId!d"d#ZJGd$d%d%eKZLd&d'ZMGd(d)d)eKZNGd*ddeKZOGd+d,d,eKZPGd-d d eKZQd.d/ZRd0d1ZSdS)2z!Routines related to PyPI, indexes)absolute_importN) specifiers)canonicalize_name)parse)BestVersionAlreadyInstalledDistributionNotFoundInvalidWheelFilenameUnsupportedWheel) parse_links)InstallationCandidate) FormatControl)Link)SelectionPreferences) TargetPython)Wheel) lru_cache)WHEEL_EXTENSION) indent_log) build_netloc)check_requires_python)MYPY_CHECK_RUNNING)SUPPORTED_EXTENSIONS) url_to_path) FrozenSetIterableListOptionalSetTextTupleUnion)Tag) _BaseVersion) LinkCollector) SearchScope)InstallRequirement)Hashesr BestCandidateResult PackageFinderFc Csyt|jd|}Wn+tjk rFtjd|j|Yn[X|sdjtt|}|stjd||j|dStjd||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. version_infoz2Ignoring 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) rrequires_pythonrInvalidSpecifierloggerdebugjoinmapstr)linkr)ignore_requires_python is_compatibleversionr6/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/index/package_finder.py_check_link_requires_python>s$r8c@s@eZdZdZejdZdddZddZdS) LinkEvaluatorzD Responsible for evaluating links for a particular project. z-py([123]\.?[0-9]?)$NcCsL|dkrd}||_||_||_||_||_||_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_python project_name)selfr?canonical_nameformats target_python allow_yankedr3r6r6r7__init__us      zLinkEvaluator.__init__c Csd}|jr;|j r;|jp%d}ddj|fS|jrY|j}|j}nR|j\}}|sudS|tkrddj|fSd|jkr|t krdj|j }d|fSd |j kr|d krdS|t kryt |j }Wntk r!dSYnXt|j|jkrVd j|j }d|fS|jj}|j|s|j}djdj|}d|fS|j}d|jkr|t krdj|j }d|fS|st||j}|sdj|j }d|fS|jj|} | ro|d| j}| jd} | |jjkrodSt|d|jjd|j } | sdSt!j"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: {} not a filezunsupported archive format: {}binaryzNo binaries permitted for {}macosx10z.zip macosx10 oneinvalid wheel filenamezwrong project name (not {})z"none of the wheel's tags match: {}z, sourcezNo sources permitted for {}zMissing project version for {}Python version is incorrectr)r3zFound link %s, version: %sT)FrF)FrI)FrJ)FrM)FN)# is_yankedr: yanked_reasonformat egg_fragmentextsplitextrr=rr?pathrfilenamerrnamer;r>get_tags supportedget_formatted_file_tagsr/r5_extract_version_from_fragment_py_version_researchstartgroup py_versionr8py_version_infor<r-r.) r@r2r5reasonegg_inforRwheelsupported_tags file_tagsmatchr_supports_pythonr6r6r7 evaluate_linksp                  zLinkEvaluator.evaluate_link) __name__ __module__ __qualname____doc__recompiler[rErhr6r6r6r7r9is  r9c Cs=|s)tjdt||t|Sg}g}d}x_|D]W}|j}|js]n/|jd|r||d7}n|j|qB|j|qBW|r|}n t|}t|t|krd} n.djt|dj dd |D} tjd 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 candidatesrhashesrLzdiscarding no candidateszdiscarding {} non-matches: {}z css|]}t|jVqdS)N)r1r2).0 candidater6r6r7 0sz*filter_unallowed_hashes..zPChecked %s links for project %r against %s hashes (%s matches, %s no digest): %s) r-r.lenlistr2has_hashis_hash_allowedappendrPr/ digest_count) candidatesror?matches_or_no_digest non_matches match_countrqr2filtereddiscard_messager6r6r7filter_unallowed_hashessF             rc@s(eZdZdZddddZdS)CandidatePreferenceszk Encapsulates some of the preferences for filtering and sorting InstallationCandidate objects. FcCs||_||_dS)zR :param allow_all_prereleases: Whether to allow all pre-releases. N)allow_all_prereleases prefer_binary)r@rrr6r6r7rEHs zCandidatePreferences.__init__N)rirjrkrlrEr6r6r6r7rAs rc@s:eZdZdZddZddZddZdS) 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. cCskt|t|kst|dkr:| sLtn||ksLt||_||_||_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 _candidatesbest_candidate)r@ryapplicable_candidatesrr6r6r7rE\s    zBestCandidateResult.__init__cCs t|jS)z(Iterate through all candidates. )iterr)r@r6r6r7iter_alluszBestCandidateResult.iter_allcCs t|jS)z3Iterate through the applicable candidates. )rr)r@r6r6r7iter_applicable{sz#BestCandidateResult.iter_applicableN)rirjrkrlrErrr6r6r6r7r'Us   c@s|eZdZdZedddddddZdddddZdd Zd d Zd d Z ddZ dS)CandidateEvaluatorzm Responsible for filtering and sorting candidates for installation based on what tags are valid. NFc Csd|dkrt}|dkr-tj}|j}|d|d|d|d|d|d|S)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. Nr?rd specifierrrro)rr SpecifierSetrW)clsr?rCrrrrordr6r6r7creates     zCandidateEvaluator.createcCs:||_||_||_||_||_||_dS)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)r@r?rdrrrror6r6r7rEs      zCandidateEvaluator.__init__cs|jp d}|j}dd|jdd|Dd|Dfdd|D}td |d |jd |j}t|d |jS) zM Return the applicable candidates from a list of candidates. NcSsh|]}t|qSr6)r1)rpvr6r6r7 s z?CandidateEvaluator.get_applicable_candidates..css|]}t|jVqdS)N)r1r5)rpcr6r6r7rrsz?CandidateEvaluator.get_applicable_candidates.. prereleasescs+g|]!}t|jkr|qSr6)r1r5)rpr)versionsr6r7 s z@CandidateEvaluator.get_applicable_candidates..ryror?key)rrfilterrrrsorted _sort_key)r@ryallow_prereleasesrrfiltered_applicable_candidatesr6)rr7get_applicable_candidatess      z,CandidateEvaluator.get_applicable_candidatesc Cs |j}t|}f}d}|j}|jrt|j}|j|sitdj|j|j rxd}|j | }|j dk rt j d|j } | j} t| d| df}n| }t|j|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 rzB{} is not a supported wheel for this platform. It can't be sorted.rLNz ^(\d+)(.*)$)rrsr2is_wheelrrUrXr rPrsupport_index_min build_tagrmrfgroupsintrvrrNr5) r@rq valid_tags support_numrbinary_preferencer2rcprirfbuild_tag_groupshas_allowed_hash yank_valuer6r6r7rs.      zCandidateEvaluator._sort_keycCs#|s dSt|d|j}|S)zy Return the best candidate per the instance's sort order, or None if no candidate is acceptable. Nr)maxr)r@ryrr6r6r7sort_best_candidate%s z&CandidateEvaluator.sort_best_candidatecCs4|j|}|j|}t|d|d|S)zF Compute and return a `BestCandidateResult` instance. rr)rrr')r@ryrrr6r6r7compute_best_candidate3s z)CandidateEvaluator.compute_best_candidate) rirjrkrl classmethodrrErrrrr6r6r6r7rs " & < rc@s~eZdZdZdddddZedddZeddZed d Z e j d d Z ed d Z eddZ eddZ eddZddZeddZddZddZddZddZd d!Zd"d#Zd$d%Zed&dd'd(Zddd)d*Zddd+d,Zd-d.ZdS)/r(zThis finds packages. This is meant to match easy_install's technique for looking for packages, by reading pages and looking for appropriate links. NcCsv|dkrt}|p-ttt}||_||_||_||_||_||_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) rr rr:_candidate_prefsr<_link_collectorr>format_control _logged_links)r@link_collectorrCrDrcandidate_prefsr3r6r6r7rEMs        zPackageFinder.__init__c Csd|dkrt}td|jd|j}|d|d|d|d|jd|jd |jS) 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. NrrrrrCrDrr3)rrrrrDrr3)rrselection_prefsrCrr6r6r7rus      zPackageFinder.createcCs|jS)N)r>)r@r6r6r7rCszPackageFinder.target_pythoncCs |jjS)N)r search_scope)r@r6r6r7rszPackageFinder.search_scopecCs||j_dS)N)rr)r@rr6r6r7rscCs |jjS)N)r find_links)r@r6r6r7rszPackageFinder.find_linkscCs |jjS)N)r index_urls)r@r6r6r7rszPackageFinder.index_urlsccs)x"|jjjD]}t|VqWdS)N)rsessionpip_trusted_originsr)r@ host_portr6r6r7 trusted_hostsszPackageFinder.trusted_hostscCs |jjS)N)rr)r@r6r6r7rsz#PackageFinder.allow_all_prereleasescCsd|j_dS)NT)rr)r@r6r6r7set_allow_all_prereleasessz'PackageFinder.set_allow_all_prereleasescCs |jjS)N)rr)r@r6r6r7rszPackageFinder.prefer_binarycCsd|j_dS)NT)rr)r@r6r6r7set_prefer_binaryszPackageFinder.set_prefer_binaryc CsRt|}|jj|}td|d|d|d|jd|jd|jS)Nr?rArBrCrDr3)rrget_allowed_formatsr9r>r:r<)r@r?rArBr6r6r7make_link_evaluators   z!PackageFinder.make_link_evaluatorcCsngg}}t}xM|D]E}||kr|j||jrU|j|q|j|qW||S)z Returns elements of links in order, non-egg links first, egg links second, while eliminating duplicates )raddrQrw)r@linkseggsno_eggsseenr2r6r6r7 _sort_linkss      zPackageFinder._sort_linkscCs6||jkr2tjd|||jj|dS)NzSkipping link: %s: %s)rr-r.r)r@r2rar6r6r7_log_skipped_linkszPackageFinder._log_skipped_linkcCsZ|j|\}}|s8|r4|j|d|dStd|jd|dt|S)z If the link is a candidate for install, convert it to an InstallationCandidate and return it. Otherwise, return None. raNrVr2r5)rhrr r?r1)r@link_evaluatorr2 is_candidateresultr6r6r7get_install_candidates z#PackageFinder.get_install_candidatecCsOg}xB|j|D]1}|j||}|dk r|j|qW|S)zU Convert links that are candidates to InstallationCandidate objects. N)rrrw)r@rrryr2rqr6r6r7evaluate_linkss  zPackageFinder.evaluate_linksc Csntjd||jj|}|dkr2gStt|}t|j|d|}WdQRX|S)Nz-Fetching project page and analyzing links: %sr)r-r.r fetch_pagertr rr)r@ project_urlr html_page page_links package_linksr6r6r7process_project_urls   z!PackageFinder.process_project_urlmaxsizec Cs|jj|}|j|}|j|d|j}g}x3|jD](}|j|d|}|j|qIW|j|d|j}|r|j ddt j ddj dd|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. rrreverseTzLocal files found: %sz, cSs"g|]}t|jjqSr6)rr2url)rprqr6r6r7rIs z5PackageFinder.find_all_candidates..) r collect_linksrrr project_urlsrextendfilessortr-r.r/) r@r?collected_linksrfind_links_versions page_versionsrr file_versionsr6r6r7find_all_candidates%s*    z!PackageFinder.find_all_candidatesc Cs@|j}tjd|d|jd|jd|jd|d|S)z3Create a CandidateEvaluator object to use. r?rCrrrro)rrrr>rr)r@r?rrorr6r6r7make_candidate_evaluatorQs     z&PackageFinder.make_candidate_evaluatorcCs:|j|}|jd|d|d|}|j|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. r?rro)rrr)r@r?rrorycandidate_evaluatorr6r6r7find_best_candidateds   z!PackageFinder.find_best_candidatec Cs|jdd}|j|jd|jd|}|j}d}|jdk rct|jj}dd}|dkr|dkrtj d|||j t d j |d}|r|dks|j|krd }| r.|dk r.|rtj d |ntj d ||jdS|rYtj d |||jttj d|j||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 trust_internetFrroNcSs,djtdd|Ddtp+dS)Nz, cSsh|]}t|jqSr6)r1r5)rprr6r6r7rs zKPackageFinder.find_requirement.._format_versions..rnone)r/r parse_version) cand_iterr6r6r7_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))rorrVrr satisfied_byrr5r-criticalrrrPr.rr) r@requpgraderobest_candidate_resultrinstalled_versionrbest_installedr6r6r7find_requirement{sT      zPackageFinder.find_requirement)rirjrkrlrErrpropertyrCrsetterrrrrrrrrrrrrrrrrrrr6r6r6r7r(Fs8 !      /cCshxIt|D];\}}|dkr(q t|d||kr |Sq Wtdj||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 {}) enumerater ValueErrorrP)fragmentrAirr6r6r7_find_name_version_seps  rc CsNyt||d}Wntk r/dSYnX||d}|sJdS|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. rLN)rr)rrA version_startr5r6r6r7rZs   rZ)Trl __future__rloggingrmZpip._vendor.packagingrZpip._vendor.packaging.utilsrpip._vendor.packaging.versionrrpip._internal.exceptionsrrrr pip._internal.index.collectorr pip._internal.models.candidater #pip._internal.models.format_controlr pip._internal.models.linkr $pip._internal.models.selection_prefsr"pip._internal.models.target_pythonrpip._internal.models.wheelrpip._internal.utils.compatrpip._internal.utils.filetypesrpip._internal.utils.loggingrpip._internal.utils.miscrpip._internal.utils.packagingrpip._internal.utils.typingrpip._internal.utils.unpackingrpip._internal.utils.urlsrtypingrrrrrrrr pip._vendor.packaging.tagsr!r"r#!pip._internal.models.search_scoper$Zpip._internal.reqr%pip._internal.utils.hashesr&rr1ZBuildTagZCandidateSortingKey__all__ getLoggerrir-r8objectr9rrr'rr(rrZr6r6r6r7sX  ": ( K-