U oÏ aeÇã@s”dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZddlmZmZddlmZmZmZmZdd lmZmZmZmZmZmZm Z d d d d dgZ!e "e#¡Z$dZ%dZ&deddde%dfZ'dZ(Gdd„de)ƒZ*Gdd„de)ƒZ+Gdd „d e)ƒZ,Gdd „d e,ƒZ-Gdd „d e-ƒZ.Gdd „d e-ƒZ/e.Z0e/Z1Gdd„de)ƒ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$ú]C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_vendor\distlib\database.pyÚ__init__1sz_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'9s  z _Cache.clearcCs2|j|jkr.||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%ÚaddAs  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|dkrtj}||_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&Os zDistributionPath.__init__cCs|jS©N©r8r"r$r$r%Ú_get_cache_enabledcsz#DistributionPath._get_cache_enabledcCs ||_dSr:r;)r#Úvaluer$r$r%Ú_set_cache_enabledfsz#DistributionPath._set_cache_enabledcCs|j ¡|j ¡dS)z, Clears the internal cache. N)r6r'r7r"r$r$r%Ú clear_cacheks zDistributionPath.clear_cachec csDtƒ}|jD]0}t |¡}|dkr&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)r8r^r`r6r Úvaluesr5r7r+r$r$r%Úget_distributionsÈs   z"DistributionPath.get_distributionscCs€d}| ¡}|js4| ¡D]}|j|kr|}q|qnH| ¡||jjkrZ|jj|d}n"|jr|||jjkr||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) Úlowerr8r^r)r`r6rr5r7)r#rÚresultr,r$r$r%Úget_distributionÞs    z!DistributionPath.get_distributionc csÈd}|dk rJz|j d||f¡}Wn$tk rHtd||fƒ‚YnX| ¡D]p}t|dƒsnt d|¡qR|j}|D]H}t |ƒ\}}|dkr¤||krÀ|VqRqx||krx|  |¡rx|VqRqxqRdS)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Ú ValueErrorrrhÚhasattrrUrVrmrÚmatch) r#rrernr,ÚprovidedÚpÚp_nameÚp_verr$r$r%Úprovides_distributionøs*ÿ    z&DistributionPath.provides_distributioncCs(| |¡}|dkrtd|ƒ‚| |¡S)z5 Return the path to a resource file. Nzno distribution named %r found)rkÚ LookupErrorÚget_resource_path)r#rÚ relative_pathr,r$r$r%Ú get_file_path!s  zDistributionPath.get_file_pathccsX| ¡D]J}|j}||kr||}|dk r>||krR||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)rhÚexportsrg)r#Úcategoryrr,r[ÚdÚvr$r$r%Úget_exported_entries*s   z%DistributionPath.get_exported_entries)NF)N)N)r.r/r0r1r&r<r>ÚpropertyZ cache_enabledr?r^r`Ú classmethodrfrhrkrvrzrr$r$r$r%rKs  ,  ) c@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) rErrir)reÚlocatorÚdigestÚextrasÚcontextrIZ download_urlsÚdigests)r#rEr$r$r%r&Os 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. rl©rrer"r$r$r%Úname_and_versioniszDistribution.name_and_versioncCs.|jj}d|j|jf}||kr*| |¡|S)z A set of distribution names and versions provided by this distribution. :return: A set of "name (version)" strings. rl)rErmrrer*)r#ÚplistÚsr$r$r%rmps  zDistribution.providescCs8|j}t d| ¡¡t||ƒ}t|j||j|jdƒS)Nz%Getting requirements from metadata %r)r„rF) rErUrVZtodictÚgetattrrIÚget_requirementsr„r…)r#Zreq_attrÚmdZreqtsr$r$r%Ú_get_requirements|s   ÿzDistribution._get_requirementscCs | d¡S)NÚ run_requires©rr"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%r•“szDistribution.dev_requiresc Cs¶t|ƒ}t|jjƒ}z| |j¡}Wn6tk rZt d|¡|  ¡d}| |¡}YnX|j }d}|j D]D}t |ƒ\}} ||kr†qlz|  | ¡}Wq²Wqltk r®YqlXql|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 rrErDrnÚ requirementrrUÚwarningÚsplitr)rmrrq) r#Úreqr[rDrnrrjrsrtrur$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)r‡rre)r#Úsuffixr$r$r%Ú__repr__¹s zDistribution.__repr__cCs>t|ƒt|ƒk rd}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)Útyperrer‡)r#Úotherrjr$r$r%Ú__eq__Ãs  ÿ þzDistribution.__eq__cCst|jƒt|jƒt|jƒS)zH Compute hash in a way which matches the equality test. )Úhashrrer‡r"r$r$r%Ú__hash__ÓszDistribution.__hash__N)r.r/r0r1Zbuild_time_dependencyÚ requestedr&r€r‡Ú download_urlr‰rmrrr’r“r”r•r›rr r¢r$r$r$r%r=s4        " cs0eZdZdZdZd‡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|dkr|j}|dkr"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Úscs¸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 sPg|_t |¡|_}|dkr*td|ƒ‚|rP|jrP||jjkrP|jj|j}nt|dkrÄ|  t ¡}|dkrt|  t ¡}|dkr†|  d¡}|dkržtdt |fƒ‚t   | ¡¡}t|dd}W5QRXtt|ƒ |||¡|rî|jrî|j |¡|  d¡}|dk |_tj |d¡}tj |¡rLt|dƒ}| ¡ d ¡} W5QRX|  ¡|_dS) Nzfinder unavailable for %sÚMETADATAzno %s found in %srArBrú top_level.txtÚrbúutf-8)ÚmodulesrrJrZror8r6r rErKr r rRrSrTr r¥rr&r-r£ÚosrQÚexistsÚopenÚreadr²Ú splitlines) r#r rErFrZr[r]rsÚfr³r§r$r%r&s8    ÿ     zInstalledDistribution.__init__cCsd|j|j|jfS)Nz#©rrer r"r$r$r%r=s ÿzInstalledDistribution.__repr__cCsd|j|jfS©Nz%s %srˆr"r$r$r%Ú__str__AszInstalledDistribution.__str__c Cs‚g}| d¡}t | ¡¡\}t|dF}|D]:}dd„tt|ƒdƒDƒ}||\}}} | ||| f¡q.W5QRXW5QRX|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©r]cSsg|]}d‘qSr:r$)Ú.0Úir$r$r%Ú Ssz6InstalledDistribution._get_records..é)Úget_distinfo_resourcerRrSrTrÚrangeÚlenr*) r#Úresultsr[r]Z record_readerÚrowÚmissingr ÚchecksumÚsizer$r$r%Ú _get_recordsDs  &z"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#rjr[r$r$r%r{[s  zInstalledDistribution.exportsc Cs8i}| t¡}|r4t | ¡¡}t|ƒ}W5QRX|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. )rËrÔrRrSrTr)r#rjr[r]r$r$r%ris  z"InstalledDistribution.read_exportsc Cs.| t¡}t|dƒ}t||ƒW5QRXdS)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%rxs  z#InstalledDistribution.write_exportsc Cs€| d¡}t | ¡¡R}t|d<}|D]0\}}||kr*|W5QR£W5QR£Sq*W5QRXW5QRXtd|ƒ‚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Æz3no resource file with relative path %r is installedN)rËrRrSrTrÚKeyError)r#ryr[r]Zresources_readerÚrelativeZ destinationr$r$r%rxƒs   6ÿ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#rjr$r$r%Úlist_installed_files—s z*InstalledDistribution.list_installed_filesFc Cs(tj |d¡}tj |j¡}| |¡}tj |d¡}| d¡}t d|¡|rRdSt|ƒÄ}|D]Ž}tj  |¡sz|  d¡r„d} } n4dtj  |¡} t |dƒ} |  |  ¡¡} W5QRX| |¡sÐ|rÞ| |¡rÞtj ||¡}| || | f¡q`| |¡r tj ||¡}| |ddf¡W5QRX|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 rQÚdirnameÚ startswithrÖrUÚinforÚisdirrNÚgetsizer¿rµrÀÚrelpathÚwriterow) r#Úpathsr´Údry_runÚbaseZbase_under_prefixÚ record_pathÚwriterr Ú hash_valuerÒÚfpr$r$r%Úwrite_installed_files¡s0      ÿ z+InstalledDistribution.write_installed_filesc Csg}tj |j¡}| d¡}| ¡D]î\}}}tj |¡sHtj ||¡}||krRq$tj |¡sr| |dddf¡q$tj  |¡r$t tj  |¡ƒ}|r®||kr®| |d||f¡q$|r$d|krÌ|  dd¡d}nd }t |d ƒ2} | |  ¡|¡} | |kr| |d || f¡W5QRXq$|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ÚÚisabsrQr¾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.        z+InstalledDistribution.check_installed_filesc CsŠi}tj |jd¡}tj |¡r†tj|ddd}| ¡ ¡}W5QRX|D]8}| dd¡\}}|dkr||  |g¡  |¡qL|||<qL|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. rr[r»©ÚencodingrírÚ namespace) r½r rQrïÚcodecsr¿rÀrÁr™r(r*)r#rjÚ 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  |¡¡W5QRX|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 rQrUrßràr*Úgetrör¿Úwrite) r#rärår÷rør)r ÚnsrÂr$r$r%Úwrite_shared_locationss  z,InstalledDistribution.write_shared_locationscCsF|tkrtd||jfƒ‚t |j¡}|dkr.set_name_and_version) r r¦r8r7rErreÚ _get_metadatar-r¥rr&)r#r rFr rEr§r$r%r&bs   zEggInfoDistribution.__init__c sÐd}dd„‰‡fdd„}d}}| d¡rötj |¡r„tj |d¡}tj |d¡}t|dd }tj |d ¡} tj |d ¡}|| ƒ}npt |¡} t|   d ¡  d ¡ƒ} t| dd}z,|   d¡} |   d¡  d¡}ˆ|   d¡ƒ}Wnt k ròd}YnXnf| d¡rPtj |¡rBtj |d ¡} || ƒ}tj |d¡}tj |d ¡}t|dd }n t d|ƒ‚|rl|  |¡|dkr²|dk r²tj |¡r²t|dƒ} |  ¡  d¡}W5QRX|s¾g}n| ¡}||_|S)NcSs¤g}| ¡}|D]Ž}| ¡}| d¡r6t d|¡q t|ƒ}|sPt d|¡q|jr`t d¡|jst| |j ¡qd  dd„|jDƒ¡}| d|j |f¡q|S) z’Create a list of dependencies from a requires.txt file. *data*: the contents of a setuptools-produced requires.txt file. ú[z.Unexpected line: quitting requirement scan: %rz#Not recognised as a requirement: %rz4extra requirements in requires.txt are not supportedz, css|]}d|VqdS)r«Nr$)rÇÚcr$r$r%Ú ‘szQEggInfoDistribution._get_metadata..parse_requires_data..rl) rÁÚstriprÞrUr˜r r„Ú constraintsr*rrQ)r³Úreqsrørùr[Zconsr$r$r%Úparse_requires_datazs( ÿ  z>EggInfoDistribution._get_metadata..parse_requires_datac sHg}z*t |dd¡}ˆ| ¡ƒ}W5QRXWntk rBYnX|S)z’Create a list of dependencies from a requires.txt file. *req_path*: the path to a setuptools-produced requires.txt file. r[r»)rör¿rÀÚIOError)Úreq_pathrrê©rr$r%Úparse_requires_path•sz>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º)rNr½r ràrQr Ú zipimportÚ zipimporterrÚget_datar²rrZadd_requirementsr¾r¿rÀrÁr¼)r#r ÚrequiresrZtl_pathZtl_datarsÚ meta_pathrErZzipfrCr³rÂr$rr%r wsX      ÿ    ÿ   z!EggInfoDistribution._get_metadatacCsd|j|j|jfS)Nz!rÃr"r$r$r%rÑs ÿzEggInfoDistribution.__repr__cCsd|j|jfSrÄrˆr"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.._sizerr[r»rózNon-existent file: %srÜN) r½r rQr¾rör¿rÚnormpathrUr˜rNràr*)r#r#r&rçrjrÂrùrsr$r$r%rÚës"     $z(EggInfoDistribution.list_installed_filesFc csštj |jd¡}tj |¡r–d}tj|ddd`}|D]T}| ¡}|dkrPd}q6|s6tj tj |j|¡¡}| |j¡r6|r„|Vq6|Vq6W5QRXdS) 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 rTr[r»róz./FN) r½r rQr¾rör¿rr'rÞ)r#ÚabsoluterçÚskiprÂrùrsr$r$r%rs   z'EggInfoDistribution.list_distinfo_filescCst|tƒo|j|jkSr:)r_rr r r$r$r%r .s  ÿzEggInfoDistribution.__eq__)N)F)r.r/r0r1r£rúr&r rrÅròrÚrr r r¢r¶r$r$r§r%rYsZ& c@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&IszDependencyGraph.__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)r+r,)r#Ú distributionr$r$r%Úadd_distributionNs z DependencyGraph.add_distributionNcCs6|j| ||f¡||j|kr2|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)r+r*r,)r#ÚxÚyÚlabelr$r$r%Úadd_edgeXs 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)rUrVrÐr(r*)r#r-r—r$r$r%Ú add_missinggszDependencyGraph.add_missingcCsd|j|jfSrÄrˆr+r$r$r%Ú _repr_distrszDependencyGraph._repr_distrcCsŠ| |¡g}|j|D]h\}}| |¡}|dk r| 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"rþz} )rr+ÚitemsrÍr*r)r#rÂZskip_disconnectedZ disconnectedr,ÚadjsrŸr1r$r$r%Úto_dot‚s(     ÿ     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|]\}}|ˆkr||f‘qSr$r$)rÇr}r[©Z to_remover$r%rÉ»sz4DependencyGraph.topological_sort..zMoving to result: %scSsg|]}d|j|jf‘qS)rlrˆ)rÇr}r$r$r%rɽs)r+r:Úlistr*rUrVr6Úkeys)r#rjÚalistÚkr~r$r=r%Útopological_sort¢s$  ÿ z DependencyGraph.topological_sortcCs2g}|j ¡D]\}}| | |¡¡qd |¡S)zRepresentation of the graphrþ)r+r:r*r5rQ)r#r8r,r;r$r$r%rÁszDependencyGraph.__repr__)N)r)T) r.r/r0r1r&r.r2r3r4r5r<rBrr$r$r$r%r*9s   r*r2c CsVt|ƒ}tƒ}i}|D]L}| |¡|jD]6}t|ƒ\}}t d|||¡| |g¡ ||f¡q*q|D]è}|j |j B|j B|j B}|D]Æ} z|  | ¡} Wn6tk rÐt d| ¡|  ¡d}|  |¡} YnX| j}d} ||kr>||D]N\}} z|  |¡} Wntk rd} YnX| 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)rr*r.rmrrUrVr(r*rr’r“r•rnrr˜r™r)rqr2r3)ÚdistsrDÚgraphrrr,rsrrerršrnÚmatchedZproviderrqr$r$r%Ú make_graphÉsN    ÿÿÿ   rFcCsv||krtd|jƒ‚t|ƒ}|g}|j|}|rh| ¡}| |¡|j|D]}||krN| |¡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)rrrFr,Úpopr*)rCr,rDÚdepÚtodor}Úsuccr$r$r%Úget_dependent_distsÿsÿ   rLcCsn||krtd|jƒ‚t|ƒ}g}|j|}|rj| ¡d}| |¡|j|D]}||krP| |¡qPq,|S)zÙRecursively 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 rGr)rrrFr+rHr*)rCr,rDršrJr}Úpredr$r$r%Úget_required_distssÿ   rNcKs4| dd¡}tf|Ž}||_||_|p(d|_t|ƒS)zO A convenience method for making a dist given just a name and version. ÚsummaryzPlaceholder for summary)rHr rrerOr)rreÚkwargsrOrŽr$r$r%Ú make_dist2s    rQ)r2)7r1Ú __future__rr¯rörRr­Úloggingr½rPr3rr@rrÚcompatrrerrrEr r r r Úutilr rrrrrrÚ__all__Ú getLoggerr.rUrÔZCOMMANDS_FILENAMErrOr rrrrrrrWrXr*rFrLrNrQr$r$r$r%Ús`  $þ ÿs7J] 6