U ÀÒ.e�ã@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*e$�ržddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3ddl m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ>e3e2de2e?e@ffZAe2e?e?e?e4eAe/e?fZBdddgZCe DeE¡ZFd1d!d"„ZGGd#d$„d$eHƒZId%d&„ZJGd'd(„d(eHƒZKGd)d„deHƒZLGd*d+„d+eHƒZMGd,d„deHƒZNd-d.„ZOd/d0„ZPdS)2z!Routines related to PyPI, indexesé)Úabsolute_importN)Ú specifiers)Úcanonicalize_name)Úparse)ÚBestVersionAlreadyInstalledÚDistributionNotFoundÚInvalidWheelFilenameÚUnsupportedWheel)ÚInstallationCandidate)Ú FormatControl)ÚLink)ÚSelectionPreferences)Ú TargetPython)ÚWHEEL_EXTENSION)Ú indent_log)Ú build_netloc)Úcheck_requires_python)ÚMYPY_CHECK_RUNNING)ÚSUPPORTED_EXTENSIONS)Ú url_to_path)ÚWheel)Ú FrozenSetÚIterableÚListÚOptionalÚSetÚTextÚTupleÚUnion)Ú _BaseVersion)Ú LinkCollector)Ú SearchScope)ÚInstallRequirement)Ú Pep425Tag)ÚHashes©r ÚBestCandidateResultÚ PackageFinderFcCs~zt|j|d�}Wn&tjk r8t d|j|¡YnBX|szd tt|ƒ¡}|sht d||j|¡dSt d||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) rZrequires_pythonrZInvalidSpecifierÚloggerÚdebugÚjoinÚmapÚstr)Úlinkr(Úignore_requires_pythonZ is_compatibleÚversionr%r%ú7/usr/lib/python3.8/site-packages/pip/_internal/index.pyÚ_check_link_requires_python;s8ÿ þ þýr3c@s,eZdZdZe d¡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_yankedr0r%r%r2Ú__init__rszLinkEvaluator.__init__c Csèd}|jr(|js(|jpd}dd |¡fS|jr<|j}|j}nð| ¡\}}|sPdS|tkrddd|fSd|jkrˆ|t krˆd|j }d|fSd |j krž|d kržd S|t k�r,zt |j ƒ}Wntk rÌYd SXt|jƒ|jkrðd |j }d|fS|j ¡}| |¡�s&| ¡}d d |¡¡}d|fS|j}d|jk�rP|t k�rPdd|j fS|�sbt||jƒ}|�svdd|j fS|j |¡} | �r´|d|  ¡…}|  d¡} | |jjk�r´dSt||jj|j d�} | �sÒdSt! "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. Nú Fzyanked for reason: {})Fz not a filezunsupported archive format: %sZbinaryzNo binaries permitted for %sZmacosx10z.zip)Fz macosx10 one)Fzinvalid wheel filenamezwrong project name (not %s)z"none of the wheel's tags match: {}ú, ÚsourcezNo sources permitted for %szMissing project version for %sé)FzPython version is incorrect)r(r0)FNzFound link %s, version: %sT)#Ú is_yankedr5Ú yanked_reasonÚformatÚ egg_fragmentÚextÚsplitextrr8rr:ÚpathrÚfilenamerrÚnamer6r9Úget_tagsÚ supportedZget_formatted_file_tagsr,r1Ú_extract_version_from_fragmentÚ_py_version_reÚsearchÚstartÚgroupÚ py_versionr3Zpy_version_infor7r*r+) r;r/r1ÚreasonZegg_inforIÚwheelÚsupported_tagsZ file_tagsÚmatchrUZsupports_pythonr%r%r2Ú evaluate_link˜sx          ÿÿÿÿ  þzLinkEvaluator.evaluate_link)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚreÚcompilerQr@rZr%r%r%r2r4fs  ù &r4c CsÞ|st dt|ƒ|¡t|ƒSg}g}d}|D]>}|j}|js@n"|j|d�rV|d7}n | |¡q.| |¡q.|rx|}nt|ƒ}t|ƒt|ƒkr–d} n d t|ƒd  dd „|Dƒ¡¡} t d 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)ÚhashesrDzdiscarding no candidateszdiscarding {} non-matches: {}z css|]}t|jƒVqdS©N)r.r/©Ú.0Ú candidater%r%r2Ú +sz*filter_unallowed_hashes..zPChecked %s links for project %r against %s hashes (%s matches, %s no digest): %s) r*r+ÚlenÚlistr/Zhas_hashÚis_hash_allowedÚappendrGr,Z digest_count) Ú candidatesrar:Zmatches_or_no_digestZ non_matchesZ match_countrer/ZfilteredZdiscard_messager%r%r2Úfilter_unallowed_hashesñsLü    þ ø rlc@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;rornr%r%r2r@Cs zCandidatePreferences.__init__N)FF)r[r\r]r^r@r%r%r%r2rm<sýrmc@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. cCsHt|ƒt|ƒkst‚|dkr&|r2t‚n ||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)ÚsetÚAssertionErrorÚ_applicable_candidatesÚ _candidatesÚbest_candidate©r;rkÚapplicable_candidatesrtr%r%r2r@Ws   zBestCandidateResult.__init__cCs t|jƒS)z(Iterate through all candidates. )Úiterrs©r;r%r%r2Úiter_allpszBestCandidateResult.iter_allcCs t|jƒS)z3Iterate through the applicable candidates. )rwrrrxr%r%r2Úiter_applicablevsz#BestCandidateResult.iter_applicableN)r[r\r]r^r@ryrzr%r%r%r2r&Psc@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ƒ}|dkrt ¡}| ¡}|||||||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:rXÚ specifierrornra)rrZ SpecifierSetrN)Úclsr:r>rornr|rarXr%r%r2Úcreate„sú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:rXr|rornrar%r%r2r@©s zCandidateEvaluator.__init__csV|jpd}|j}dd„|jdd„|Dƒ|d�Dƒ‰‡fdd„|Dƒ}t||j|jd �S) zM Return the applicable candidates from a list of candidates. NcSsh|] }t|ƒ’qSr%)r.)rdÚvr%r%r2Ú Ész?CandidateEvaluator.get_applicable_candidates..css|]}t|jƒVqdSrb©r.r1©rdÚcr%r%r2rfÒsz?CandidateEvaluator.get_applicable_candidates..)Z prereleasescsg|]}t|jƒˆkr|‘qSr%r‡rˆ©Zversionsr%r2Ú Øsz@CandidateEvaluator.get_applicable_candidates..)rkrar:)rrƒÚfilterrlr€r‚)r;rkZallow_prereleasesr|rvr%rŠr2Úget_applicable_candidates¾s  ÷ÿ ÿýz,CandidateEvaluator.get_applicable_candidatesc CsÆ|j}t|ƒ}d}d}|j}|jr�t|jƒ}| |¡sDtd|jƒ‚|jrNd}|  |¡ }|j dk r–t   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%s is not a supported wheel for this platform. It can't be sorted.rDNz ^(\d+)(.*)$éÿÿÿÿ)r„rgr/Zis_wheelrrLrOr r�Zsupport_index_minÚ build_tagr_rYÚgroupsÚintrir€rEr1) r;reZ valid_tagsZ support_numr�Zbinary_preferencer/rWZprirYZbuild_tag_groupsZhas_allowed_hashZ yank_valuer%r%r2Ú _sort_keyâs<  ÿÿ  þzCandidateEvaluator._sort_keycCsH|sdSt||jd�}|j}|jrD|jp*d}dj||d�}t |¡|S)zy Return the best candidate per the instance's sort order, or None if no candidate is acceptable. N©ÚkeyrAzqThe candidate selected for download or install is a yanked version: {candidate} Reason for being yanked: {reason})rerV)Úmaxr’r/rErFrGr*Zwarning)r;rkrtr/rVÚmsgr%r%r2Úsort_best_candidates  üù z&CandidateEvaluator.sort_best_candidatecCs"| |¡}| |¡}t|||d�S)zF Compute and return a `BestCandidateResult` instance. )rvrt)r�r—r&rur%r%r2Úcompute_best_candidate<s  ýz)CandidateEvaluator.compute_best_candidate)NFFNN)FFN) r[r\r]r^Ú classmethodr~r@r�r’r—r˜r%r%r%r2r{}s ù )ù $<r{c@sÆeZdZdZd&dd„Zed'dd„ƒZedd„ƒZej d d„ƒZed d „ƒZ ed d „ƒZ edd„ƒZ edd„ƒZ dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd(d d!„Zd)d"d#„Zd$d%„ZdS)*r'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) rmr rpr5Ú_candidate_prefsr7Ú_link_collectorr9Úformat_controlÚ _logged_links)r;Úlink_collectorr>r?rœÚcandidate_prefsr0r%r%r2r@VszPackageFinder.__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)rorn)rŸržr>r?rœr0)rrmrornr?rœr0)r}ržZselection_prefsr>rŸr%r%r2r~~sþúzPackageFinder.createcCs|jjSrb©r›Ú search_scoperxr%r%r2r¡ŸszPackageFinder.search_scopecCs ||j_dSrbr )r;r¡r%r%r2r¡¤scCs|jjSrb)r›Ú find_linksrxr%r%r2r¢©szPackageFinder.find_linkscCs|jjSrb)r¡Ú index_urlsrxr%r%r2r£®szPackageFinder.index_urlsccs|jjjD]}t|ŽVq dSrb)r›ZsessionZpip_trusted_originsr)r;Z host_portr%r%r2Ú trusted_hosts³szPackageFinder.trusted_hostscCs|jjSrb©ršrnrxr%r%r2rn¹sz#PackageFinder.allow_all_prereleasescCs d|j_dS)NTr¥rxr%r%r2Úset_allow_all_prereleases¾sz'PackageFinder.set_allow_all_prereleasescCs.t|ƒ}|j |¡}t||||j|j|jd�S)N)r:r<r=r>r?r0)rrœZget_allowed_formatsr4r9r5r7)r;r:r<r=r%r%r2Úmake_link_evaluatorÂs úz!PackageFinder.make_link_evaluatorcCsPgg}}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 )rpÚaddrHrj)r;ÚlinksZeggsZno_eggsÚseenr/r%r%r2Ú _sort_linksÐs    zPackageFinder._sort_linkscCs(||jkr$t d||¡|j |¡dS)NzSkipping link: %s: %s)r�r*r+r¨)r;r/rVr%r%r2Ú_log_skipped_linkás zPackageFinder._log_skipped_linkcCs<| |¡\}}|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. )rVN)Zprojectr/r1)rZr¬r r:r.)r;Úlink_evaluatorr/Z is_candidateÚresultr%r%r2Úget_install_candidateìsûz#PackageFinder.get_install_candidatecCs6g}| |¡D]"}| ||¡}|dk r| |¡q|S)zU Convert links that are candidates to InstallationCandidate objects. N)r«r¯rj)r;r­r©rkr/rer%r%r2Úevaluate_linkss   zPackageFinder.evaluate_linksc Cs¼|j |¡}| |¡}|j||jd�}g}|j ¡D]>\}}t d|¡t ƒ�|j||d�}|  |¡W5QRXq4|j||j d�} | r°| j dd�t dd  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©zAnalyzing links from page %sT)ÚreversezLocal files found: %srBcSsg|]}t|jjƒ‘qSr%)rr/Zurlrcr%r%r2r‹2sÿz5PackageFinder.find_all_candidates..)r›Z collect_linksr§r°r¢ZpagesÚitemsr*r+rÚextendÚfilesÚsortr,) r;r:Zcollected_linksr­Zfind_links_versionsZ page_versionsZpage_urlZ page_linksZ new_versionsZ file_versionsr%r%r2Úfind_all_candidates s8  þ þþ  þþ z!PackageFinder.find_all_candidatescCs"|j}tj||j|j|j||d�S)z3Create a CandidateEvaluator object to use. )r:r>rornr|ra)ršr{r~r9rorn)r;r:r|rarŸr%r%r2Úmake_candidate_evaluator;s úz&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. )r:r|ra)r¶r·r˜)r;r:r|rarkZcandidate_evaluatorr%r%r2Úfind_best_candidateNs ýz!PackageFinder.find_best_candidatec Cs|jdd�}|j|j|j|d�}|j}d}|jdk r@t|jjƒ}dd„}|dkrz|dkrzt  d|||  ¡ƒ¡t d|ƒ‚d}|r˜|dks”|j|kr˜d }|sÊ|dk rÊ|r¶t  d |¡nt  d ||j¡dS|rèt  d |||  ¡ƒ¡t‚t  d |j||  ¡ƒ¡|jS)zÙTry to find a Link matching req Expects req, an InstallRequirement and upgrade, a boolean Returns a Link if found, Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise F)Ztrust_internet)r|raNcSs d tdd„|Dƒtd�¡pdS)NrBcSsh|]}t|jƒ’qSr%r‡rˆr%r%r2r†}szKPackageFinder.find_requirement.._format_versions..r“Znone)r,ÚsortedÚ parse_version)Z cand_iterr%r%r2Ú_format_versionsws  þýz8PackageFinder.find_requirement.._format_versionszNCould not find a version that satisfies the requirement %s (from versions: %s)z%No matching distribution found for %sTzLExisting 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))rar¸rMr|rtZ satisfied_byrºr1r*Zcriticalryrr+rzrr/) r;ZreqZupgraderaZbest_candidate_resultrtZinstalled_versionr»Zbest_installedr%r%r2Úfind_requirementesh ÿ    üÿÿþ ýü ü ýzPackageFinder.find_requirement)NNN)N)NN)NN)r[r\r]r^r@r™r~Úpropertyr¡Úsetterr¢r£r¤rnr¦r§r«r¬r¯r°r¶r·r¸r¼r%r%r%r2r'OsD ù (ü         1ü ü cCsLt|ƒD].\}}|dkrqt|d|…ƒ|kr|Sqtd ||¡ƒ‚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Ú ValueErrorrG)Úfragmentr<Úir‰r%r%r2Ú_find_name_version_sepµs  rÄcCsBzt||ƒd}Wntk r(YdSX||d…}|s>dS|S)zúParse 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)rÄrÁ)rÂr<Z version_startr1r%r%r2rPÐs  rP)F)Qr^Z __future__rZloggingr_Zpip._vendor.packagingrZpip._vendor.packaging.utilsrZpip._vendor.packaging.versionrrºZpip._internal.exceptionsrrrr Zpip._internal.models.candidater Z#pip._internal.models.format_controlr Zpip._internal.models.linkr Z$pip._internal.models.selection_prefsr Z"pip._internal.models.target_pythonrZpip._internal.utils.filetypesrZpip._internal.utils.loggingrZpip._internal.utils.miscrZpip._internal.utils.packagingrZpip._internal.utils.typingrZpip._internal.utils.unpackingrZpip._internal.utils.urlsrZpip._internal.wheelrÚtypingrrrrrrrrrZpip._internal.collectorr Z!pip._internal.models.search_scoper!Zpip._internal.reqr"Zpip._internal.pep425tagsr#Zpip._internal.utils.hashesr$r‘r.ZBuildTagZCandidateSortingKeyÚ__all__Z getLoggerr[r*r3Úobjectr4rlrmr&r{r'rÄrPr%r%r%r2Ús^                 (      ÿ  ý + K-Sh