3 PfE@s@ddlZddlmZddlZddlZddlZddlZddlZy ddlZWne k rdddl ZYnXddl Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.dd l/m0Z0m1Z1dd l2m3Z3m4Z4ej5e6Z7ej8d Z9ej8d ej:Z;ej8d ZGdddeZ?Gddde@ZAGdddeAZBGdddeAZCGddde@ZDGdddeAZEGdddeAZFGdd d eAZGGd!d"d"eAZHGd#d$d$eAZIeIeGeEd%d&d'd(d)ZJeJjKZKej8d*ZLGd+d,d,e@ZMdS).N)BytesIO)DistlibException)urljoinurlparse urlunparse url2pathname pathname2urlqueuequoteunescape string_types build_openerHTTPRedirectHandler text_typeRequest HTTPErrorURLError) DistributionDistributionPath make_dist)Metadata) cached_propertyparse_credentials ensure_slashsplit_filenameget_project_dataparse_requirementparse_name_and_version ServerProxynormalize_name) get_schemeUnsupportedVersionError)Wheel is_compatiblez^(\w+)=([a-f0-9]+)z;\s*charset\s*=\s*(.*)\s*$ztext/html|application/x(ht)?mlzhttps://pypi.python.org/pypicCs |dkr t}t|dd}|jS)z Return all distribution names known by an index. :param url: The URL of the index. :return: A list of all known distribution names. Ng@)timeout) DEFAULT_INDEXr list_packages)urlclientr*/usr/lib/python3.6/locators.pyget_all_distribution_names)s r,c@s$eZdZdZddZeZZZdS)RedirectHandlerzE A class to work around a bug in some Python 3.2.x releases. c Csd}xdD]}||kr ||}Pq W|dkr0dSt|}|jdkrpt|j|}t|drh|j||n|||<tj||||||S)Nlocationurireplace_header)r.r/)rschemerZ get_full_urlhasattrr1BaseRedirectHandlerhttp_error_302) selfreqfpcodemsgheadersZnewurlkeyZurlpartsr*r*r+r5=s   zRedirectHandler.http_error_302N)__name__ __module__ __qualname____doc__r5Zhttp_error_301Zhttp_error_303Zhttp_error_307r*r*r*r+r-4sr-c@seZdZdZd/Zd0Zd1Zd Zed2Zd3ddZ ddZ ddZ ddZ ddZ ddZee eZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd4d-d.Zd S)5LocatorzG A base class for locators - things that locate distributions. .tar.gz.tar.bz2.tar.zip.tgz.tbz.egg.exe.whl.pdfNdefaultcCs,i|_||_tt|_d|_tj|_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) _cacher2rr-openermatcherr Queueerrors)r6r2r*r*r+__init__cs  zLocator.__init__c CsXg}xN|jjsRy|jjd}|j|Wn|jjk rDwYnX|jjqW|S)z8 Return any errors which have occurred. F)rQemptygetappendZEmpty task_done)r6resulter*r*r+ get_errorsvs  zLocator.get_errorscCs |jdS)z> Clear any errors which may have been logged. N)rY)r6r*r*r+ clear_errorsszLocator.clear_errorscCs|jjdS)N)rMclear)r6r*r*r+ clear_cacheszLocator.clear_cachecCs|jS)N)_scheme)r6r*r*r+ _get_schemeszLocator._get_schemecCs ||_dS)N)r])r6valuer*r*r+ _set_schemeszLocator._set_schemecCs tddS)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. z Please implement in the subclassN)NotImplementedError)r6namer*r*r+ _get_projects zLocator._get_projectcCs tddS)zJ Return all the distribution names known to this locator. z Please implement in the subclassN)ra)r6r*r*r+get_distribution_namesszLocator.get_distribution_namescCsL|jdkr|j|}n2||jkr,|j|}n|j|j|}||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)rMrcrZ)r6rbrWr*r*r+ get_projects      zLocator.get_projectcCsPt|}tj|j}d}|jd}|r6tt||j}|jdkd|j k|||fS)zu Give an url a score which can be used to choose preferred URLs for a given project release. Tz.whlhttpszpypi.python.org) r posixpathbasenamepathendswithr$r# wheel_tagsr2netloc)r6r(trhZ compatibleZis_wheelr*r*r+ score_urls  zLocator.score_urlcCsR|}|rN|j|}|j|}||kr(|}||kr@tjd||ntjd|||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)rnloggerdebug)r6url1url2rWs1s2r*r*r+ prefer_urls   zLocator.prefer_urlcCs t||S)zZ Attempt to split a filename in project name, version and Python version. )r)r6filename project_namer*r*r+rszLocator.split_filenamecCsdd}d}t|\}}}}} } | jjdr.same_projectNzegg=z %s: version hint in fragment: %rr/z.whlTr0z, cSs"g|]}djt|ddqS).N)joinlist).0vr*r*r+ sz8Locator.convert_url_to_download_info..)rbversionrvr(zpython-versionzinvalid path for wheel: %sz No match for project/version: %s)rbrrvr(zpython-versionz %s_digest)NNr)rlower startswithrorp HASHER_HASHmatchgroupsrjr#r$rkrbrrvrr|pyver Exceptionwarningdownloadable_extensionsrgrhlenr)r6r(rwrxrWr2rlriparamsqueryfragmalgodigestZorigpathwheelincluderXrvZextrmrbrrr*r*r+convert_url_to_download_infosf            z$Locator.convert_url_to_download_infocCs4d}x*dD]"}d|}||kr |||f}Pq W|S)z Get a digest from a dictionary by looking at keys of the form 'algo_digest'. Returns a 2-tuple (algo, digest) if found, else None. Currently looks only for SHA256, then MD5. Nsha256md5z %s_digest)rrr*)r6inforWrr<r*r*r+ _get_digest)s  zLocator._get_digestc Cs|jd}|jd}||kr,||}|j}nt|||jd}|j}|j||_}|d}||d|<|j|dkr|j|j||_|dj|t j |||_ |||<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. rbr)r2r(digestsurlsN) popmetadatarr2rr source_urlru setdefaultsetaddlocator) r6rWrrbrdistmdrr(r*r*r+_update_version_data9s   zLocator._update_version_dataFc Csd}t|}|dkr td|t|j}|j|j|_}tjd|t|j |j |j }t |dkr8g}|j } x|D]|} | d krqzyJ|j| stjd|| n,|s| | j r|j| ntjd| |j Wqztk rtjd || YqzXqzWt |d krt||jd }|r8tjd ||d} || }|r|jrN|j|_|jdij| t|_i} |jdi} x&|jD]}|| kr~| || |<q~W| |_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{rrz%s did not match %rz%skipping pre-release version %s of %szerror matching %s with %rr)r<zsorted list: %s)rrr)rrr!r2rO requirementrorptyper=rerbrZ version_classrZ is_prereleaserUrrsortedr<ZextrasrTr download_urlsr)r6r prereleasesrWrr2rOversionsZslistZvclskrdZsdr(r*r*r+locatePsT            zLocator.locate)rBrCrDrErFrG)rHrIrJ)rK)rJ)rL)F)r=r>r?r@source_extensionsbinary_extensionsexcluded_extensionsrkrrRrYrZr\r^r`propertyr2rcrdrernrurrrrrr*r*r*r+rASs.   FrAcs0eZdZdZfddZddZddZZS)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|jf|||_t|dd|_dS)z Initialise an instance. :param url: The URL to use for XML-RPC. :param kwargs: Passed to the superclass constructor. g@)r%N)superrrRbase_urlrr))r6r(kwargs) __class__r*r+rRszPyPIRPCLocator.__init__cCst|jjS)zJ Return all the distribution names known to this locator. )rr)r')r6r*r*r+rdsz%PyPIRPCLocator.get_distribution_namesc Csiid}|jj|d}x|D]}|jj||}|jj||}t|jd}|d|_|d|_|jd|_ |jdg|_ |jd|_ t |}|r|d } | d |_ |j| |_||_|||<xB|D]:} | d } |j| } |d j|tj| | |d | <qWqW|S) N)rrT)r2rbrlicensekeywordssummaryrr(rr)r)Zpackage_releasesZ release_urlsZ release_datarr2rbrrTrrrrrrrrrrr) r6rbrWrrrdatarrrr(rr*r*r+rcs0           zPyPIRPCLocator._get_project)r=r>r?r@rRrdrc __classcell__r*r*)rr+rs rcs0eZdZdZfddZddZddZZS)PyPIJSONLocatorzw This locator uses PyPI's JSON interface. It's very limited in functionality and probably not worth using. c s tt|jf|t||_dS)N)rrrRrr)r6r(r)rr*r+rRszPyPIJSONLocator.__init__cCs tddS)zJ Return all the distribution names known to this locator. zNot available from this locatorN)ra)r6r*r*r+rdsz&PyPIJSONLocator.get_distribution_namescCsiid}t|jdt|}y|jj|}|jj}tj|}t |j d}|d}|d|_ |d|_ |j d|_|j dg|_|j d |_t|}||_|d } |||j <x`|d D]T} | d }|jj||j| |j|<|d j|j tj||j| |d |<qWx|d jD]\} } | |j kr:q"t |j d} |j | _ | | _ t| }||_||| <x\| D]T} | d }|jj||j| |j|<|d j| tj||j| |d |<qpWq"WWn@tk r}z"|jjt|tjd|WYdd}~XnX|S)N)rrz%s/json)r2rrbrrrrrr(rZreleaseszJSON fetch failed: %s) rrr rNopenreaddecodejsonloadsrr2rbrrTrrrrrrrrrrritemsrrQputrro exception)r6rbrWr(resprrrrrrrZinfosZomdodistrXr*r*r+rcsT               " zPyPIJSONLocator._get_project)r=r>r?r@rRrdrcrr*r*)rr+rs rc@s`eZdZdZejdejejBejBZ ejdejejBZ ddZ ejdejZ e ddZd 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||_||_|_|jj|j}|r0|jd|_dS)zk Initialise an instance with the Unicode page contents and the URL they came from. rN)rrr(_basesearchgroup)r6rr(rr*r*r+rRs  z Page.__init__z[^a-z0-9$&+,/:;=?@.#%_\\|-]cCsdd}t}x|jj|jD]}|jd}|dpZ|dpZ|dpZ|dpZ|dpZ|d }|d pr|d pr|d }t|j|}t|}|jj d d|}|j ||fqWt |dddd}|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||||fS)zTidy up an URL.)rrr )r(r2rlrirrrr*r*r+clean%s zPage.links..cleanr0Zrel1Zrel2Zrel3Zrel4Zrel5Zrel6rqrrZurl3cSsdt|jdS)Nz%%%2xr)ordr)rr*r*r+3szPage.links..cSs|dS)Nrr*)rmr*r*r+r7sT)r<reverse) r_hreffinditerr groupdictrrr _clean_resubrr)r6rrWrrrelr(r*r*r+linkss  z Page.linksN)r=r>r?r@recompileISXrrrRrrrr*r*r*r+rs rcseZdZdZejdddddZdfdd Zd d Zd d Z ddZ e j de j ZddZddZddZddZddZe j dZddZZS)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. cCstjttdjS)N)Zfileobj)gzipZGzipFilerrr)br*r*r+rEszSimpleScrapingLocator.cCs|S)Nr*)rr*r*r+rFs)ZdeflaterZnoneN c sftt|jf|t||_||_i|_t|_t j |_ t|_ d|_ ||_tj|_tj|_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)rrrRrrr% _page_cacher_seenr rP _to_fetch _bad_hostsskip_externals num_workers threadingRLock_lock_gplock)r6r(r%rr)rr*r+rRIs    zSimpleScrapingLocator.__init__cCsJg|_x>t|jD]0}tj|jd}|jd|j|jj|qWdS)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) _threadsrangerrZThread_fetchZ setDaemonstartrU)r6irmr*r*r+_prepare_threadscs  z&SimpleScrapingLocator._prepare_threadscCs>x|jD]}|jjdqWx|jD] }|jq$Wg|_dS)zu Tell all the threads to terminate (by sending a sentinel value) and wait for them to do so. N)rrrr|)r6rmr*r*r+ _wait_threadsps    z#SimpleScrapingLocator._wait_threadscCsiid}|jx||_||_t|jdt|}|jj|jj|j z&t j d||j j ||j jWd|jX|`WdQRX|S)N)rrz%s/z Queueing %s)rrWrwrrr rr[rrrorprrr|r)r6rbrWr(r*r*r+rc}s      z"SimpleScrapingLocator._get_projectz<\b(linux-(i\d86|x86_64|arm\w+)|win(32|-amd64)|macosx-?\d+)\bcCs |jj|S)zD Does an URL refer to a platform-specific download? )platform_dependentr)r6r(r*r*r+_is_platform_dependentsz,SimpleScrapingLocator._is_platform_dependentc CsT|j|rd}n|j||j}tjd|||rP|j|j|j|WdQRX|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)rrrwrorprrrW)r6r(rr*r*r+_process_downloads z'SimpleScrapingLocator._process_downloadc Cst|\}}}}}}|j|j|j|jr2d}n~|jrL|j|j rLd}nd|j|js^d}nR|d krld}nD|dkrzd}n6|j|rd}n&|j ddd } | j d krd}nd }t j d |||||S)z Determine whether a link URL from a referring page and with a particular "rel" attribute should be queued for scraping. Fhomepagedownloadhttprfftp:rrZ localhostTz#should_queue: %s (%s) from %s -> %s)rr)rrfr) rrjrrrrrrrsplitrrorp) r6linkZreferrerrr2rlri_rWhostr*r*r+ _should_queues*     z#SimpleScrapingLocator._should_queuecCsx|jj}zyz|r|j|}|dkr(wx\|jD]R\}}||jkr0|jj||j| r0|j|||r0tj d|||jj |q0WWn2t k r}z|j j t |WYdd}~XnXWd|jjX|sPqWdS)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)rrTget_pagerrrrrrorprrrQrrV)r6r(pagerrrXr*r*r+rs&     & zSimpleScrapingLocator._fetchcCsXt|\}}}}}}|dkr:tjjt|r:tt|d}||jkr`|j|}tj d||n|j ddd}d}||j krtj d||nt |d d id }zytj d ||j j||jd } tj d|| j} | jdd} tj| r| j} | j} | jd}|r"|j|}|| } d}tj| }|r@|jd}y| j|} Wn tk rn| jd} YnXt| | }||j| <Wntk r}z |jdkrtjd||WYdd}~Xnt k r}z2tjd|||j!|j j"|WdQRXWYdd}~Xn2t#k rB}ztjd||WYdd}~XnXWd||j|<X|S)a Get the HTML for an URL, possibly from an in-memory cache. XXX TODO Note: this cache is never actually cleared. It's assumed that the data won't get stale over the lifetime of a locator instance (not necessarily true for the default_locator). filez index.htmlzReturning %s from cache: %srrrNzSkipping %s due to bad host %szAccept-encodingZidentity)r;z Fetching %s)r%z Fetched %sz Content-Typer0zContent-Encodingzutf-8zlatin-1izFetch failed: %s: %s)$rosriisdirrrrrrorprrrrNrr%rrTHTML_CONTENT_TYPErZgeturlrdecodersCHARSETrrr UnicodeErrorrrr9rrrrr)r6r(r2rlrirrWrr7rr;Z content_typeZ final_urlrencodingdecoderrrXr*r*r+rsZ              &$ zSimpleScrapingLocator.get_pagez]*>([^<]+)r?r@zlibZ decompressrrRrrrcrrrrrrrrrr rdrr*r*)rr+r;s"   ; rcs8eZdZdZfddZddZddZdd ZZS) DirectoryLocatorz? This class locates distributions in a directory tree. c sN|jdd|_tt|jf|tjj|}tjj|sDt 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) rrrr rRrriabspathrrbase_dir)r6rir)rr*r+rR5s    zDirectoryLocator.__init__cCs |j|jS)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. )rjr)r6rvparentr*r*r+should_includeFszDirectoryLocator.should_includec Csiid}xtj|jD]v\}}}xb|D]Z}|j||r(tjj||}tddttjj|dddf}|j ||}|r(|j ||q(W|j sPqW|S)N)rrrr0) rwalkrrrir|rr rrrr) r6rbrWrootdirsfilesfnr(rr*r*r+rcNs     zDirectoryLocator._get_projectc Cst}xtj|jD]x\}}}xd|D]\}|j||r$tjj||}tddttjj |dddf}|j |d}|r$|j |dq$W|j sPqW|S)zJ Return all the distribution names known to this locator. rr0Nrb) rrrrrrir|rr rrrr)r6rWrrrrr(rr*r*r+rd^s    z'DirectoryLocator.get_distribution_names) r=r>r?r@rRrrcrdrr*r*)rr+r 0s  r c@s eZdZdZddZddZdS) 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 tddS)zJ Return all the distribution names known to this locator. zNot available from this locatorN)ra)r6r*r*r+rdxsz"JSONLocator.get_distribution_namescCsiid}t|}|rx|jdgD]}|ddks$|ddkrBq$t|d|d|jd d |jd }|j}|d |_d |kr|d rd|d f|_|jdi|_|jdi|_|||j <|dj |j t j |d q$W|S)N)rrrZptypeZsdistZ pyversionsourcerbrrzPlaceholder for summary)rr2r(rrZ requirementsexportsr) rrTrr2rrrZ dependenciesrrrrr)r6rbrWrrrrr*r*r+rc~s&    "zJSONLocator._get_projectN)r=r>r?r@rdrcr*r*r*r+rqsrcs(eZdZdZfddZddZZS)DistPathLocatorz This locator finds installed distributions in a path. It can be useful for adding to an :class:`AggregatingLocator`. c s*tt|jf|t|ts t||_dS)zs Initialise an instance. :param distpath: A :class:`DistributionPath` instance to search. N)rrrR isinstancerAssertionErrordistpath)r6rr)rr*r+rRszDistPathLocator.__init__cCsP|jj|}|dkr iid}n,|j|d|jt|jgid|jtdgii}|S)N)rrrr)rZget_distributionrrr)r6rbrrWr*r*r+rcs  zDistPathLocator._get_project)r=r>r?r@rRrcrr*r*)rr+rs rcsReZdZdZfddZfddZddZeej j eZ dd Z d d Z Z S) AggregatingLocatorzI This class allows you to chain and/or merge a list of locators. cs*|jdd|_||_tt|jf|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)rr locatorsrrrR)r6r!r)rr*r+rRs zAggregatingLocator.__init__cs*tt|jx|jD] }|jqWdS)N)rrr\r!)r6r)rr*r+r\s zAggregatingLocator.clear_cachecCs ||_x|jD] }||_qWdS)N)r]r!r2)r6r_rr*r*r+r`s zAggregatingLocator._set_schemec Csi}x|jD]}|j|}|r |jr|jdi}|jdi}|j||jd}|r|rx6|jD]*\}} ||kr||| O<qb| ||<qbW|jd} |r| r| j|q |jdkrd} n$d} x|D]}|jj|rd} PqW| r |}Pq W|S)NrrTF)r!rer rTupdaterrOr) r6rbrWrrrrZdfrrZddfoundr*r*r+rcs8           zAggregatingLocator._get_projectc Cs@t}x4|jD]*}y||jO}Wqtk r6YqXqW|S)zJ Return all the distribution names known to this locator. )rr!rdra)r6rWrr*r*r+rds  z)AggregatingLocator.get_distribution_names)r=r>r?r@rRr\r`rrAr2fgetrcrdrr*r*)rr+rs  ,rzhttps://pypi.python.org/simple/g@)r%legacy)r2z1(?P[\w-]+)\s*\(\s*(==\s*)?(?P[^)]+)\)$c@sLeZdZdZdddZddZddZd d Zd d Zd dZ dddZ dS)DependencyFinderz0 Locate dependencies for distributions. NcCs|pt|_t|jj|_dS)zf Initialise an instance, using the specified locator to locate distributions. N)default_locatorrr!r2)r6rr*r*r+rRs zDependencyFinder.__init__cCsvtjd||j}||j|<||j||jf<xD|jD]:}t|\}}tjd||||jj |t j ||fq4WdS)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) rorpr< dists_by_namedistsrprovidesrprovidedrrr)r6rrbprr*r*r+add_distribution&s    z!DependencyFinder.add_distributioncCs|tjd||j}|j|=|j||jf=xN|jD]D}t|\}}tjd||||j|}|j ||f|s0|j|=q0WdS)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) rorpr<r(r)rr*rr+remove)r6rrbr,rsr*r*r+remove_distribution5s    z$DependencyFinder.remove_distributionc CsBy|jj|}Wn,tk r<|jd}|jj|}YnX|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)r2rOr"r)r6reqtrOrbr*r*r+ get_matcherGs  zDependencyFinder.get_matcherc Csv|j|}|j}t}|j}||krrxL||D]@\}}y|j|}Wntk r\d}YnX|r.|j|Pq.W|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)r2r<rr+rr"r) r6r1rOrbrWr+rproviderrr*r*r+find_providersWs   zDependencyFinder.find_providersc Cs|j|}t}x,|D]$}|j|}|j|js|j|qW|r^|jd||t|fd}nD|j||j|=x"|D]}|jj|tj|qvW|j |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) reqtsrr2rrr frozensetr0rr-) r6r3otherproblemsZrlistZ unmatchedr/rOrWr*r*r+try_to_replaceos"         zDependencyFinder.try_to_replaceFcCsi|_i|_i|_i|_t|p g}d|krH|jd|tdddgO}t|trh|}}tj d|n4|j j ||d}}|dkrt d|tj d |d |_ t}t|g}t|g}x|r|j}|j} | |jkr|j|n"|j| } | |kr |j|| ||j|jB} |j} t} ||krbx2dD]*}d|}||kr4| t|d|O} q4W| | B| B}x>|D]4}|j|}|sNtj d||j j ||d}|dkr| r|j j |d d}|dkrtj d||jd|fn^|j|j}}||f|jkr|j||j||| krN||krN|j|tj d|jxZ|D]R}|j} | |jkr|jj|tj|n"|j| } | |krT|j|| |qTWqvWqWt|jj}x.|D]&}||k|_|jrtj d|jqWtj 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)rNzUnable to locate %rz located %sTtestbuilddevz:%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)r:r;r<)r+r)r(r5rr.rrrorprrrZ requestedrr<r-r9Z run_requiresZ meta_requiresZbuild_requiresgetattrr4rrZname_and_versionrvaluesZbuild_time_dependency)r6rZ meta_extrasrrrr8ZtodoZ install_distsrbr7ZireqtsZsreqtsZereqtsr<rXZ all_reqtsrZ providersr3nrr,r)r*r*r+finds                                zDependencyFinder.find)N)NF) r=r>r?r@rRr-r0r2r4r9r@r*r*r*r+r&s (r&)N)NriorrZloggingrrgrr ImportErrorZdummy_threadingr r0rcompatrrrrr r r r r rrr4rrrrZdatabaserrrrrutilrrrrrrrrr rr!r"rr#r$Z getLoggerr=rorrrrrr&r,r-objectrArrrrr rrrr'rZNAME_VERSION_REr&r*r*r*r+sZ   D ,    ;0E:vA&[