a *žegØÇã@sŽdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZddlmZmZddlmZmZmZmZdd lmZmZmZmZmZmZm Z gd ¢Z!e "e#¡Z$d Z%d Z&d eddde%dfZ'dZ(Gdd„de)ƒZ*Gdd„de)ƒZ+Gdd„de)ƒZ,Gdd„de,ƒZ-Gdd„de-ƒZ.Gdd„de-ƒZ/e.Z0e/Z1Gdd „d e)ƒZ2d*d"d#„Z3d$d%„Z4d&d'„Z5d(d)„Z6dS)+zPEP 376 implementation.é)Úunicode_literalsNé)ÚDistlibExceptionÚ resources)ÚStringIO)Ú get_schemeÚUnsupportedVersionError)ÚMetadataÚMETADATA_FILENAMEÚWHEEL_METADATA_FILENAMEÚLEGACY_METADATA_FILENAME)Úparse_requirementÚcached_propertyÚparse_name_and_versionÚ read_exportsÚ write_exportsÚ CSVReaderÚ CSVWriter)Ú DistributionÚBaseInstalledDistributionÚInstalledDistributionÚEggInfoDistributionÚDistributionPathzpydist-exports.jsonzpydist-commands.jsonÚ INSTALLERÚRECORDÚ REQUESTEDÚ RESOURCESÚSHAREDz .dist-infoc@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú_CachezL A simple cache mapping names and .dist-info paths to distributions cCsi|_i|_d|_dS)zZ Initialise an instance. There is normally one for each DistributionPath. FN)ÚnameÚpathÚ generated©Úself©r$úF/usr/local/lib/python3.9/site-packages/pip/_vendor/distlib/database.pyÚ__init__.sz_Cache.__init__cCs|j ¡|j ¡d|_dS)zC Clear the cache, setting it to its initial state. FN)rÚclearr r!r"r$r$r%r'6s  z _Cache.clearcCs2|j|jvr.||j|j<|j |jg¡ |¡dS)z` Add a distribution to the cache. :param dist: The distribution to add. N)r rÚ setdefaultÚkeyÚappend©r#Údistr$r$r%Úadd>s  z _Cache.addN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r&r'r-r$r$r$r%r)src@s„eZdZdZddd„Zdd„Zdd „ZeeeƒZd d „Z d d „Z dd„Z e dd„ƒZ dd„Zdd„Zddd„Zdd„Zddd„ZdS)rzU Represents a set of distributions installed on a path (typically sys.path). NFcCsD|durtj}||_d|_||_tƒ|_tƒ|_d|_tdƒ|_ dS)a  Create an instance from a path, optionally including legacy (distutils/ setuptools/distribute) distributions. :param path: The path to use, as a list of directories. If not specified, sys.path is used. :param include_egg: If True, this instance will look for and return legacy distributions as well as those based on PEP 376. NTÚdefault) Úsysr Ú _include_distÚ _include_eggrÚ_cacheÚ _cache_eggÚ_cache_enabledrÚ_scheme)r#r Z include_eggr$r$r%r&Ms zDistributionPath.__init__cCs|jS©N©r8r"r$r$r%Ú_get_cache_enabledasz#DistributionPath._get_cache_enabledcCs ||_dSr:r;)r#Úvaluer$r$r%Ú_set_cache_enableddsz#DistributionPath._set_cache_enabledcCs|j ¡|j ¡dS)z, Clears the internal cache. N)r6r'r7r"r$r$r%Ú clear_cacheis zDistributionPath.clear_cachec csÀtƒ}|jD]¬}t |¡}|dur&q | d¡}|r |js| ¡|jj ¡D] }|Vq0|jrZ|jj ¡D] }|VqNdS)a5 Provides an iterator that looks for distributions and returns :class:`InstalledDistribution` or :class:`EggInfoDistribution` instances for each one of them. :rtype: iterator of :class:`InstalledDistribution` and :class:`EggInfoDistribution` instances N)r8rfrhr6r Úvaluesr5r7r+r$r$r%Úget_distributionsÇs   z"DistributionPath.get_distributionscCs€d}| ¡}|js4| ¡D]}|j|kr|}q|qnH| ¡||jjvrZ|jj|d}n"|jr|||jjvr||jj|d}|S)a= Looks for a named distribution on the path. This function only returns the first result found, as no more than one value is expected. If nothing is found, ``None`` is returned. :rtype: :class:`InstalledDistribution`, :class:`EggInfoDistribution` or ``None`` Nr) Úlowerr8rfr)rhr6rr5r7)r#rÚresultr,r$r$r%Úget_distributionÝs    z!DistributionPath.get_distributionc csÆd}|durHz|j d||f¡}Wn"tyFtd||fƒ‚Yn0| ¡D]p}t|dƒslt d|¡qP|j}|D]H}t |ƒ\}}|dur¢||kr¾|VqPqv||krv|  |¡rv|VqPqvqPdS)a Iterates over all distributions to find which distributions provide *name*. If a *version* is provided, it will be used to filter the results. This function only returns the first result found, since no more than one values are expected. If the directory is not found, returns ``None``. :parameter version: a version specifier that indicates the version required, conforming to the format in ``PEP-345`` :type name: string :type version: string Nú%s (%s)zinvalid name or version: %r, %rÚprovideszNo "provides": %s) r9ÚmatcherÚ ValueErrorrrpÚhasattrrWrXrurÚmatch) r#rrmrvr,ÚprovidedÚpÚp_nameÚp_verr$r$r%Úprovides_distribution÷s&    z&DistributionPath.provides_distributioncCs(| |¡}|durtd|ƒ‚| |¡S)z5 Return the path to a resource file. Nzno distribution named %r found)rsÚ LookupErrorÚget_resource_path)r#rÚ relative_pathr,r$r$r%Ú get_file_paths  zDistributionPath.get_file_pathccsX| ¡D]J}|j}||vr||}|dur>||vrR||Vq| ¡D] }|VqFqdS)zÙ Return all of the exported entries in a particular category. :param category: The category to search for entries. :param name: If specified, only entries with that name are returned. N)rpÚexportsro)r#Úcategoryrr,raÚdÚvr$r$r%Úget_exported_entries(s   z%DistributionPath.get_exported_entries)NF)N)N)r.r/r0r1r&r<r>ÚpropertyZ cache_enabledr?rfrhÚ classmethodrnrprsr~r‚r‡r$r$r$r%rHs  .  ( rc@s¬eZdZdZdZdZdd„Zedd„ƒZeZ edd„ƒZ ed d „ƒZ d d „Z ed d„ƒZ edd„ƒZedd„ƒZedd„ƒZedd„ƒZdd„Zdd„Zdd„Zdd„ZdS) rzª A base class for distributions, whether installed or from indexes. Either way, it must have some metadata, so that's all that's needed for construction. FcCsL||_|j|_|j ¡|_|j|_d|_d|_d|_d|_t ƒ|_ i|_ dS)zŠ Initialise an instance. :param metadata: The instance of :class:`Metadata` describing this distribution. N) rErrqr)rmÚlocatorÚdigestÚextrasÚcontextrKZ download_urlsÚdigests)r#rEr$r$r%r&Ms zDistribution.__init__cCs|jjS)zH The source archive download URL for this distribution. )rEÚ source_urlr"r$r$r%r^szDistribution.source_urlcCsd|j|jfS)zX A utility property which displays the name and version in parentheses. rt©rrmr"r$r$r%Úname_and_versiongszDistribution.name_and_versioncCs.|jj}d|j|jf}||vr*| |¡|S)z A set of distribution names and versions provided by this distribution. :return: A set of "name (version)" strings. rt)rErurrmr*)r#ÚplistÚsr$r$r%runs  zDistribution.providescCs:|j}t||ƒ}t d|j||¡t|j||j|jdƒS)Nz)%s: got requirements %r from metadata: %r)rŒrF) rEÚgetattrrWrXrrKÚget_requirementsrŒr)r#Zreq_attrÚmdZreqtsr$r$r%Ú_get_requirementszs zDistribution._get_requirementscCs | d¡S)NÚ run_requires©r—r"r$r$r%r˜€szDistribution.run_requirescCs | d¡S)NÚ meta_requiresr™r"r$r$r%rš„szDistribution.meta_requirescCs | d¡S)NÚbuild_requiresr™r"r$r$r%r›ˆszDistribution.build_requirescCs | d¡S)NÚ test_requiresr™r"r$r$r%rœŒszDistribution.test_requirescCs | d¡S)NÚ dev_requiresr™r"r$r$r%rszDistribution.dev_requiresc Cs²t|ƒ}t|jjƒ}z| |j¡}Wn4tyXt d|¡|  ¡d}| |¡}Yn0|j }d}|j D]B}t |ƒ\}} ||kr„qjz|  | ¡}Wq®WqjtyªYqj0qj|S)z¿ Say if this instance matches (fulfills) a requirement. :param req: The requirement to match. :rtype req: str :return: True if it matches, else False. ú+could not read version %r - using name onlyrF)r rrErDrvÚ requirementrrWr\Úsplitr)rurry) r#ÚreqrarDrvrrrr{r|r}r$r$r%Úmatches_requirement”s(          z Distribution.matches_requirementcCs(|jrd|j}nd}d|j|j|fS)zC Return a textual representation of this instance, z [%s]r@z)rrrm)r#Úsuffixr$r$r%Ú__repr__µs zDistribution.__repr__cCs>t|ƒt|ƒurd}n$|j|jko8|j|jko8|j|jk}|S)a< See if this distribution is the same as another. :param other: The distribution to compare with. To be equal to one another. distributions must have the same type, name, version and source_url. :return: True if it is the same, else False. F)Útyperrmr)r#Úotherrrr$r$r%Ú__eq__¿s$zDistribution.__eq__cCst|jƒt|jƒt|jƒS)zH Compute hash in a way which matches the equality test. )Úhashrrmrr"r$r$r%Ú__hash__ÍszDistribution.__hash__N)r.r/r0r1Zbuild_time_dependencyÚ requestedr&rˆrÚ download_urlr‘rur—r˜ršr›rœrr¢r¤r§r©r$r$r$r%r;s4        ! rcs0eZdZdZdZd‡fdd„ Zddd„Z‡ZS) rz] This is the base class for installed distributions (whether PEP 376 or legacy). Ncs tt|ƒ |¡||_||_dS)a Initialise an instance. :param metadata: An instance of :class:`Metadata` which describes the distribution. This will normally have been initialised from a metadata file in the ``path``. :param path: The path of the ``.dist-info`` or ``.egg-info`` directory for the distribution. :param env: This is normally the :class:`DistributionPath` instance where this distribution was found. N)Úsuperrr&r Ú dist_path)r#rEr rF©Ú __class__r$r%r&Üs z"BaseInstalledDistribution.__init__cCsd|dur|j}|dur"tj}d}ntt|ƒ}d|j}||ƒ ¡}t |¡ d¡ d¡}d||fS)a” Get the hash of some data, using a particular hash algorithm, if specified. :param data: The data to be hashed. :type data: bytes :param hasher: The name of a hash implementation, supported by hashlib, or ``None``. Examples of valid values are ``'sha1'``, ``'sha224'``, ``'sha384'``, '``sha256'``, ``'md5'`` and ``'sha512'``. If no hasher is specified, the ``hasher`` attribute of the :class:`InstalledDistribution` instance is used. If the hasher is determined to be ``None``, MD5 is used as the hashing algorithm. :returns: The hash of the data. If a hasher was explicitly specified, the returned hash will be prefixed with the specified hasher followed by '='. :rtype: str Nr@z%s=ó=Úasciiú%s%s) ÚhasherÚhashlibÚmd5r”r‹Úbase64Úurlsafe_b64encodeÚrstripÚdecode)r#Údatar³Úprefixr‹r$r$r%Úget_hashës   z"BaseInstalledDistribution.get_hash)N)N)r.r/r0r1r³r&r¼Ú __classcell__r$r$r®r%rÔsrcs¸eZdZdZdZd'‡fdd„ Zdd„Zdd „Zd d „Ze d d „ƒZ dd„Z dd„Z dd„Z dd„Zd(dd„Zdd„Ze dd„ƒZd)dd„Zdd „Zd!d"„Zd#d$„Zd%d&„ZejZ‡ZS)*ra  Created with the *path* of the ``.dist-info`` directory provided to the constructor. It reads the metadata contained in ``pydist.json`` when it is instantiated., or uses a passed in Metadata instance (useful for when dry-run mode is being used). Úsha256Nc s~g|_t |¡|_}|dur*td|ƒ‚|rP|jrP||jjvrP|jj|j}nˆ|durØ|  t ¡}|durt|  t ¡}|dur†|  t ¡}|duržtdt |fƒ‚t  | ¡¡}t|dd}Wdƒn1sÎ0Ytt|ƒ |||¡|r|jr|j |¡|  d¡}|du|_tj |d¡}tj |¡rzt|dƒ}| ¡ d¡} Wdƒn1sf0Y|  ¡|_dS) Nzfinder unavailable for %szno %s found in %srArBrú top_level.txtÚrbúutf-8)ÚmodulesrrLr`rwr8r6r rErMr r r rTrUrVr r¬rr&r-rªÚosrSÚexistsÚopenÚreadr¹Ú splitlines) r#r rErFr`rarcr{Úfrºr®r$r%r&s4    *    .zInstalledDistribution.__init__cCsd|j|j|jfS)Nz#©rrmr r"r$r$r%r¤6szInstalledDistribution.__repr__cCsd|j|jfS©Nz%s %srr"r$r$r%Ú__str__9szInstalledDistribution.__str__c Csªg}| d¡}t | ¡¡z}t|dP}|D]:}dd„tt|ƒdƒDƒ}||\}}} | ||| f¡q.Wdƒn1s~0YWdƒn1sœ0Y|S)a" Get the list of installed files for the distribution :return: A list of tuples of path, hash and size. Note that hash and size might be ``None`` for some entries. The path is exactly as stored in the file (which is as in PEP 376). r©rccSsg|]}d‘qSr:r$)Ú.0Úir$r$r%Ú Kóz6InstalledDistribution._get_records..éN)Úget_distinfo_resourcerTrUrVrÚrangeÚlenr*) r#ÚresultsrarcZ record_readerÚrowÚmissingr ÚchecksumÚsizer$r$r%Ú _get_records<s  Nz"InstalledDistribution._get_recordscCsi}| t¡}|r| ¡}|S)a Return the information exported by this distribution. :return: A dictionary of exports, mapping an export category to a dict of :class:`ExportEntry` instances describing the individual export entries, and keyed by name. )rÒÚEXPORTS_FILENAMEr)r#rrrar$r$r%rƒSs  zInstalledDistribution.exportscCsLi}| t¡}|rHt | ¡¡}t|ƒ}Wdƒn1s>0Y|S)zý Read exports data from a file in .ini format. :return: A dictionary of exports, mapping an export category to a list of :class:`ExportEntry` instances describing the individual export entries. N)rÒrÛrTrUrVr)r#rrrarcr$r$r%ras  &z"InstalledDistribution.read_exportscCsB| t¡}t|dƒ}t||ƒWdƒn1s40YdS)a Write a dictionary of exports to a file in .ini format. :param exports: A dictionary of exports, mapping an export category to a list of :class:`ExportEntry` instances describing the individual export entries. ÚwN)Úget_distinfo_filerÛrÅr)r#rƒÚrfrÈr$r$r%rps  z#InstalledDistribution.write_exportsc Cs¬| d¡}t | ¡¡t}t|dJ}|D]4\}}||kr*|WdƒWdƒSq*Wdƒn1st0YWdƒn1s’0Ytd|ƒ‚dS)aW NOTE: This API may change in the future. Return the absolute path to a resource file with the given relative path. :param relative_path: The path, relative to .dist-info, of the resource of interest. :return: The absolute path where the resource is to be found. rrÌNz3no resource file with relative path %r is installed)rÒrTrUrVrÚKeyError)r#rrarcZresources_readerÚrelativeÚ destinationr$r$r%r€{s   bÿz'InstalledDistribution.get_resource_pathccs| ¡D] }|VqdS)zª Iterates over the ``RECORD`` entries and returns a tuple ``(path, hash, size)`` for each line. :returns: iterator of (path, hash, size) N)rÚ)r#rrr$r$r%Úlist_installed_filess z*InstalledDistribution.list_installed_filesFc CsRtj |d¡}tj |j¡}| |¡}tj |d¡}| d¡}t d|¡|rRdSt|ƒâ}|D]¢}tj  |¡sz|  d¡r„d} } nHdtj  |¡} t |dƒ} |  |  ¡¡} Wdƒn1sÂ0Y| |¡sä|rò| |¡ròtj ||¡}| || | f¡q`| |¡rtj ||¡}| |ddf¡Wdƒn1sD0Y|S)zÖ Writes the ``RECORD`` file, using the ``paths`` iterable passed in. Any existing ``RECORD`` file is silently overwritten. prefix is used to determine when to write absolute paths. r@rú creating %sN©z.pycz.pyoz%drÀ)rÃr rSÚdirnameÚ startswithrÝrWÚinforÚisdirrPÚgetsizerÅr¼rÆÚrelpathÚwriterow) r#Úpathsr»Údry_runÚbaseZbase_under_prefixÚ record_pathÚwriterr Ú hash_valuerÙÚfpr$r$r%Úwrite_installed_files™s,      , 0z+InstalledDistribution.write_installed_filesc Cs0g}tj |j¡}| d¡}| ¡D]\}}}tj |¡sJtj ||¡}||krTq$tj |¡st| |dddf¡q$tj  |¡r$t tj  |¡ƒ}|r°||kr°| |d||f¡q$|r$d|vrÎ|  dd¡d}nd }t |d ƒ<} | |  ¡|¡} | |kr | |d || f¡Wd ƒq$1s 0Yq$|S) ᨠChecks that the hashes and sizes of the files in ``RECORD`` are matched by the files themselves. Returns a (possibly empty) list of mismatches. Each entry in the mismatch list will be a tuple consisting of the path, 'exists', 'size' or 'hash' according to what didn't match (existence is checked first, then size, then hash), the expected value and the actual value. rrÄTFrÙú=rrNrÀr¨)rÃr rårÝrâÚisabsrSrÄr*ÚisfileÚstrrér rÅr¼rÆ) r#Ú mismatchesrîrïr rñrÙZ actual_sizer³rÈZ actual_hashr$r$r%Úcheck_installed_files»s.        4z+InstalledDistribution.check_installed_filescCsži}tj |jd¡}tj |¡rštj|ddd}| ¡ ¡}Wdƒn1sR0Y|D]8}| dd¡\}}|dkr|  |g¡  |¡q`|||<q`|S) a  A dictionary of shared locations whose keys are in the set 'prefix', 'purelib', 'platlib', 'scripts', 'headers', 'data' and 'namespace'. The corresponding value is the absolute path of that category for this distribution, and takes into account any paths selected by the user at installation time (e.g. via command-line arguments). In the case of the 'namespace' key, this would be a list of absolute paths for the roots of namespace packages in this distribution. The first time this property is accessed, the relevant information is read from the SHARED file in the .dist-info directory. rrarÁ©ÚencodingNrõrÚ namespace) rÃr rSr÷ÚcodecsrÅrÆrÇr r(r*)r#rrÚ shared_pathrÈÚlinesÚliner)r=r$r$r%Úshared_locationsÞs * z&InstalledDistribution.shared_locationsc CsÀtj |jd¡}t d|¡|r$dSg}dD].}||}tj ||¡r,| d||f¡q,| dd¡D]}| d|¡qhtj |d d d  }|  d  |¡¡Wdƒn1s²0Y|S) aa Write shared location information to the SHARED file in .dist-info. :param paths: A dictionary as described in the documentation for :meth:`shared_locations`. :param dry_run: If True, the action is logged but no file is actually written. :return: The path of the file written to. rrãN)r»ÚlibÚheadersÚscriptsrºz%s=%srýr$z namespace=%srÜrÁrûÚ ) rÃr rSrWrçrèr*ÚgetrþrÅÚwrite) r#rìrírÿrr)r ÚnsrÈr$r$r%Úwrite_shared_locationsùs  .z,InstalledDistribution.write_shared_locationscCsF|tvrtd||jfƒ‚t |j¡}|dur.set_name_and_version) r r­r8r7rErrmÚ _get_metadatar-r¬rr&)r#r rFrrEr®r$r%r&Ws   zEggInfoDistribution.__init__csäd}dd„‰‡fdd„}d}}| d¡rôtj |¡r„tj |d¡}tj |d¡}t|dd }tj |d ¡} tj |d ¡}|| ƒ}nnt |¡} t|   d ¡  d ¡ƒ} t| dd}z,|   d¡} |   d¡  d¡}ˆ|   d¡ƒ}Wnt yðd}Yn0nf| d¡rNtj |¡r@tj |d ¡} || ƒ}tj |d¡}tj |d ¡}t|dd }n t d|ƒ‚|rj|  |¡|durÆ|durÆtj |¡rÆt|dƒ} |  ¡  d¡}Wdƒn1s¼0Y|sÒg}n| ¡}||_|S)NcSsªg}| ¡}|D]”}| ¡}|s"q| d¡r‰rÐzQEggInfoDistribution._get_metadata..parse_requires_data..rt) rÇÚstriprærWr\r rŒÚ constraintsr*rrS)rºÚreqsrrraZconsr$r$r%Úparse_requires_dataps(    z>EggInfoDistribution._get_metadata..parse_requires_datacsZg}z>t |dd¡}ˆ| ¡ƒ}Wdƒn1s60YWntyTYn0|S)z’Create a list of dependencies from a requires.txt file. *req_path*: the path to a setuptools-produced requires.txt file. rarÁN)rþrÅrÆÚIOError)Úreq_pathrrò©rr$r%Úparse_requires_paths. z>EggInfoDistribution._get_metadata..parse_requires_pathrHzEGG-INFOzPKG-INFOrA)r rDz requires.txtr¿zEGG-INFO/PKG-INFOÚutf8rBzEGG-INFO/requires.txtzEGG-INFO/top_level.txtrÁrGz,path must end with .egg-info or .egg, got %rrÀ)rPrÃr rèrSr Ú zipimportÚ zipimporterrÚget_datar¹rrZadd_requirementsrÄrÅrÆrÇrÂ)r#r Úrequiresr Ztl_pathZtl_datar{Ú meta_pathrErZzipfrCrºrÈr$rr%rmsT           ÿ   .z!EggInfoDistribution._get_metadatacCsd|j|j|jfS)Nz!rÉr"r$r$r%r¤ÈszEggInfoDistribution.__repr__cCsd|j|jfSrÊrr"r$r$r%rËËszEggInfoDistribution.__str__cCs`g}tj |jd¡}tj |¡r\| ¡D]2\}}}||kr._md5cSs t |¡jSr:)rÃÚstatÚst_size)r r$r$r%Ú_sizeñsz7EggInfoDistribution.list_installed_files.._sizer'rarÁrûzNon-existent file: %sräN) rÃr rSrÄrþrÅrÚnormpathrWr\rPrèr*)r#r+r.rïrrrÈrr{r$r$r%râás"     8z(EggInfoDistribution.list_installed_filesFccs®tj |jd¡}tj |¡rªd}tj|dddj}|D]T}| ¡}|dkrPd}q6|s6tj tj |j|¡¡}| |j¡r6|r„|Vq6|Vq6Wdƒn1s 0YdS) a  Iterates over the ``installed-files.txt`` entries and returns paths for each line if the path is pointing to a file located in the ``.egg-info`` directory or one of its subdirectories. :parameter absolute: If *absolute* is ``True``, each returned path is transformed into a local absolute path. Otherwise the raw value from ``installed-files.txt`` is returned. :type absolute: boolean :returns: iterator of paths r'TrarÁrûz./FN) rÃr rSrÄrþrÅrr/ræ)r#ÚabsoluterïÚskiprÈrr{r$r$r%rs   z'EggInfoDistribution.list_distinfo_filescCst|tƒo|j|jkSr:)rgrr rr$r$r%r§$szEggInfoDistribution.__eq__)N)F)r.r/r0r1rªrr&rr¤rËrúrârr§rr©r½r$r$r®r%rNs[& rc@s^eZdZdZdd„Zdd„Zddd„Zd d „Zd d „Zddd„Z ddd„Z dd„Z dd„Z dS)ÚDependencyGraphaù Represents a dependency graph between distributions. The dependency relationships are stored in an ``adjacency_list`` that maps distributions to a list of ``(other, label)`` tuples where ``other`` is a distribution and the edge is labeled with ``label`` (i.e. the version specifier, if such was provided). Also, for more efficient traversal, for every distribution ``x``, a list of predecessors is kept in ``reverse_list[x]``. An edge from distribution ``a`` to distribution ``b`` means that ``a`` depends on ``b``. If any missing dependencies are found, they are stored in ``missing``, which is a dictionary that maps distributions to a list of requirements that were not provided by any other distributions. cCsi|_i|_i|_dSr:)Úadjacency_listÚ reverse_listr×r"r$r$r%r&?szDependencyGraph.__init__cCsg|j|<g|j|<dS)zÍAdd the *distribution* to the graph. :type distribution: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` N)r3r4)r#Ú distributionr$r$r%Úadd_distributionDs z DependencyGraph.add_distributionNcCs6|j| ||f¡||j|vr2|j| |¡dS)ašAdd an edge from distribution *x* to distribution *y* with the given *label*. :type x: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` :type y: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` :type label: ``str`` or ``None`` N)r3r*r4)r#ÚxÚyÚlabelr$r$r%Úadd_edgeNs zDependencyGraph.add_edgecCs&t d||¡|j |g¡ |¡dS)a Add a missing *requirement* for the given *distribution*. :type distribution: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` :type requirement: ``str`` z %s missing %rN)rWrXr×r(r*)r#r5rŸr$r$r%Ú add_missing]szDependencyGraph.add_missingcCsd|j|jfSrÊrr+r$r$r%Ú _repr_disthszDependencyGraph._repr_distrcCsŠ| |¡g}|j|D]h\}}| |¡}|dur| d|j|jf¡q>q|sÞt|ƒdkrÞ| d¡| d¡| d¡|D]}| d |j¡| d ¡q´| d ¡| d ¡dS) a9Writes a DOT output for the graph to the provided file *f*. If *skip_disconnected* is set to ``True``, then all distributions that are not dependent on any other distribution are skipped. :type f: has to support ``file``-like operations :type skip_disconnected: ``bool`` zdigraph dependencies { rNz"%s" -> "%s" [label="%s"] z "%s" -> "%s" zsubgraph disconnected { zlabel = "Disconnected" zbgcolor = red z"%s"rz} )rr3ÚitemsrÔr*r)r#rÈZskip_disconnectedÚ disconnectedr,Úadjsr¦r9r$r$r%Úto_dotxs$         zDependencyGraph.to_dotcsÂg}i}|j ¡D]\}}|dd…||<qg‰t| ¡ƒdd…D]\}}|sDˆ |¡||=qDˆshq²| ¡D]\}}‡fdd„|Dƒ||<qpt ddd„ˆDƒ¡| ˆ¡q,|t| ¡ƒfS)aa Perform a topological sort of the graph. :return: A tuple, the first element of which is a topologically sorted list of distributions, and the second element of which is a list of distributions that cannot be sorted because they have circular dependencies and so form a cycle. Ncs g|]\}}|ˆvr||f‘qSr$r$)rÍr…ra©Ú to_remover$r%rϰrÐz4DependencyGraph.topological_sort..zMoving to result: %scSsg|]}d|j|jf‘qS)rtr)rÍr…r$r$r%rϱrÐ)r3rBÚlistr*rWrXr>Úkeys)r#rrÚalistÚkr†r$rFr%Útopological_sort—s   z DependencyGraph.topological_sortcCs2g}|j ¡D]\}}| | |¡¡qd |¡S)zRepresentation of the graphr)r3rBr*r=rS)r#r@r,rDr$r$r%r¤µszDependencyGraph.__repr__)N)r)T) r.r/r0r1r&r6r:r;r<r=rErLr¤r$r$r$r%r2/s   r2r2c CsRt|ƒ}tƒ}i}|D]L}| |¡|jD]6}t|ƒ\}}t d|||¡| |g¡ ||f¡q*q|D]ä}|j |j B|j B|j B}|D]Â} z|  | ¡} Wn4tyÎt d| ¡|  ¡d}|  |¡} Yn0| j}d} ||vr:||D]L\}} z|  |¡} Wntyd} Yn0| rì| || | ¡d} q:qì| sˆ| || ¡qˆqh|S)a6Makes a dependency graph from the given distributions. :parameter dists: a list of distributions :type dists: list of :class:`distutils2.database.InstalledDistribution` and :class:`distutils2.database.EggInfoDistribution` instances :rtype: a :class:`DependencyGraph` instance zAdd to provided: %s, %s, %sržrFT)rr2r6rurrWrXr(r*r˜ršr›rrvrr\r r)ryr:r;)ÚdistsrDÚgraphrzr,r{rrmr%r¡rvÚmatchedÚproviderryr$r$r%Ú make_graph½sB        rQcCsv||vrtd|jƒ‚t|ƒ}|g}|j|}|rh| ¡}| |¡|j|D]}||vrN| |¡qNq.| d¡|S)zÚRecursively generate a list of distributions from *dists* that are dependent on *dist*. :param dists: a list of distributions :param dist: a distribution, member of *dists* for which we are interested ú1given distribution %r is not a member of the listr)rrrQr4Úpopr*)rMr,rNÚdepÚtodor…Úsuccr$r$r%Úget_dependent_distsñsÿ   rWc Cs ||vrtd|jƒ‚t|ƒ}tƒ}|j|}tdd„|Dƒƒ}|rœ| ¡d}| |¡|j|}|D]0}|d}||vrh||vrh| |¡| |¡qhq@|S)aRecursively generate a list of distributions from *dists* that are required by *dist*. :param dists: a list of distributions :param dist: a distribution, member of *dists* for which we are interested in finding the dependencies. rRcss|]}|dVqdS)rNr$)rÍÚtr$r$r%rrÐz%get_required_dists..r)rrrQrKr3rSr-r*) rMr,rNr¡rUr_r…Z pred_listÚpredr$r$r%Úget_required_dists s$ÿ     rZcKs8| dd¡}tfi|¤Ž}||_||_|p,d|_t|ƒS)zO A convenience method for making a dist given just a name and version. ÚsummaryzPlaceholder for summary)rSr rrmr[r)rrmÚkwargsr[r–r$r$r%Ú make_dist(s   r])r2)7r1Ú __future__rr¶rþrTr´ÚloggingrÃrRr3r"r@rrÚcompatrrmrrrEr r r r Úutilr rrrrrrÚ__all__Ú getLoggerr.rWrÛZCOMMANDS_FILENAMEr rQrrrrrrrrYrZr2rQrWrZr]r$r$r$r%ÚsP  $ t7E^ 4