a R€aýÊã@s0ddlZddlmZddlZddlZddlZddlZddlZz ddlZWne ybddl ZYn0ddl Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-dd l.m/Z/m0Z0dd l1m2Z2m3Z3e 4e5¡Z6e 7d ¡Z8e 7d ej9¡Z:e 7d ¡Z;dZGdd„de?ƒZ@Gdd„de@ƒZAGdd„de@ƒZBGdd„de?ƒZCGdd„de@ƒZDGdd„de@ƒZEGdd „d e@ƒZFGd!d"„d"e@ƒZGGd#d$„d$e@ƒZHeHeFƒeDd%d&d'd(d)ZIeIjJZJGd*d+„d+e?ƒZKdS)-éN)ÚBytesIOé)ÚDistlibException)ÚurljoinÚurlparseÚ urlunparseÚ url2pathnameÚ pathname2urlÚqueueÚquoteÚunescapeÚ build_openerÚHTTPRedirectHandlerÚ text_typeÚRequestÚ HTTPErrorÚURLError)Ú DistributionÚDistributionPathÚ make_dist)ÚMetadataÚMetadataInvalidError)Úcached_propertyÚ ensure_slashÚsplit_filenameÚget_project_dataÚparse_requirementÚparse_name_and_versionÚ ServerProxyÚnormalize_name)Ú get_schemeÚUnsupportedVersionError)ÚWheelÚ is_compatiblez^(\w+)=([a-f0-9]+)z;\s*charset\s*=\s*(.*)\s*$ztext/html|application/x(ht)?mlzhttps://pypi.org/pypicCs>|dur t}t|dd}z| ¡W|dƒƒS|dƒƒ0dS)z• Return all distribution names known by an index. :param url: The URL of the index. :return: A list of all known distribution names. Nç@©ÚtimeoutÚclose)Ú DEFAULT_INDEXrÚ list_packages)ÚurlÚclient©r,úM/opt/alt/python39/lib/python3.9/site-packages/pip/_vendor/distlib/locators.pyÚget_all_distribution_names)s  þr.c@s$eZdZdZdd„ZeZZZdS)ÚRedirectHandlerzE A class to work around a bug in some Python 3.2.x releases. c Cs‚d}dD]}||vr||}q"q|dur.dSt|ƒ}|jdkrnt| ¡|ƒ}t|dƒrf| ||¡n|||<t ||||||¡S)N)ÚlocationZuriÚÚreplace_header)rÚschemerZ get_full_urlÚhasattrr2ÚBaseRedirectHandlerÚhttp_error_302) ÚselfÚreqÚfpÚcodeÚmsgÚheadersZnewurlÚkeyZurlpartsr,r,r-r6@s   ÿzRedirectHandler.http_error_302N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r6Zhttp_error_301Zhttp_error_303Zhttp_error_307r,r,r,r-r/7sr/c@s¶eZdZdZdZdZdZdZedZd)dd „Z d d „Z d d „Z dd„Z dd„Z dd„Zee eƒZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd*d'd(„ZdS)+ÚLocatorzG A base class for locators - things that locate distributions. )z.tar.gzz.tar.bz2z.tarz.zipz.tgzz.tbz)z.eggz.exeú.whl)z.pdfN)rCÚdefaultcCs,i|_||_ttƒƒ|_d|_t ¡|_dS)a^ Initialise an instance. :param scheme: Because locators look for most recent versions, they need to know the version scheme to use. This specifies the current PEP-recommended scheme - use ``'legacy'`` if you need to support existing distributions on PyPI. N) Ú_cacher3r r/ÚopenerÚmatcherr ÚQueueÚerrors)r7r3r,r,r-Ú__init__fs  zLocator.__init__cCsTg}|j ¡sPz|j d¡}| |¡Wn|jjyBYqYn0|j ¡q|S)z8 Return any errors which have occurred. F)rIÚemptyÚgetÚappendZEmptyÚ task_done)r7ÚresultÚer,r,r-Ú get_errorsys    zLocator.get_errorscCs | ¡dS)z> Clear any errors which may have been logged. N)rQ©r7r,r,r-Ú clear_errors‡szLocator.clear_errorscCs|j ¡dS©N)rEÚclearrRr,r,r-Ú clear_cacheŽszLocator.clear_cachecCs|jSrT©Ú_schemerRr,r,r-Ú _get_scheme‘szLocator._get_schemecCs ||_dSrTrW)r7Úvaluer,r,r-Ú _set_scheme”szLocator._set_schemecCs tdƒ‚dS)a= For a given project, get a dictionary mapping available versions to Distribution instances. This should be implemented in subclasses. If called from a locate() request, self.matcher will be set to a matcher for the requirement to satisfy, otherwise it will be None. ú Please implement in the subclassN©ÚNotImplementedError)r7Únamer,r,r-Ú _get_project™s zLocator._get_projectcCs tdƒ‚dS)úJ Return all the distribution names known to this locator. r\Nr]rRr,r,r-Úget_distribution_names¥szLocator.get_distribution_namescCsL|jdur| |¡}n2||jvr,|j|}n| ¡| |¡}||j|<|S)zÖ For a given project, get a dictionary mapping available versions to Distribution instances. This calls _get_project to do all the work, and just implements a caching layer on top. N)rEr`rS)r7r_rOr,r,r-Ú get_project«s      zLocator.get_projectcCs^t|ƒ}t |j¡}d}| d¡}| |j¡}|rBtt|ƒ|jƒ}|j dkd|j v||||fS)zu Give an url a score which can be used to choose preferred URLs for a given project release. TrCÚhttpszpypi.org) rÚ posixpathÚbasenameÚpathÚendswithÚdownloadable_extensionsr#r"Ú wheel_tagsr3Únetloc)r7r*ÚtrfZ compatibleZis_wheelZis_downloadabler,r,r-Ú score_url¼s   ÿzLocator.score_urlcCsR|}|rN| |¡}| |¡}||kr(|}||kr@t d||¡nt d||¡|S)a{ Choose one of two URLs where both are candidates for distribution archives for the same version of a distribution (for example, .tar.gz vs. zip). The current implementation favours https:// URLs over http://, archives from PyPI over those from other locations, wheel compatibility (if a wheel) and then the archive name. zNot replacing %r with %rzReplacing %r with %r)rmÚloggerÚdebug)r7Úurl1Úurl2rOÚs1Ús2r,r,r-Ú prefer_urlËs   zLocator.prefer_urlcCs t||ƒS)zZ Attempt to split a filename in project name, version and Python version. )r)r7ÚfilenameÚ project_namer,r,r-rászLocator.split_filenamec Cs dd„}d}t|ƒ\}}}}} } |  ¡ d¡r.same_projectNzegg=z %s: version hint in fragment: %r)NNéÿÿÿÿú/rCzWheel not compatible: %sTr1z, cSs"g|]}d t|dd…ƒ¡‘qS)Ú.éN)ÚjoinÚlist)Ú.0Úvr,r,r-Ú óz8Locator.convert_url_to_download_info..)r_Úversionrur*úpython-versionzinvalid path for wheel: %szNot downloadable: %sz No match for project/version: %s)r_r‚rur*rƒú %s_digest)rÚlowerÚ startswithrnroÚ HASHER_HASHÚmatchÚgroupsrhr"r#rjr_r‚rurr|ÚpyverÚ ExceptionÚwarningrirerfÚlenr)r7r*rvrwrOr3rkrgÚparamsÚqueryÚfragÚmÚalgoÚdigestZorigpathÚwheelZincluderPruZextrlr_r‚rŠr,r,r-Úconvert_url_to_download_infoçsvÿ     ÿÿú $    ÿü   z$Locator.convert_url_to_download_infocCshd}d|vr6|d}dD]}||vr|||f}q6q|sddD]$}d|}||vr>|||f}qdq>|S)zò Get a digest from a dictionary by looking at a "digests" dictionary or keys of the form 'algo_digest'. Returns a 2-tuple (algo, digest) if found, else None. Currently looks only for SHA256, then MD5. NÚdigests)Zsha256Úmd5r„r,)r7ÚinforOr–r’r=r,r,r-Ú _get_digest1s  zLocator._get_digestc Cs®| d¡}| d¡}||vr,||}|j}nt|||jd}|j}| |¡|_}|d}||d|<|j|dkrœ| |j|¡|_|d |t ƒ¡  |¡||_ |||<dS)zñ Update a result dictionary (the final result from _get_project) with a dictionary for a specific version, which typically holds information gleaned from a filename or URL for an archive for the distribution. r_r‚©r3r*r–ÚurlsN) ÚpopÚmetadatarr3r™r“Ú source_urlrtÚ setdefaultÚsetÚaddÚlocator) r7rOr˜r_r‚ÚdistÚmdr“r*r,r,r-Ú_update_version_dataHs   zLocator._update_version_dataFc Cs€d}t|ƒ}|dur td|ƒ‚t|jƒ}| |j¡|_}t d|t|ƒj ¡|  |j ¡}t |ƒdkrg}|j } |D]X} | dvr†qxz(| | ¡s”n|s¢| | ƒjs¬| | ¡WqxtyÎt d|| ¡Yqx0qxt |ƒdkrìt||jd}|rt d |¡|d } || }|rv|jr$|j|_| d i¡ | tƒ¡|_i} | d i¡} |jD]}|| vrR| || |<qR| |_d|_|S) a Find the most recent distribution which matches the given requirement. :param requirement: A requirement of the form 'foo (1.0)' or perhaps 'foo (>= 1.0, < 2.0, != 1.3)' :param prereleases: If ``True``, allow pre-release versions to be located. Otherwise, pre-release versions are not returned. :return: A :class:`Distribution` instance, or ``None`` if no such distribution could be located. NzNot a valid requirement: %rzmatcher: %s (%s)r{©r›r–zerror matching %s with %rr)r=zsorted list: %srxr›r–)rrr r3rGÚ requirementrnroÚtyper>rcr_rZ version_classrˆZ is_prereleaserMr‹rŒÚsortedr=ZextrasrLr Ú download_urlsr–)r7r§Ú prereleasesrOÚrr3rGÚversionsZslistZvclsÚkr‚ÚdÚsdr*r,r,r-Úlocate_sP           zLocator.locate)rD)F)r>r?r@rAÚsource_extensionsÚbinary_extensionsÚexcluded_extensionsrjrirJrQrSrVrYr[Úpropertyr3r`rbrcrmrtrr•r™r¥r±r,r,r,r-rBVs.   JrBcs0eZdZdZ‡fdd„Zdd„Zdd„Z‡ZS)ÚPyPIRPCLocatorz‘ This locator uses XML-RPC to locate distributions. It therefore cannot be used with simple mirrors (that only mirror file content). c s.tt|ƒjfi|¤Ž||_t|dd|_dS)z— Initialise an instance. :param url: The URL to use for XML-RPC. :param kwargs: Passed to the superclass constructor. r$r%N)Úsuperr¶rJÚbase_urlrr+©r7r*Úkwargs©Ú __class__r,r-rJ szPyPIRPCLocator.__init__cCst|j ¡ƒS©ra)r r+r)rRr,r,r-rb«sz%PyPIRPCLocator.get_distribution_namesc Csiidœ}|j |d¡}|D]Þ}|j ||¡}|j ||¡}t|jd}|d|_|d|_| d¡|_ | dg¡|_ | d¡|_ t |ƒ}|r|d } | d |_ | | ¡|_||_|||<|D]:} | d } | | ¡} |d  |tƒ¡ | ¡| |d | <q¾q|S) Nr¦Tršr_r‚ÚlicenseÚkeywordsÚsummaryrr*r›r–)r+Zpackage_releasesZ release_urlsZ release_datarr3r_r‚rLr¾r¿rÀrržr™r“r¢rŸr r¡) r7r_rOr­rr›Údatarr£r˜r*r“r,r,r-r`±s0         zPyPIRPCLocator._get_project©r>r?r@rArJrbr`Ú __classcell__r,r,r»r-r¶›s r¶cs0eZdZdZ‡fdd„Zdd„Zdd„Z‡ZS)ÚPyPIJSONLocatorzw This locator uses PyPI's JSON interface. It's very limited in functionality and probably not worth using. c s$tt|ƒjfi|¤Žt|ƒ|_dSrT)r·rÄrJrr¸r¹r»r,r-rJÐszPyPIJSONLocator.__init__cCs tdƒ‚dS©razNot available from this locatorNr]rRr,r,r-rbÔsz&PyPIJSONLocator.get_distribution_namesc Cs iidœ}t|jdt|ƒƒ}z¤|j |¡}| ¡ ¡}t |¡}t |j d}|d}|d|_ |d|_ |  d¡|_|  dg¡|_|  d ¡|_t|ƒ}||_|d } |||j <|d D]T} | d }|j |¡| | ¡|j|<|d  |j tƒ¡ |¡| | ¡|d |<qº|d  ¡D]¤\} } | |j kr4qt |j d} |j | _ | | _ t| ƒ}||_||| <| D]T} | d }|j |¡| | ¡|j|<|d  | tƒ¡ |¡| | ¡|d |<qhqWnBty}z(|j t|ƒ¡t d|¡WYd}~n d}~00|S)Nr¦z%s/jsonršr˜r_r‚r¾r¿rÀr›r*r–ZreleaseszJSON fetch failed: %s) rr¸r rFÚopenÚreadÚdecodeÚjsonÚloadsrr3r_r‚rLr¾r¿rÀrr¢rªr¡r™r–rŸr Úitemsr‹rIÚputrrnÚ exception)r7r_rOr*ÚresprÁr¯r¤r£r›r˜r‚ZinfosZomdÚodistrPr,r,r-r`ÚsT                "zPyPIJSONLocator._get_projectrÂr,r,r»r-rÄËs rÄc@s`eZdZdZe dejejBejB¡Z e dejejB¡Z dd„Z e dej¡Z e dd„ƒZd S) ÚPagez4 This class represents a scraped HTML page. zÝ (rel\s*=\s*(?:"(?P[^"]*)"|'(?P[^']*)'|(?P[^>\s ]*))\s+)? href\s*=\s*(?:"(?P[^"]*)"|'(?P[^']*)'|(?P[^>\s ]*)) (\s+rel\s*=\s*(?:"(?P[^"]*)"|'(?P[^']*)'|(?P[^>\s ]*)))? z!]+)cCs4||_||_|_|j |j¡}|r0| d¡|_dS)zk Initialise an instance with the Unicode page contents and the URL they came from. rN)rÁr¸r*Ú_baseÚsearchÚgroup)r7rÁr*r‘r,r,r-rJ s  z Page.__init__z[^a-z0-9$&+,/:;=?@.#%_\\|-]cCs¾dd„}tƒ}|j |j¡D]Š}| d¡}|dpX|dpX|dpX|dpX|dpX|d }|d pp|d pp|d }t|j|ƒ}t|ƒ}|j  d d„|¡}|  ||f¡qt |dd„dd}|S)zâ Return the URLs of all the links on a page together with information about their "rel" attribute, for determining which ones to treat as downloads and which ones to queue for further scraping. cSs,t|ƒ\}}}}}}t||t|ƒ|||fƒS)zTidy up an URL.)rrr )r*r3rkrgrŽrrr,r,r-Úclean4s ÿzPage.links..cleanr1Zrel1Zrel2Zrel3Zrel4Zrel5Zrel6rprqZurl3cSsdt| d¡ƒS)Nz%%%2xr)ÚordrÓ)r‘r,r,r-ÚBrzPage.links..cSs|dS)Nrr,)rlr,r,r-rÖFrT)r=Úreverse) r Ú_hrefÚfinditerrÁÚ groupdictrr¸r Ú _clean_reÚsubr¡r©)r7rÔrOrˆr¯Úrelr*r,r,r-Úlinks-s$ ÿÿÿ z Page.linksN)r>r?r@rAÚreÚcompileÚIÚSÚXrØrÑrJrÛrrÞr,r,r,r-rÐsü rÐcs˜eZdZdZejdd„dd„dœZd‡fdd „ Zd d „Zd d „Z dd„Z e   de j ¡Zdd„Zdd„Zdd„Zdd„Zdd„Ze   d¡Zdd„Z‡ZS)ÚSimpleScrapingLocatorzã A locator which scrapes HTML pages to locate downloads for a distribution. This runs multiple threads to do the I/O; performance is at least as good as pip's PackageFinder, which works in an analogous fashion. cCstjt|ƒd ¡S)N)Zfileobj)ÚgzipZGzipFilerrÇ©Úbr,r,r-rÖTrzSimpleScrapingLocator.cCs|SrTr,rær,r,r-rÖUr)ZdeflateråZnoneNé c sptt|ƒjfi|¤Žt|ƒ|_||_i|_tƒ|_t   ¡|_ tƒ|_ d|_ ||_t ¡|_t ¡|_d|_dS)a¤ Initialise an instance. :param url: The root URL to use for scraping. :param timeout: The timeout, in seconds, to be applied to requests. This defaults to ``None`` (no timeout specified). :param num_workers: The number of worker threads you want to do I/O, This defaults to 10. :param kwargs: Passed to the superclass. FN)r·rärJrr¸r&Ú _page_cacher Ú_seenr rHÚ _to_fetchÚ _bad_hostsÚskip_externalsÚ num_workersÚ threadingÚRLockÚ_lockÚ_gplockÚplatform_check)r7r*r&rîrºr»r,r-rJXs     zSimpleScrapingLocator.__init__cCsFg|_t|jƒD]0}tj|jd}| d¡| ¡|j |¡qdS)z¾ Threads are created only when get_project is called, and terminate before it returns. They are there primarily to parallelise I/O (i.e. fetching web pages). )ÚtargetTN) Ú_threadsÚrangerîrïZThreadÚ_fetchZ setDaemonÚstartrM)r7Úirlr,r,r-Ú_prepare_threadsss  z&SimpleScrapingLocator._prepare_threadscCs6|jD]}|j d¡q|jD] }| ¡qg|_dS)zu Tell all the threads to terminate (by sending a sentinel value) and wait for them to do so. N)rõrërÌr|)r7rlr,r,r-Ú _wait_threads€s    z#SimpleScrapingLocator._wait_threadsc Cs®iidœ}|jŠ||_||_t|jdt|ƒƒ}|j ¡|j ¡|  ¡z.t   d|¡|j   |¡|j  ¡W| ¡n | ¡0|`Wdƒn1s 0Y|S)Nr¦z%s/z Queueing %s)ròrOrvrr¸r rêrUrérúrnrorërÌr|rû)r7r_rOr*r,r,r-r`s      "z"SimpleScrapingLocator._get_projectz<\b(linux_(i\d86|x86_64|arm\w+)|win(32|_amd64)|macosx_?\d+)\bcCs |j |¡S)zD Does an URL refer to a platform-specific download? )Úplatform_dependentrÒ)r7r*r,r,r-Ú_is_platform_dependent¢sz,SimpleScrapingLocator._is_platform_dependentcCsn|jr| |¡rd}n| ||j¡}t d||¡|rj|j| |j|¡Wdƒn1s`0Y|S)a% See if an URL is a suitable download for a project. If it is, register information in the result dictionary (for _get_project) about the specific version it's for. Note that the return value isn't actually used other than as a boolean value. Nzprocess_download: %s -> %s) rórýr•rvrnrorñr¥rO)r7r*r˜r,r,r-Ú_process_download¨s ,z'SimpleScrapingLocator._process_downloadc CsÄt|ƒ\}}}}}}| |j|j|j¡r2d}n||jrJ| |j¡sJd}nd| |j¡s\d}nR|dvrjd}nD|dvrxd}n6| |¡rˆd}n&|  dd¡d} |   ¡dkrªd}nd}t   d ||||¡|S) z‘ Determine whether a link URL from a referring page and with a particular "rel" attribute should be queued for scraping. F)ZhomepageZdownload)ÚhttprdÚftpú:rrZ localhostTz#should_queue: %s (%s) from %s -> %s) rrhr²r³r´rír†r¸rýÚsplitr…rnro) r7ÚlinkZreferrerrÝr3rkrgÚ_rOÚhostr,r,r-Ú _should_queue¼s.ÿ    ÿz#SimpleScrapingLocator._should_queuec Cs|j ¡}zÞzš|r¤| |¡}|dur4WW|j ¡q|jD]h\}}||jvr:zB|j |¡| |¡sŒ| |||¡rŒt   d||¡|j  |¡Wq:t y Yq:0q:Wn4t yÚ}z|j  t|ƒ¡WYd}~n d}~00W|j ¡n |j ¡0|sqþqdS)z× Get a URL to fetch from the work queue, get the HTML page, examine its links for download candidates and candidates for further scraping. This is a handy method to run in a thread. NzQueueing %s from %s)rërLÚget_pagerNrÞrêr¡rþrrnrorÌrr‹rIr)r7r*ÚpagerrÝrPr,r,r-r÷Ùs0   ñ    ÿ  (zSimpleScrapingLocator._fetchc Cs|t|ƒ\}}}}}}|dkr:tj t|ƒ¡r:tt|ƒdƒ}||jvr`|j|}t  d||¡n|  dd¡d}d}||j vrt  d||¡nèt |d d id }zÈzàt  d |¡|j j||jd } t  d|¡|  ¡} |  dd¡} t | ¡r‚|  ¡} |  ¡} |  d¡}|r"|j|}|| ƒ} d}t | ¡}|r@| d¡}z|  |¡} Wntyl|  d¡} Yn0t| | ƒ}||j| <WnØtyÄ}z&|jdkr°t d||¡WYd}~n¢d}~0t y*}zNt d||¡|j!|j  "|¡Wdƒn1s 0YWYd}~n]*>([^<]+)r?r@rAÚzlibÚ decompressrrJrúrûr`rßràrárürýrþrr÷rrrbrÃr,r,r»r-räJs&ý  ÿ!; räcs8eZdZdZ‡fdd„Zdd„Zdd„Zdd „Z‡ZS) ÚDirectoryLocatorz? This class locates distributions in a directory tree. c sR| dd¡|_tt|ƒjfi|¤Žtj |¡}tj |¡sHt d|ƒ‚||_ dS)aŒ Initialise an instance. :param path: The root of the directory tree to search. :param kwargs: Passed to the superclass constructor, except for: * recursive - if True (the default), subdirectories are recursed into. If False, only the top-level directory is searched, Ú recursiveTzNot a directory: %rN) rœrr·rrJr rgÚabspathr rÚbase_dir)r7rgrºr»r,r-rJHs    zDirectoryLocator.__init__cCs | |j¡S)zá Should a filename be considered as a candidate for a distribution archive? As well as the filename, the directory which contains it is provided, though not used by the current implementation. )rhri)r7ruÚparentr,r,r-Úshould_includeYszDirectoryLocator.should_includec Csiidœ}t |j¡D]t\}}}|D]Z}| ||¡r$tj ||¡}tddttj |¡ƒdddfƒ}|  ||¡}|r$|  ||¡q$|j sqŒq|S)Nr¦r r1) r Úwalkrrrgr|rr rr•r¥r) r7r_rOÚrootÚdirsÚfilesÚfnr*r˜r,r,r-r`as  þ zDirectoryLocator._get_projectc CsŽtƒ}t |j¡D]v\}}}|D]\}| ||¡r tj ||¡}tddttj  |¡ƒdddfƒ}|  |d¡}|r |  |d¡q |j sqŠq|S)rar r1Nr_) r r rrrrgr|rr rr•r¡r)r7rOrrrr r*r˜r,r,r-rbqs þ z'DirectoryLocator.get_distribution_names) r>r?r@rArJrr`rbrÃr,r,r»r-rCs  rc@s eZdZdZdd„Zdd„ZdS)Ú JSONLocatora This locator uses special extended metadata (not available on PyPI) and is the basis of performant dependency resolution in distlib. Other locators require archive downloads before dependencies can be determined! As you might imagine, that can be slow. cCs tdƒ‚dSrÅr]rRr,r,r-rb‹sz"JSONLocator.get_distribution_namescCsÚiidœ}t|ƒ}|rÖ| dg¡D]²}|ddks"|ddkr@q"t|d|d| d d ¡|jd }|j}|d |_d |vr|d rd|d f|_| di¡|_| di¡|_|||j <|d  |j t ƒ¡  |d ¡q"|S)Nr¦rZptypeZsdistZ pyversionÚsourcer_r‚rÀzPlaceholder for summary)rÀr3r*r“r—Z requirementsÚexportsr›) rrLrr3rržr“Z dependenciesr#r‚rŸr r¡)r7r_rOrÁr˜r£r¤r,r,r-r`‘s* ÿý   zJSONLocator._get_projectN)r>r?r@rArbr`r,r,r,r-r!„sr!cs(eZdZdZ‡fdd„Zdd„Z‡ZS)ÚDistPathLocatorz‚ This locator finds installed distributions in a path. It can be useful for adding to an :class:`AggregatingLocator`. c s.tt|ƒjfi|¤Žt|tƒs$J‚||_dS)zs Initialise an instance. :param distpath: A :class:`DistributionPath` instance to search. N)r·r$rJÚ isinstancerÚdistpath)r7r&rºr»r,r-rJ¯szDistPathLocator.__init__cCsP|j |¡}|dur iidœ}n,|j|d|jt|jgƒid|jtdgƒii}|S)Nr¦r›r–)r&Zget_distributionr‚r rž)r7r_r£rOr,r,r-r`¹s  ýzDistPathLocator._get_project)r>r?r@rArJr`rÃr,r,r»r-r$ªs r$csReZdZdZ‡fdd„Z‡fdd„Zdd„Zeej j eƒZ dd „Z d d „Z ‡Z S) ÚAggregatingLocatorzI This class allows you to chain and/or merge a list of locators. cs.| dd¡|_||_tt|ƒjfi|¤ŽdS)aÏ Initialise an instance. :param locators: The list of locators to search. :param kwargs: Passed to the superclass constructor, except for: * merge - if False (the default), the first successful search from any of the locators is returned. If True, the results from all locators are merged (this can be slow). ÚmergeFN)rœr(Úlocatorsr·r'rJ)r7r)rºr»r,r-rJÊs zAggregatingLocator.__init__cs&tt|ƒ ¡|jD] }| ¡qdSrT)r·r'rVr)©r7r¢r»r,r-rVÚs zAggregatingLocator.clear_cachecCs||_|jD] }||_q dSrT)rXr)r3)r7rZr¢r,r,r-r[ßs zAggregatingLocator._set_schemec Csìi}|jD]Ü}| |¡}|r |jr¨| di¡}| di¡}| |¡| d¡}|rŠ|rŠ| ¡D]*\}} ||vr€||| O<q^| ||<q^| d¡} |ræ| ræ|  |¡q |jdur¸d} n"d} |D]}|j |¡rÀd} qÚqÀ| r |}qèq |S)Nr›r–TF)r)rcr(rLÚupdaterËrGrˆ) r7r_rOr¢r¯rr–Zdfr®rÚddÚfoundr,r,r-r`æs8          zAggregatingLocator._get_projectc Cs:tƒ}|jD](}z|| ¡O}Wq ty2Yq 0q |Sr½)r r)rbr^)r7rOr¢r,r,r-rbs  z)AggregatingLocator.get_distribution_names)r>r?r@rArJrVr[rµrBr3Úfgetr`rbrÃr,r,r»r-r'Æs  ,r'zhttps://pypi.org/simple/r$r%Úlegacyršc@sLeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z ddd„Z dS)ÚDependencyFinderz0 Locate dependencies for distributions. NcCs|pt|_t|jjƒ|_dS)zf Initialise an instance, using the specified locator to locate distributions. N)Údefault_locatorr¢r r3r*r,r,r-rJ/s zDependencyFinder.__init__cCsrt d|¡|j}||j|<||j||jf<|jD]:}t|ƒ\}}t d|||¡|j  |t ƒ¡  ||f¡q2dS)z¨ Add a distribution to the finder. This will update internal information about who provides what. :param dist: The distribution to add. zadding distribution %szAdd to provided: %s, %s, %sN) rnror=Ú dists_by_nameÚdistsr‚ÚprovidesrÚprovidedrŸr r¡)r7r£r_Úpr‚r,r,r-Úadd_distribution7s    z!DependencyFinder.add_distributioncCsxt d|¡|j}|j|=|j||jf=|jD]D}t|ƒ\}}t d|||¡|j|}|  ||f¡|s.|j|=q.dS)z° Remove a distribution from the finder. This will update internal information about who provides what. :param dist: The distribution to remove. zremoving distribution %sz Remove from provided: %s, %s, %sN) rnror=r2r3r‚r4rr5Úremove)r7r£r_r6r‚Úsr,r,r-Úremove_distributionFs    z$DependencyFinder.remove_distributioncCs@z|j |¡}Wn*ty:| ¡d}|j |¡}Yn0|S)zÞ Get a version matcher for a requirement. :param reqt: The requirement :type reqt: str :return: A version matcher (an instance of :class:`distlib.version.Matcher`). r)r3rGr!r)r7ÚreqtrGr_r,r,r-Ú get_matcherXs   zDependencyFinder.get_matcherc Csr| |¡}|j}tƒ}|j}||vrn||D]@\}}z| |¡}WntyXd}Yn0|r,| |¡qnq,|S)zÓ Find the distributions which can fulfill a requirement. :param reqt: The requirement. :type reqt: str :return: A set of distribution which can fulfill the requirement. F)r<r=r r5rˆr!r¡) r7r;rGr_rOr5r‚Úproviderrˆr,r,r-Úfind_providershs    zDependencyFinder.find_providersc Csž|j|}tƒ}|D]$}| |¡}| |j¡s| |¡q|rZ| d||t|ƒf¡d}n@| |¡|j|=|D]}|j |tƒ¡ |¡qp|  |¡d}|S)aŠ Attempt to replace one provider with another. This is typically used when resolving dependencies from multiple sources, e.g. A requires (B >= 1.0) while C requires (B >= 1.1). For successful replacement, ``provider`` must meet all the requirements which ``other`` fulfills. :param provider: The provider we are trying to replace with. :param other: The provider we're trying to replace. :param problems: If False is returned, this will contain what problems prevented replacement. This is currently a tuple of the literal string 'cantreplace', ``provider``, ``other`` and the set of requirements that ``provider`` couldn't fulfill. :return: True if we can replace ``other`` with ``provider``, else False. Z cantreplaceFT) Úreqtsr r<rˆr‚r¡Ú frozensetr:rŸr7) r7r=ÚotherÚproblemsZrlistZ unmatchedr9rGrOr,r,r-Útry_to_replace€s$     ÿ  zDependencyFinder.try_to_replaceFcCsði|_i|_i|_i|_t|p gƒ}d|vrF| d¡|tgd¢ƒO}t|tƒrf|}}t  d|¡n4|j j ||d}}|durŽt d|ƒ‚t  d|¡d|_ tƒ}t|gƒ}t|gƒ}|r¢| ¡}|j} | |jvrä| |¡n"|j| } | |kr| || |¡|j|jB} |j} tƒ} |r^||vr^d D]*}d |}||vr2| t|d |ƒO} q2| | B| B}|D].}| |¡}|sDt  d |¡|j j ||d}|durÀ|sÀ|j j |dd}|duræt  d |¡| d|f¡n^|j|j}}||f|jvr| |¡| |¡|| vrD||vrD| |¡t  d|j¡|D]R}|j} | |jvrv|j |tƒ¡ |¡n"|j| } | |krH| || |¡qHqnqºt|j ¡ƒ}|D]&}||v|_|jr´t  d|j¡q´t  d|¡||fS)aŽ Find a distribution and all distributions it depends on. :param requirement: The requirement specifying the distribution to find, or a Distribution instance. :param meta_extras: A list of meta extras such as :test:, :build: and so on. :param prereleases: If ``True``, allow pre-release versions to be returned - otherwise, don't return prereleases unless they're all that's available. Return a set of :class:`Distribution` instances and a set of problems. The distributions returned should be such that they have the :attr:`required` attribute set to ``True`` if they were from the ``requirement`` passed to ``find()``, and they have the :attr:`build_time_dependency` attribute set to ``True`` unless they are post-installation dependencies of the ``requirement``. The problems should be a tuple consisting of the string ``'unsatisfied'`` and the requirement which couldn't be satisfied by any distribution known to the locator. z:*:)z:test:z:build:z:dev:zpassed %s as requirement)r«NzUnable to locate %rz located %sT)ÚtestZbuildÚdevz:%s:z %s_requireszNo providers found for %rzCannot satisfy %rZ unsatisfiedzAdding %s to install_distsz#%s is a build-time dependency only.zfind done for %s)r5r3r2r?r r8r%rrnror¢r±rZ requestedrœr=r7rCZ run_requiresZ meta_requiresZbuild_requiresÚgetattrr>r¡r‚Zname_and_versionrŸÚvaluesZbuild_time_dependency)r7r§Z meta_extrasr«r£rÏrBZtodoZ install_distsr_rAZireqtsZsreqtsZereqtsr=rPZ all_reqtsr¬Z providersr=Únrr6r3r,r,r-Úfind¨s’   ÿ                    ÿ    ÿ zDependencyFinder.find)N)NF) r>r?r@rArJr7r:r<r>rCrIr,r,r,r-r0*s (r0)N)LråÚiorrÉZloggingr rerßrïÚ ImportErrorZdummy_threadingrr1rÚcompatrrrrr r r r r rr5rrrrZdatabaserrrrrrÚutilrrrrrrrrr‚r r!r”r"r#Z getLoggerr>rnràr‡rárr r(r.r/ÚobjectrBr¶rÄrÐrärr!r$r'r1r±r0r,r,r,r-Ús\    @(    G0E:zA&[ÿü