3 ”ReB’ã@s@dZddlmZddlZddlZddlmZddlmZddl 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*�r¶ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9ddl m:Z:ddlm;Z;ddlm?Z?ddl@mAZAe7e6fe6eBeCffZDe6eBeBeBe:eDe3eBfZEddd gZFejGeHƒZId2d"d#„ZJGd$d%„d%eKƒZLd&d'„ZMGd(d)„d)eKƒZNGd*d„deKƒZOGd+d,„d,eKƒZPGd-d „d eKƒZQd.d/„ZRd0d1„ZSdS)3z!Routines related to PyPI, indexesé)Úabsolute_importN)Ú specifiers)Úcanonicalize_name)Úparse)ÚBestVersionAlreadyInstalledÚDistributionNotFoundÚInvalidWheelFilenameÚUnsupportedWheel)Ú 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)Ú FrozenSetÚIterableÚListÚOptionalÚSetÚTextÚTupleÚUnion)ÚTag)Ú _BaseVersion)Ú LinkCollector)Ú SearchScope)ÚInstallRequirement)ÚHashesr ÚBestCandidateResultÚ PackageFinderFc Cs~yt|j|d�}Wn&tjk r8tjd|j|ƒYnBX|szdjtt|ƒƒ}|shtjd||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) rÚrequires_pythonrÚInvalidSpecifierÚloggerÚdebugÚjoinÚmapÚstr)Úlinkr)Úignore_requires_pythonÚ is_compatibleÚversion©r6ú‘/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/index/package_finder.pyÚ_check_link_requires_python>s$  r8c@s,eZdZdZejdƒZddd„Zdd„ZdS) Ú LinkEvaluatorzD Responsible for evaluating links for a particular project. z-py([123]\.?[0-9]?)$NcCs4|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_pythonÚ project_name)Úselfr?Úcanonical_nameÚformatsÚ target_pythonÚ allow_yankedr3r6r6r7Ú__init__uszLinkEvaluator.__init__c Csþd}|jr*|j r*|jpd}ddj|ƒfS|jr@|j}|j}�nö|jƒ\}}|sTdS|tkrjddj|ƒfSd|jkr�|t kr�dj|j ƒ}d|fSd |j kr¦|d kr¦dS|t k�r6yt |j ƒ}Wntk rÒdSXt|jƒ|jk�rúd j|j ƒ}d|fS|jjƒ}|j|ƒ�s0|jƒ}djdj|ƒƒ}d|fS|j}d|jk�r`|t k�r`dj|j ƒ}d|fS|�srt||jƒ}|�sŒdj|j ƒ}d|fS|jj|ƒ} | �rÊ|d| jƒ…}| jdƒ} | |jjk�rÊdSt||jj|j d�} | �sèdSt!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 oneúinvalid 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 incorrect)r)r3zFound link %s, version: %sT)FrF)FrI)FrJ)FrM)FN)#Ú is_yankedr:Ú yanked_reasonÚformatÚ egg_fragmentÚextÚsplitextrr=rr?ÚpathrÚfilenamerrÚnamer;r>Úget_tagsÚ supportedÚget_formatted_file_tagsr/r5Ú_extract_version_from_fragmentÚ_py_version_reÚsearchÚstartÚgroupÚ py_versionr8Úpy_version_infor<r-r.) r@r2r5ÚreasonÚegg_inforRÚwheelÚsupported_tagsÚ file_tagsÚmatchr_Úsupports_pythonr6r6r7Ú evaluate_link›sp              zLinkEvaluator.evaluate_link)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚreÚcompiler[rErhr6r6r6r7r9is r9c Csâ|stjdt|ƒ|ƒt|ƒSg}g}d}xF|D]>}|j}|jsBn"|j|d�rX|d7}n |j|ƒq0|j|ƒq0W|r||}nt|ƒ}t|ƒt|ƒkršd} 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 candidatesr)ÚhashesrLzdiscarding no candidateszdiscarding {} non-matches: {}z css|]}t|jƒVqdS)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.ÚlenÚlistr2Úhas_hashÚis_hash_allowedÚappendrPr/Ú digest_count) Ú candidatesror?Úmatches_or_no_digestÚ non_matchesÚ match_countrqr2ÚfilteredÚdiscard_messager6r6r7Úfilter_unallowed_hashesösF     rc@seZdZdZddd„ZdS)Ú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@r‚r�r6r6r7rEHs zCandidatePreferences.__init__N)FF)rirjrkrlrEr6r6r6r7r€Asr€c@s(eZdZdZdd„Zdd„Zdd„ZdS) r'zÄA collection of candidates, returned by `PackageFinder.find_best_candidate`. This class is only intended to be instantiated by CandidateEvaluator's `compute_best_candidate()` method. cCsJt|ƒt|ƒkst‚|dkr(| s4t‚n ||ks4t‚||_||_||_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ÚAssertionErrorÚ_applicable_candidatesÚ _candidatesÚbest_candidate)r@ryÚapplicable_candidatesr‡r6r6r7rE\s   zBestCandidateResult.__init__cCs t|jƒS)z(Iterate through all candidates. )Úiterr†)r@r6r6r7Úiter_alluszBestCandidateResult.iter_allcCs t|jƒS)z3Iterate through the applicable candidates. )r‰r…)r@r6r6r7Úiter_applicable{sz#BestCandidateResult.iter_applicableN)rirjrkrlrErŠr‹r6r6r6r7r'Usc@sHeZdZdZeddd„ƒZddd„Zdd „Zd d „Zd d „Z dd„Z dS)ÚCandidateEvaluatorzm Responsible for filtering and sorting candidates for installation based on what tags are valid. NFcCs:|dkrtƒ}|dkrtjƒ}|jƒ}|||||||d�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. N)r?rdÚ specifierr‚r�ro)rrÚ SpecifierSetrW)Úclsr?rCr‚r�r�rordr6r6r7Úcreate‰szCandidateEvaluator.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?rdr�r‚r�ror6r6r7rE®s zCandidateEvaluator.__init__csd|jpd}|j}dd„|jdd„|Dƒ|d�Dƒ‰‡fdd„|Dƒ}t||j|jd �}t||jd �S) zM Return the applicable candidates from a list of candidates. NcSsh|] }t|ƒ’qSr6)r1)rpÚvr6r6r7ú Îsz?CandidateEvaluator.get_applicable_candidates..css|]}t|jƒVqdS)N)r1r5)rpÚcr6r6r7rr×sz?CandidateEvaluator.get_applicable_candidates..)Ú prereleasescsg|]}t|jƒˆkr|‘qSr6)r1r5)rpr™)Úversionsr6r7ú Þsz@CandidateEvaluator.get_applicable_candidates..)ryror?)Úkey)r‘r•Úfilterrr’r”ÚsortedÚ _sort_key)r@ryÚallow_prereleasesr�rˆÚfiltered_applicable_candidatesr6)r›r7Úget_applicable_candidatesÃs    z,CandidateEvaluator.get_applicable_candidatesc CsÈ|j}t|ƒ}f}d}|j}|jr’t|jƒ}|j|ƒsFtdj|jƒƒ‚|j rPd}|j |ƒ }|j dk r˜t 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+)(.*)$éÿÿÿÿ)r–rsr2Úis_wheelrrUrXr rPr“Úsupport_index_minÚ build_tagrmrfÚgroupsÚintrvr’rNr5) r@rqÚ valid_tagsÚ support_numr§Úbinary_preferencer2rcÚprirfÚbuild_tag_groupsÚhas_allowed_hashÚ yank_valuer6r6r7r és.      zCandidateEvaluator._sort_keycCs|sdSt||jd�}|S)zy Return the best candidate per the instance's sort order, or None if no candidate is acceptable. N)r�)Úmaxr )r@ryr‡r6r6r7Úsort_best_candidate%s z&CandidateEvaluator.sort_best_candidatecCs"|j|ƒ}|j|ƒ}t|||d�S)zF Compute and return a `BestCandidateResult` instance. )rˆr‡)r£r²r')r@ryrˆr‡r6r6r7Úcompute_best_candidate3s   z)CandidateEvaluator.compute_best_candidate)NFFNN)FFN) rirjrkrlÚ classmethodr�rEr£r r²r³r6r6r6r7rŒ‚s " &<rŒc@søeZdZdZd/dd„Zed0dd„ƒZedd„ƒZed d „ƒZ e j d d „ƒZ ed d „ƒZ edd„ƒZ edd„ƒZ edd„ƒZdd„Zedd„ƒZdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zedd&�d'd(„ƒZd1d)d*„Zd2d+d,„Zd-d.„ZdS)3r(z This finds packages. This is meant to match easy_install's technique for looking for packages, by reading pages and looking for appropriate links. NcCsP|dkrtƒ}|pttƒtƒƒ}||_||_||_||_||_||_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) r€r rƒr:Ú_candidate_prefsr<Ú_link_collectorr>Úformat_controlÚ _logged_links)r@Úlink_collectorrCrDr·Úcandidate_prefsr3r6r6r7rEMszPackageFinder.__init__cCs8|dkrtƒ}t|j|jd�}|||||j|j|jd�S)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)r‚r�)rºr¹rCrDr·r3)rr€r‚r�rDr·r3)r�r¹Úselection_prefsrCrºr6r6r7r�us zPackageFinder.createcCs|jS)N)r>)r@r6r6r7rC–szPackageFinder.target_pythoncCs|jjS)N)r¶Ú search_scope)r@r6r6r7r¼›szPackageFinder.search_scopecCs ||j_dS)N)r¶r¼)r@r¼r6r6r7r¼ scCs|jjS)N)r¶Ú find_links)r@r6r6r7r½¥szPackageFinder.find_linkscCs|jjS)N)r¼Ú index_urls)r@r6r6r7r¾ªszPackageFinder.index_urlsccs"x|jjjD]}t|ŽVq WdS)N)r¶ÚsessionÚpip_trusted_originsr)r@Ú host_portr6r6r7Ú trusted_hosts¯szPackageFinder.trusted_hostscCs|jjS)N)rµr�)r@r6r6r7r�µsz#PackageFinder.allow_all_prereleasescCs d|j_dS)NT)rµr�)r@r6r6r7Úset_allow_all_prereleasesºsz'PackageFinder.set_allow_all_prereleasescCs|jjS)N)rµr‚)r@r6r6r7r‚¾szPackageFinder.prefer_binarycCs d|j_dS)NT)rµr‚)r@r6r6r7Úset_prefer_binaryÃszPackageFinder.set_prefer_binarycCs.t|ƒ}|jj|ƒ}t||||j|j|jd�S)N)r?rArBrCrDr3)rr·Úget_allowed_formatsr9r>r:r<)r@r?rArBr6r6r7Úmake_link_evaluatorÇs z!PackageFinder.make_link_evaluatorcCsTgg}}tƒ}x:|D]2}||kr|j|ƒ|jr>|j|ƒq|j|ƒqW||S)z� Returns elements of links in order, non-egg links first, egg links second, while eliminating duplicates )rƒÚaddrQrw)r@ÚlinksÚeggsÚno_eggsÚseenr2r6r6r7Ú _sort_linksÕs    zPackageFinder._sort_linkscCs(||jkr$tjd||ƒ|jj|ƒdS)NzSkipping link: %s: %s)r¸r-r.rÇ)r@r2rar6r6r7Ú_log_skipped_linkæs zPackageFinder._log_skipped_linkcCs<|j|ƒ\}}|s(|r$|j||d�dSt|j|t|ƒd�S)z� If the link is a candidate for install, convert it to an InstallationCandidate and return it. Otherwise, return None. )raN)rVr2r5)rhrÍr r?r1)r@Úlink_evaluatorr2Ú is_candidateÚresultr6r6r7Úget_install_candidateñsz#PackageFinder.get_install_candidatecCs:g}x0|j|ƒD]"}|j||ƒ}|dk r|j|ƒqW|S)zU Convert links that are candidates to InstallationCandidate objects. N)rÌrÑrw)r@rÎrÈryr2rqr6r6r7Úevaluate_linkss  zPackageFinder.evaluate_linksc CsTtjd|ƒ|jj|ƒ}|dkr$gStt|ƒƒ}tƒ�|j||d�}WdQRX|S)Nz-Fetching project page and analyzing links: %s)rÈ)r-r.r¶Ú fetch_pagertr rrÒ)r@Ú project_urlrÎÚ html_pageÚ page_linksÚ package_linksr6r6r7Úprocess_project_urls  z!PackageFinder.process_project_url)Úmaxsizec Csš|jj|ƒ}|j|ƒ}|j||jd�}g}x&|jD]}|j||d�}|j|ƒq2W|j||jd�}|rŽ|j dd�t 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. )rÈ)rÎT)ÚreversezLocal files found: %sz, cSsg|]}t|jjƒ‘qSr6)rr2Úurl)rprqr6r6r7rœIsz5PackageFinder.find_all_candidates..) r¶Ú collect_linksrÆrÒr½Ú project_urlsrØÚextendÚfilesÚsortr-r.r/) r@r?Úcollected_linksrÎÚfind_links_versionsÚ page_versionsrÔr×Ú file_versionsr6r6r7Úfind_all_candidates%s*        z!PackageFinder.find_all_candidatescCs"|j}tj||j|j|j||d�S)z3Create a CandidateEvaluator object to use. )r?rCr‚r�r�ro)rµrŒr�r>r‚r�)r@r?r�rorºr6r6r7Úmake_candidate_evaluatorQs z&PackageFinder.make_candidate_evaluatorcCs$|j|ƒ}|j|||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?r�ro)rårær³)r@r?r�roryÚcandidate_evaluatorr6r6r7Úfind_best_candidateds  z!PackageFinder.find_best_candidatec Cs|jdd�}|j|j|j|d�}|j}d}|jdk r@t|jjƒ}dd„}|dkr||dkr|tj d|||j ƒƒƒt dj |ƒƒ‚d}|rš|dks–|j|kršd }| rÎ|dk rÎ|rºtj d |ƒntj d ||jƒdS|rìtj d |||jƒƒƒt‚tj d |j||jƒƒƒ|S)zêTry 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�roNcSs djtdd„|Dƒtd�ƒpdS)Nz, cSsh|]}t|jƒ’qSr6)r1r5)rpr™r6r6r7r˜”szKPackageFinder.find_requirement.._format_versions..)r�Únone)r/rŸÚ parse_version)Ú cand_iterr6r6r7Ú_format_versions�s  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))rorèrVr�r‡Ú satisfied_byrër5r-ÚcriticalrŠrrPr.r‹r) r@ÚreqÚupgraderoÚbest_candidate_resultr‡Úinstalled_versionríÚbest_installedr6r6r7Úfind_requirement{sT     zPackageFinder.find_requirement)NNN)N)NN)NN)rirjrkrlrEr´r�ÚpropertyrCr¼Úsetterr½r¾rÂr�rÃr‚rÄrÆrÌrÍrÑrÒrØrrårærèrõr6r6r6r7r(Fs8 !          /  cCsLx6t|ƒD]*\}}|dkrq t|d|…ƒ|kr |Sq Wtdj||ƒƒ‚dS)aöFind 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)ÚfragmentrAÚir™r6r6r7Ú_find_name_version_sepÍs rýc Cs@yt||ƒd}Wntk r&dSX||d…}|s+ 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)rýrú)rûrAÚ version_startr5r6r6r7rZès  rZ)F)TrlÚ __future__rÚloggingrmZpip._vendor.packagingrZpip._vendor.packaging.utilsrÚpip._vendor.packaging.versionrrëÚpip._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_pythonrÚpip._internal.models.wheelrÚpip._internal.utils.compatrÚpip._internal.utils.filetypesrÚpip._internal.utils.loggingrÚpip._internal.utils.miscrÚpip._internal.utils.packagingrÚpip._internal.utils.typingrÚpip._internal.utils.unpackingrÚpip._internal.utils.urlsrÚtypingrrrrrrrr Úpip._vendor.packaging.tagsr!r"r#Ú!pip._internal.models.search_scoper$Zpip._internal.reqr%Úpip._internal.utils.hashesr&r©r1ZBuildTagZCandidateSortingKeyÚ__all__Ú getLoggerrir-r8Úobjectr9rr€r'rŒr(rýrZr6r6r6r7Ús`                   (         (K-E