a oe{@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZmZmZddlmZmZddlmZmZmZddlmZmZddlmZmZddlm Z m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'dd l m(Z(dd l)m*Z*m+Z+m,Z,m-Z-gdZ.Gddde/Z0GdddZ1GdddZ2Gddde2Z3Gddde4Z5Gddde5Z6GdddZ7Gddde7e8Z9Gdd d ej:Z;Gd!d"d"ZGd'd(d(Z?Gd)d*d*Z@Gd+d,d,ZAeGd-d.d.ee>ZBGd/d0d0e=ZCd1d2ZDd3d4ZEej d5d6d7ZFd8d9ZGe jHeejId:ZJe-e6e9fd5d;d<ZKd=d>ZLd?d@ZMe+eNe*eNfd5dAdBZOdCdDZPdEdFZQdS)GN) _adapters_meta _py39compat)FreezableDefaultDictPair) NullFinderinstall pypy_partial) method_cache pass_none)always_iterableunique_everseen)PackageMetadata SimplePath)suppress) import_module)MetaPathFinder)starmap)ListMappingOptionalUnion) DistributionDistributionFinderrPackageNotFoundError distribution distributions entry_pointsfilesmetadatapackages_distributionsrequiresversionc@s$eZdZdZddZeddZdS)rzThe package was not found.cCs d|jS)Nz"No package metadata was found for nameselfr(>> for item in Sectioned.read(Sectioned._sample): ... print(item) Pair(name='sec1', value='# comments ignored') Pair(name='sec1', value='a = 1') Pair(name='sec1', value='b = 2') Pair(name='sec2', value='a = 2') >>> res = Sectioned.section_pairs(Sectioned._sample) >>> item = next(res) >>> item.name 'sec1' >>> item.value Pair(name='a', value='1') >>> item = next(res) >>> item.value Pair(name='b', value='2') >>> item = next(res) >>> item.name 'sec2' >>> item.value Pair(name='a', value='2') >>> list(res) [] zm [sec1] # comments ignored a = 1 b = 2 [sec2] a = 2 cCsdd|j||jdDS)Ncss,|]$}|jdur|jt|jdVqdS)N)value)r%_replacerparser4).0sectionr(r(r) js z*Sectioned.section_pairs..)filter_)readvalid)clstextr(r(r) section_pairshszSectioned.section_pairsNccsXt|ttj|}d}|D]4}|do4|d}|rF|d}qt||VqdS)N[]z[])filtermapstrstrip splitlines startswithendswithr)r>r:linesr%r4Z section_matchr(r(r)r;ps zSectioned.readcCs|o|d S)N#)rG)liner(r(r)r<{szSectioned.valid)N) r.r/r0r1textwrapdedentlstripZ_sample classmethodr? staticmethodr;r<r(r(r(r)r3?s   r3c@s0eZdZdZejejdee ddZ ddZ dS)DeprecatedTuplea Provide subscript item access for backward compatibility. >>> recwarn = getfixture('recwarn') >>> ep = EntryPoint(name='name', value='value', group='group') >>> ep[:] ('name', 'value', 'group') >>> ep[0] 'name' >>> len(recwarn) 1 zAEntryPoint tuple interface is deprecated. Access members by name. stacklevelcCs|||Sr+)_warn_key)r'itemr(r(r) __getitem__szDeprecatedTuple.__getitem__N) r.r/r0r1 functoolspartialwarningswarnDeprecationWarningr rUrXr(r(r(r)rQs rQc@seZdZUdZedZeed<eed<eed<dZ e ded<d d Z d d Z e d dZe ddZe ddZddZddZddZddZddZddZdd Zd!d"Zd#d$ZdS)% EntryPointaAn entry point as defined by Python packaging conventions. See `the packaging docs on entry points `_ for more information. >>> ep = EntryPoint( ... name=None, group=None, value='package.module:attr [extra1, extra2]') >>> ep.module 'package.module' >>> ep.attr 'attr' >>> ep.extras ['extra1', 'extra2'] zH(?P[\w.]+)\s*(:\s*(?P[\w.]+)\s*)?((?P\[.*\])\s*)?$r%r4groupNrdistcCst|j|||ddS)Nr%r4r_varsupdate)r'r%r4r_r(r(r)__init__szEntryPoint.__init__cCsD|j|j}t|d}td|dp,dd}tt ||S)zLoad the entry point from its definition. If only a module is indicated by the value, return that module. Otherwise, return the named object. moduleNattr.) patternmatchr4rr_rBsplitrYreducegetattr)r'rkrfattrsr(r(r)loadszEntryPoint.loadcCs|j|j}|dS)Nrfrjrkr4r_r'rkr(r(r)rfszEntryPoint.modulecCs|j|j}|dS)Nrgrqrrr(r(r)rgszEntryPoint.attrcCs$|j|j}td|dp dS)Nz\w+extrasrh)rjrkr4refindallr_rrr(r(r)rsszEntryPoint.extrascCst|j|d|S)Nr`rb)r'r`r(r(r)_forszEntryPoint._forcCsd}t|tt|j|fS)zP Supply iter so one may construct dicts of EntryPoints by name. zJConstruction of dict of EntryPoints is deprecated in favor of EntryPoints.)r[r\r]iterr%)r'msgr(r(r)__iter__s zEntryPoint.__iter__c s(fdd|D}tttj||S)a$ EntryPoint matches the given parameters. >>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]') >>> ep.matches(group='foo') True >>> ep.matches(name='bar', value='bing:bong [extra1, extra2]') True >>> ep.matches(group='foo', name='other') False >>> ep.matches() True >>> ep.matches(extras=['extra1', 'extra2']) True >>> ep.matches(module='bing') True >>> ep.matches(attr='bong') True c3s|]}t|VqdSr+rn)r7Zparamr&r(r)r9z%EntryPoint.matches..)allrCoperatoreqvalues)r'paramsror(r&r)matchesszEntryPoint.matchescCs|j|j|jfSr+rar&r(r(r)rVszEntryPoint._keycCs||kSr+rVr'otherr(r(r)__lt__ szEntryPoint.__lt__cCs||kSr+rrr(r(r)__eq__szEntryPoint.__eq__cCs tddS)Nz!EntryPoint objects are immutable.)AttributeError)r'r%r4r(r(r) __setattr__szEntryPoint.__setattr__cCsd|jd|jd|jdS)NzEntryPoint(name=z, value=z, group=)rar&r(r(r)__repr__szEntryPoint.__repr__cCs t|Sr+)hashrVr&r(r(r)__hash__szEntryPoint.__hash__)r.r/r0r1rtcompilerjrD__annotations__r`rrerpr2rfrgrsrwrzrrVrrrrrr(r(r(r)r^s2      r^csheZdZdZdZejejde e ddZ e dfdd Z eee d d d Zd d ZZS)DeprecatedLista> Allow an otherwise immutable object to implement mutability for compatibility. >>> recwarn = getfixture('recwarn') >>> dl = DeprecatedList(range(3)) >>> dl[0] = 1 >>> dl.append(3) >>> del dl[3] >>> dl.reverse() >>> dl.sort() >>> dl.extend([4]) >>> dl.pop(-1) 4 >>> dl.remove(1) >>> dl += [5] >>> dl + [6] [1, 2, 5, 6] >>> dl + (6,) [1, 2, 5, 6] >>> dl.insert(0, 0) >>> dl [0, 1, 2, 5] >>> dl == [0, 1, 2, 5] True >>> dl == (0, 1, 2, 5) True >>> len(recwarn) 1 r(zAEntryPoints list interface is deprecated. Cast to list if needed.rRrS method_namecsfdd}|fS)Ncs|tt|i|Sr+)rUrnsuper)r'r,kwargs) __class__rr(r)wrappedHsz7DeprecatedList._wrap_deprecated_method..wrappedr()rrrrr)_wrap_deprecated_methodGsz&DeprecatedList._wrap_deprecated_methodzM__setitem__ __delitem__ append reverse extend pop remove __iadd__ insert sortcCs,t|ts|t|}|t||Sr+) isinstancetuplerUrrr(r(r)__add__Vs zDeprecatedList.__add__cCs(t|ts|t|}t||Sr+)rrrUrrr(r(r)r\s zDeprecatedList.__eq__)r.r/r0r1 __slots__rYrZr[r\r]r rUrDrlocalsrdrCrlrr __classcell__r(r(rr)rs"rcs\eZdZdZdZfddZddZeddZed d Z e d d Z e d dZ ZS) EntryPointszC An immutable collection of selectable EntryPoint objects. r(cs\t|tr&tjdtddt|Sztt|j |dWSt yVt |Yn0dS)z; Get the EntryPoint in self matching name. zGAccessing entry points by index is deprecated. Cast to tuple if needed.rRrSr$N) rintr[r\r]rrXnextrxselect StopIterationKeyErrorr-rr(r)rXks   zEntryPoints.__getitem__c s$fdd|D}tdd|DS)zv Select entry points from self that match the given parameters (typically group and/or name). c3s |]}tj|fiVqdSr+)rZ ep_matchesr7eprr(r)r9r|z%EntryPoints.select..css|]\}}|r|VqdSr+r()r7r predicater(r(r)r9r|r)r'rZ candidatesr(rr)r|szEntryPoints.selectcCsdd|DS)zB Return the set of all names of all entry points. cSsh|] }|jqSr(r$rr(r(r) r|z$EntryPoints.names..r(r&r(r(r)namesszEntryPoints.namescCsdd|DS)z Return the set of all groups of all entry points. For coverage while SelectableGroups is present. >>> EntryPoints().groups set() cSsh|] }|jqSr()r_rr(r(r)rr|z%EntryPoints.groups..r(r&r(r(r)groupss zEntryPoints.groupscs|fdd||DS)Nc3s|]}|VqdSr+)rwrrvr(r)r9r|z-EntryPoints._from_text_for..) _from_text)r=r>r`r(rvr)_from_text_forszEntryPoints._from_text_forcCsddt|pdDS)Ncss&|]}t|jj|jj|jdVqdS)raN)r^r4r%)r7rWr(r(r)r9sz)EntryPoints._from_text..rh)r3r?)r>r(r(r)rs zEntryPoints._from_text)r.r/r0r1rrXrr2rrrOrrPrrr(r(rr)rds    rcsveZdZdZejejdee ddZ fddZ dfdd Z fd d Z fd d ZfddZfddZZS) Deprecateda Compatibility add-in for mapping to indicate that mapping behavior is deprecated. >>> recwarn = getfixture('recwarn') >>> class DeprecatedDict(Deprecated, dict): pass >>> dd = DeprecatedDict(foo='bar') >>> dd.get('baz', None) >>> dd['foo'] 'bar' >>> list(dd) ['foo'] >>> list(dd.keys()) ['foo'] >>> 'foo' in dd True >>> list(dd.values()) ['bar'] >>> len(recwarn) 1 z:SelectableGroups dict interface is deprecated. Use select.rRrScs|t|Sr+)rUrrXr-rr(r)rXszDeprecated.__getitem__Ncs|t||Sr+)rUrget)r'r%defaultrr(r)rszDeprecated.getcs|tSr+)rUrrzr&rr(r)rzszDeprecated.__iter__cs|tj|Sr+)rUr __contains__)r'r,rr(r)rszDeprecated.__contains__cs|tSr+)rUrkeysr&rr(r)rszDeprecated.keyscs|tSr+)rUrrr&rr(r)rszDeprecated.values)N)r.r/r0r1rYrZr[r\r]r rUrXrrzrrrrr(r(rr)rs    rcsPeZdZdZeddZefddZeddZedd Z d d Z Z S) SelectableGroupszs A backward- and forward-compatible result from entry_points that fully implements the dict interface. cCs4td}t||d}t||}|dd|DS)Nr_keycss|]\}}|t|fVqdSr+r)r7r_epsr(r(r)r9r|z(SelectableGroups.load..)r~ attrgettersorted itertoolsgroupby)r=rZby_groupZorderedZgroupedr(r(r)rps   zSelectableGroups.loadcstt|}ttj|S)zH Reconstruct a list of all entrypoints from the groups. )rrrrrchain from_iterable)r'rrr(r)_allszSelectableGroups._allcCs|jjSr+)rrr&r(r(r)rszSelectableGroups.groupscCs|jjS)zR for coverage: >>> SelectableGroups().names set() )rrr&r(r(r)rszSelectableGroups.namescKs|s|S|jjfi|Sr+)rr)r'rr(r(r)rszSelectableGroups.select) r.r/r0r1rOrpr2rrrrrr(r(rr)rs   rc@s*eZdZdZd ddZddZddZd S) PackagePathz"A reference to a path in a packageutf-8cCs<|j|d}|WdS1s.0YdS)Nencodinglocateopenr;)r'rstreamr(r(r) read_textszPackagePath.read_textcCs:|d}|WdS1s,0YdS)Nrbr)r'rr(r(r) read_binaryszPackagePath.read_binarycCs |j|S)z'Return a path-like object for this path)r` locate_filer&r(r(r)r szPackagePath.locateN)r)r.r/r0r1rrrr(r(r(r)rs rc@seZdZddZddZdS)FileHashcCs|d\|_}|_dS)N=) partitionmoder4)r'spec_r(r(r)reszFileHash.__init__cCsd|jd|jdS)Nz)rr4r&r(r(r)rszFileHash.__repr__N)r.r/r0rerr(r(r(r)rsrc@seZdZdZejddZejddZee dddZ ed d Z e d d Z e d dZeejdddZeddZeddZeddZeddZeddZddZddZed d!Zd"d#Zd$d%Zed&d'Ze d(d)Zd*S)+rzA Python distribution package.cCsdS)zAttempt to load metadata file given by the name. :param filename: The name of the file in the distribution info. :return: The text if found, otherwise None. Nr(r'filenamer(r(r)rszDistribution.read_textcCsdS)z[ Given a path to a file in this distribution, return a path to it. Nr(r'pathr(r(r)r$szDistribution.locate_filer$cCs>|s tdzt|j|dWSty8t|Yn0dS)aReturn the Distribution for the given package name. :param name: The name of the distribution package to search for. :return: The Distribution instance (or subclass thereof) for the named package, if found. :raises PackageNotFoundError: When the named package's distribution metadata cannot be found. :raises ValueError: When an invalid value is supplied for name. z A distribution name is required.r$N) ValueErrorrdiscoverrr)r=r%r(r(r) from_name+s  zDistribution.from_namec sN|ddr|rtdp.tjfi|tjfdd|DS)aReturn an iterable of Distribution objects for all packages. Pass a ``context`` or pass keyword arguments for constructing a context. :context: A ``DistributionFinder.Context`` object. :return: Iterable of Distribution objects for all packages. contextNz cannot accept context and kwargsc3s|]}|VqdSr+r()r7Zresolverrr(r)r9Ksz(Distribution.discover..)poprrContextrrr_discover_resolvers)r=rr(rr)r=s zDistribution.discovercCstt|S)zReturn a Distribution for the indicated metadata path :param path: a string or path-like object :return: a concrete Distribution instance for the path )PathDistributionpathlibPathrr(r(r)atOszDistribution.atcCsddtjD}td|S)z#Search the meta_path for resolvers.css|]}t|ddVqdS)find_distributionsNr{)r7finderr(r(r)r9[sz3Distribution._discover_resolvers..N)sys meta_pathrB)Zdeclaredr(r(r)rXsz Distribution._discover_resolversreturncCs.|dp|dp|d}tt|S)zReturn the parsed metadata for this Distribution. The returned object will have keys that name the various bits of metadata. See PEP 566 for details. ZMETADATAzPKG-INFOrh)rrZMessageemailZmessage_from_stringr'r>r(r(r)r `s  zDistribution.metadatacCs |jdS)z8Return the 'Name' metadata for the distribution package.Namer r&r(r(r)r%qszDistribution.namecCs t|jS)z(Return a normalized version of the name.)Prepared normalizer%r&r(r(r)_normalized_namevszDistribution._normalized_namecCs |jdS)z;Return the 'Version' metadata for the distribution package.ZVersionrr&r(r(r)r#{szDistribution.versioncCst|d|S)Nzentry_points.txt)rrrr&r(r(r)rszDistribution.entry_pointscs2dfdd tfdd}|p.S)aBFiles in this distribution. :return: List of PackagePath for this distribution or None Result is `None` if the metadata file that enumerates files (i.e. RECORD for dist-info or SOURCES.txt for egg-info) is missing. Result may be empty if the metadata exists but is empty. Ncs6t|}|rt|nd|_|r&t|nd|_|_|Sr+)rrrrsizer`)r%rZsize_strresultr&r(r) make_files z%Distribution.files..make_filecsttt|Sr+)listrcsvreader)rI)rr(r) make_filessz&Distribution.files..make_files)NN)r _read_files_distinfo_read_files_egginfo)r'rr()rr'r)rs zDistribution.filescCs|d}|o|S)z* Read the lines of RECORD ZRECORD)rrFrr(r(r)rs z!Distribution._read_files_distinfocCs|d}|otdj|S)z` SOURCES.txt might contain literal commas, so wrap each line in quotes. z SOURCES.txtz"{}")rrCformatrFrr(r(r)rs z Distribution._read_files_egginfocCs|p|}|ot|S)z6Generated requirements specified for this Distribution)_read_dist_info_reqs_read_egg_info_reqsr)r'Zreqsr(r(r)r"szDistribution.requirescCs |jdS)Nz Requires-Dist)r Zget_allr&r(r(r)rsz!Distribution._read_dist_info_reqscCs|d}t|j|S)Nz requires.txt)rr _deps_from_requires_text)r'sourcer(r(r)rs z Distribution._read_egg_info_reqscCs|t|Sr+)%_convert_egg_info_reqs_to_simple_reqsr3r;)r=rr(r(r)rsz%Distribution._deps_from_requires_textc#sJddfdd}dd}|D]$}||j}|j|||jVq dS)a Historically, setuptools would solicit and store 'extra' requirements, including those with environment markers, in separate sections. More modern tools expect each dependency to be defined separately, with any relevant extras and environment markers attached directly to that requirement. This method converts the former to the latter. See _test_deps_from_requires_text for an example. cSs|od|dS)Nz extra == ""r(r$r(r(r)make_conditionszJDistribution._convert_egg_info_reqs_to_simple_reqs..make_conditioncsX|pd}|d\}}}|r,|r,d|d}ttd||g}|rTdd|SdS)Nrh:(rz; z and )rrrBjoin)r8ZextrasepZmarkersZ conditionsrr(r) quoted_markers  zIDistribution._convert_egg_info_reqs_to_simple_reqs..quoted_markercSs dd|vS)z PEP 508 requires a space between the url_spec and the quoted_marker. Ref python/importlib_metadata#357.  @r()Zreqr(r(r) url_req_spaceszIDistribution._convert_egg_info_reqs_to_simple_reqs..url_req_spaceN)r4r%)Zsectionsrr r8spacer(rr)rs   z2Distribution._convert_egg_info_reqs_to_simple_reqsN)r.r/r0r1abcabstractmethodrrrOrDrrrPrrr2rrr r%rr#rrrrr"rrrrr(r(r(r)rsF            rc@s2eZdZdZGdddZejefddZdS)rzJ A MetaPathFinder capable of discovering installed distributions. c@s(eZdZdZdZddZeddZdS)zDistributionFinder.Contextaw Keyword arguments presented by the caller to ``distributions()`` or ``Distribution.discover()`` to narrow the scope of a search for distributions in all DistributionFinders. Each DistributionFinder may expect any parameters and should attempt to honor the canonical parameters defined below when appropriate. NcKst||dSr+rb)r'rr(r(r)resz#DistributionFinder.Context.__init__cCst|dtjS)z The sequence of directory path that a distribution finder should search. Typically refers to Python installed package paths such as "site-packages" directories and defaults to ``sys.path``. r)rcrrrr&r(r(r)rs zDistributionFinder.Context.path)r.r/r0r1r%rer2rr(r(r(r)rs  rcCsdS)z Find distributions. Return an iterable of all Distribution instances capable of loading the metadata for packages matching the ``context``, a DistributionFinder.Context instance. Nr()r'rr(r(r)rsz%DistributionFinder.find_distributionsN)r.r/r0r1rr r rr(r(r(r)rs rcsheZdZdZefddZddZddZdd Z d d Z d d Z e ddZ eddZZS)FastPathzs Micro-optimized class for searching a path for children. >>> FastPath('').children() ['...'] cs t|Sr+)r__new__)r=rootrr(r)rszFastPath.__new__cCs ||_dSr+)r)r'rr(r(r)reszFastPath.__init__cCst|j|Sr+)rrr)r'childr(r(r)joinpath!szFastPath.joinpathcCsltt t|jpdWdS1s.0Ytt|WdS1s^0YgS)Nri)r Exceptionoslistdirr zip_childrenr&r(r(r)children$s  . &zFastPath.childrencCs2t|j}|j}|j|_tdd|DS)Ncss |]}|tjddVqdS)rrN)rl posixpathr)r7rr(r(r)r90r|z(FastPath.zip_children..)zipprrZnamelistrdictfromkeys)r'Zzip_pathrr(r(r)r+s  zFastPath.zip_childrencCs||j|Sr+)lookupmtimesearchr-r(r(r)r2szFastPath.searchcCsDttt|jjWdS1s,0Y|jdSr+)rOSErrorrstatrst_mtimer cache_clearr&r(r(r)r5s ,zFastPath.mtimecCst|Sr+)Lookup)r'rr(r(r)r;szFastPath.lookup)r.r/r0r1rY lru_cacherrerrrrr2rr rrr(r(rr)r s r c@s"eZdZedddZddZdS)r"rc Cstj|j}|d}tt|_tt|_ | D]}|}|dr| dd dd}t |}|j|||q8|r8|dkr8| dd dd}t |}|j |||q8|j|j dS)Nz.eggz .dist-infoz .egg-inforir-zegg-info)rrbasenamerlowerrHrrinfoseggsr rpartitionrrrappendrlegacy_normalizeZfreeze) r'rbaseZ base_is_eggrZlowr% normalizedlegacy_normalizedr(r(r)reAs          zLookup.__init__cCsP|r|j|jntj|j}|r2|j|jntj|j}t||Sr+)r(r.rrrrr)r/)r'preparedr(r)r(r(r)rVsz Lookup.searchN)r.r/r0r rerr(r(r(r)r"@sr"c@s@eZdZdZdZdZddZeddZeddZ d d Z dS) rzE A prepared search for metadata on a possibly-named package. NcCs.||_|durdS|||_|||_dSr+)r%rr.r,r/r-r(r(r)rels  zPrepared.__init__cCstdd|ddS)zC PEP 503 normalization plus dashes as underscores. z[-_.]+r%r)rtsubr'replacer$r(r(r)rsszPrepared.normalizecCs|ddS)z| Normalize the package name as found in the convention in older packaging tools versions and specs. r%r)r'r2r$r(r(r)r,zszPrepared.legacy_normalizecCs t|jSr+)boolr%r&r(r(r)__bool__szPrepared.__bool__) r.r/r0r1r.r/rerPrr,r4r(r(r(r)rds  rc@s4eZdZdZefddZeddZddZ dS) MetadataPathFinderzA degenerate finder for distribution packages on the file system. This finder supplies only a find_distributions() method for versions of Python that do not have a PathFinder find_distributions(). cCs||j|j}tt|S)a  Find distributions. Return an iterable of all Distribution instances capable of loading the metadata for packages matching ``context.name`` (or all names if ``None`` indicated) along the paths in the list of directories ``context.path``. ) _search_pathsr%rrCr)r'rfoundr(r(r)rs z%MetadataPathFinder.find_distributionscs(t|tjfddtt|DS)z1Find metadata directories in paths heuristically.c3s|]}|VqdSr+)r)r7rr0r(r)r9sz3MetadataPathFinder._search_paths..)rrrrrCr )r=r%pathsr(r8r)r6sz MetadataPathFinder._search_pathscCstjdSr+)r rr!)r=r(r(r)invalidate_cachessz$MetadataPathFinder.invalidate_cachesN) r.r/r0r1rrrrOr6r:r(r(r(r)r5s   r5csTeZdZedddZddZejje_ddZe fdd Z e d d Z Z S) rrcCs ||_dS)zfConstruct a distribution. :param path: SimplePath indicating the metadata directory. N)_pathrr(r(r)reszPathDistribution.__init__cCsHtttttt$|j|jddWdS1s:0YdS)Nrr) rFileNotFoundErrorIsADirectoryErrorrNotADirectoryErrorPermissionErrorr;rrrr(r(r)rszPathDistribution.read_textcCs |jj|Sr+)r;parentrr(r(r)rszPathDistribution.locate_filecs.tjt|j}ttj||p,t j S)zz Performance optimization: where possible, resolve the normalized name from the file system path. ) rrr&rDr;r rr_name_from_stemrr)r'stemrr(r)rsz!PathDistribution._normalized_namecCs0tj|\}}|dvrdS|d\}}}|S)a7 >>> PathDistribution._name_from_stem('foo-3.0.egg-info') 'foo' >>> PathDistribution._name_from_stem('CherryPy-3.0.dist-info') 'CherryPy' >>> PathDistribution._name_from_stem('face.egg-info') 'face' >>> PathDistribution._name_from_stem('foo.bar') r$Nr%)rrsplitextr)rBrextr%rrestr(r(r)rAs z PathDistribution._name_from_stem)r.r/r0rrerrr1rr2rrPrArr(r(rr)rs  rcCs t|S)zGet the ``Distribution`` instance for the named package. :param distribution_name: The name of the distribution package as a string. :return: A ``Distribution`` instance (or subclass thereof). )rrZdistribution_namer(r(r)rsrcKstjfi|S)z|Get all ``Distribution`` instances in the current environment. :return: An iterable of ``Distribution`` instances. )rr)rr(r(r)rsrrcCs t|jS)zGet the metadata for the named package. :param distribution_name: The name of the distribution package to query. :return: A PackageMetadata containing the parsed metadata. )rrr rFr(r(r)r sr cCs t|jS)zGet the version string for the named package. :param distribution_name: The name of the distribution package to query. :return: The version string for the package as defined in the package's "Version" metadata key. )rr#rFr(r(r)r#sr#rcKs2tjddttD}t|jfi|S)aReturn EntryPoint objects for all installed packages. Pass selection parameters (group or name) to filter the result to entry points matching those properties (see EntryPoints.select()). For compatibility, returns ``SelectableGroups`` object unless selection parameters are supplied. In the future, this function will return ``EntryPoints`` instead of ``SelectableGroups`` even when no selection parameters are supplied. For maximum future compatibility, pass selection parameters or invoke ``.select`` with parameters on the result. :return: EntryPoints or SelectableGroups for all installed packages. css|] }|jVqdSr+)r)r7r`r(r(r)r9szentry_points..)rrr_uniquerrrpr)rrr(r(r)rs rcCs t|jS)zReturn a list of files for the named package. :param distribution_name: The name of the distribution package to query. :return: List of files composing the distribution. )rrrFr(r(r)rsrcCs t|jS)z Return a list of requirements for the named package. :return: An iterator of requirements, suitable for packaging.requirement.Requirement. )rr"rFr(r(r)r"(sr"cCsHtt}tD].}t|p"t|D]}|||jdq$qt|S)z Return a mapping of top-level packages to their distributions. >>> import collections.abc >>> pkgs = packages_distributions() >>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values()) True r) collections defaultdictrr_top_level_declared_top_level_inferredr+r r)Z pkg_to_distr`pkgr(r(r)r!2s  r!cCs|dp dS)Nz top_level.txtrh)rrlrvr(r(r)rJCsrJcCsddt|jDS)NcSs:h|]2}|jdkrt|jdkr*|jdn |djqS)z.pyrrrh)suffixlenparts with_suffixr%)r7fr(r(r)rHs z&_top_level_inferred..)r rrvr(r(r)rKGsrK)Rrrtr rrrrrr~rLr[rYrrrHrhrrr _collectionsrrZ_compatrr r _functoolsr r _itertoolsr rrr contextlibr importlibr importlib.abcrrtypingrrrr__all__ModuleNotFoundErrorrr3rQr^rrrrrr PurePosixPathrrrrr r"rr5rrrr r#rZZnormalized_namerGrrr"rDr!rJrKr(r(r(r)sx     AF>7(I0/$"5