a xcz@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZmZddlmZmZddlmZmZmZddlmZmZddlmZmZddlmZm 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.Z/GdddZ0GdddZ1Gddde1Z2Gddde3Z4Gddde4Z5GdddZ6Gddde6e7Z8Gdd d ej9Z:Gd!d"d"Z;Gd#d$d$ZGd)d*d*Z?Gd+d,d,Z@eGd-d.d.ee=ZAGd/d0d0e<ZBd1d2ZCd3d4ZDejd5d6d7ZEd8d9ZFe jGeeHd:d;ZIe,e5e8fd5dd?ZKd@dAZLe*eMe)eMfd5dBdCZNdDdEZOdFdGZPdS)HN) _adapters_meta)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'?/usr/lib/python3.9/site-packages/importlib_metadata/__init__.py__str__6szPackageNotFoundError.__str__cCs |j\}|SN)argsr&r$r'r'r(r$9szPackageNotFoundError.nameN)__name__ __module__ __qualname____doc__r)propertyr$r'r'r'r(r3src@sDeZdZdZedZeddZ e d ddZ e dd Z dS) Sectioneda A simple entry point config parser for performance >>> 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$_replacerparser3).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=r9linesr$r3Z section_matchr'r'r(r:ps zSectioned.readcCs|o|d S)N#)rF)liner'r'r(r;{szSectioned.valid)N) r-r.r/r0textwrapdedentlstripZ_sample classmethodr> staticmethodr:r;r'r'r'r(r2?s   r2c@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.r/r0 functoolspartialwarningswarnDeprecationWarningr rTrWr'r'r'r(rPs rPc@seZdZUdZedZdZede d<ddZ dd Z e d d Z e d d Ze ddZddZddZddZddZddZddZddZddZd 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*)?$NrdistcCst|j|||ddS)Nr$r3groupvarsupdate)r&r$r3r`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.) patternmatchr3rr`rAsplitrXreducegetattr)r&rjreattrsr'r'r(loadszEntryPoint.loadcCs|j|j}|dS)Nrerirjr3r`r&rjr'r'r(reszEntryPoint.modulecCs|j|j}|dS)Nrfrprqr'r'r(rfszEntryPoint.attrcCs$|j|j}td|dp dS)Nz\w+extrasrg)rirjr3refindallr`rqr'r'r(rrszEntryPoint.extrascCst|j|d|S)Nr^ra)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.)rZr[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*rm)r6Zparamr%r'r(r8z%EntryPoint.matches..)allrBoperatoreqvalues)r&paramsrnr'r%r(matchesszEntryPoint.matchescCs|j|j|jfSr*r_r%r'r'r(rUszEntryPoint._keycCs||kSr*rUr&otherr'r'r(__lt__szEntryPoint.__lt__cCs||kSr*rrr'r'r(__eq__ szEntryPoint.__eq__cCs tddS)Nz!EntryPoint objects are immutable.)AttributeError)r&r$r3r'r'r( __setattr__ szEntryPoint.__setattr__cCsd|jd|jd|jdS)NzEntryPoint(name=z, value=z, group=)r_r%r'r'r(__repr__szEntryPoint.__repr__cCs t|Sr*)hashrUr%r'r'r(__hash__szEntryPoint.__hash__)r-r.r/r0rscompilerir^r__annotations__rdror1rerfrrrvryrrUrrrrrr'r'r'r(r]s,      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.rQrR method_namecsfdd}|fS)Ncs|tt|i|Sr*)rTrmsuper)r&r+kwargs) __class__rr'r(wrappedDsz7DeprecatedList._wrap_deprecated_method..wrappedr')rrrrr(_wrap_deprecated_methodCsz&DeprecatedList._wrap_deprecated_methodzM__setitem__ __delitem__ append reverse extend pop remove __iadd__ insert sortcCs,t|ts|t|}|t||Sr*) isinstancetuplerTrrr'r'r(__add__Rs zDeprecatedList.__add__cCs(t|ts|t|}t||Sr*)rrrTrrr'r'r(rXs zDeprecatedList.__eq__)r-r.r/r0 __slots__rXrYrZr[r\r rTrCrlocalsrcrBrkrr __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.rQrRr#N) rintrZr[r\rrWnextrwselect StopIterationKeyErrorr,rr'r(rWgs   zEntryPoints.__getitem__c stfdd|DS)zv Select entry points from self that match the given parameters (typically group and/or name). c3s"|]}|jfir|VqdSr*)rr6Zeprr'r(r8}r{z%EntryPoints.select..rr&rr'rr(rxszEntryPoints.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*)rvrrur'r(r8r{z-EntryPoints._from_text_for..) _from_text)r<r=r^r'rur(_from_text_forszEntryPoints._from_text_forcCsddt|pdDS)Ncss&|]}t|jj|jj|jdVqdS)r_N)r]r3r$)r6rVr'r'r(r8sz)EntryPoints._from_text..rg)r2r>)r=r'r'r(rs zEntryPoints._from_text)r-r.r/r0rrWrr1rrrNrrOrrr'r'rr(r`s    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.rQrRcs|t|Sr*)rTrrWr,rr'r(rWszDeprecated.__getitem__Ncs|t||Sr*)rTrget)r&r$defaultrr'r(rszDeprecated.getcs|tSr*)rTrryr%rr'r(ryszDeprecated.__iter__cs|tj|Sr*)rTr __contains__)r&r+rr'r(rszDeprecated.__contains__cs|tSr*)rTrkeysr%rr'r(rszDeprecated.keyscs|tSr*)rTrrr%rr'r(rszDeprecated.values)N)r-r.r/r0rXrYrZr[r\r rTrWrryrrrrr'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)r6r`epsr'r'r(r8r{z(SelectableGroups.load..)r} attrgettersorted itertoolsgroupby)r<rZby_groupZorderedZgroupedr'r'r(ros   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*)rrrr'r'r(rszSelectableGroups.select) r-r.r/r0rNror1rrrrrr'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(rszPackagePath.locateN)r)r-r.r/r0rrrr'r'r'r(rs rc@seZdZddZddZdS)FileHashcCs|d\|_}|_dS)N=) partitionmoder3)r&spec_r'r'r(rd szFileHash.__init__cCsd|jd|jdS)Nz)rr3r%r'r'r(rszFileHash.__repr__N)r-r.r/rdrr'r'r'r(r src@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(rszDistribution.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')r6Zresolverrr'r(r8Fsz(Distribution.discover..)poprrContextrrr_discover_resolvers)r<rr'rr(r8s 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(atJszDistribution.atcCsddtjD}td|S)z#Search the meta_path for resolvers.css|]}t|ddVqdS)find_distributionsNrz)r6finderr'r'r(r8Vsz3Distribution._discover_resolvers..N)sys meta_pathrA)Zdeclaredr'r'r(rSsz 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-INFOrg)rrZMessageemailZmessage_from_stringr&r=r'r'r(r[s  zDistribution.metadatacCs |jdS)z8Return the 'Name' metadata for the distribution package.Namerr%r'r'r(r$lszDistribution.namecCs t|jS)z(Return a normalized version of the name.)Prepared normalizer$r%r'r'r(_normalized_nameqszDistribution._normalized_namecCs |jdS)z;Return the 'Version' metadata for the distribution package.ZVersionrr%r'r'r(r"vszDistribution.versioncCst|d|S)Nzentry_points.txt)rrrr%r'r'r(r{szDistribution.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)rH)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)rrErr'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"{}")rrBformatrErr'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)rZget_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_reqsr2r:)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)Nrg:(rz; z and )rrrAjoin)r7ZextrasepZmarkersZ 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)r3r$)Zsectionsrrr7spacer'rr(rs   z2Distribution._convert_egg_info_reqs_to_simple_reqsN)r-r.r/r0abcabstractmethodrrrNrCrrrOrrr1rrrr$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*ra)r&rr'r'r(rdsz#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)rbrrrr%r'r'r(rs zDistributionFinder.Context.path)r-r.r/r0r$rdr1rr'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.r/r0rr 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(r szFastPath.__new__cCs ||_dSr*)r )r&r r'r'r(rdszFastPath.__init__cCst|j|Sr*)rrr )r&childr'r'r(joinpathszFastPath.joinpathcCsltt t|jpdWdS1s.0Ytt|WdS1s^0YgS)Nrh)r Exceptionoslistdirr  zip_childrenr%r'r'r(childrens  . &zFastPath.childrencCs2t|j}|j}|j|_tdd|DS)Ncss |]}|tjddVqdS)rrN)rk posixpathr)r6rr'r'r(r8+r{z(FastPath.zip_children..)zipprr Znamelistrdictfromkeys)r&Zzip_pathrr'r'r(r&s  zFastPath.zip_childrencCs||j|Sr*)lookupmtimesearchr,r'r'r(r-szFastPath.searchcCsDttt|jjWdS1s,0Y|jdSr*)rOSErrorrstatr st_mtimer cache_clearr%r'r'r(r0s ,zFastPath.mtimecCst|Sr*)Lookup)r&rr'r'r(r6szFastPath.lookup)r-r.r/r0rX lru_cacher rdrrrrr1rr 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-inforhr-zegg-info)rrbasenamer lowerrGrrinfoseggsr rpartitionrrrappendrlegacy_normalizeZfreeze) r&rbaseZ base_is_eggrZlowr$ normalizedlegacy_normalizedr'r'r(rd<s          zLookup.__init__cCsP|r|j|jntj|j}|r2|j|jntj|j}t||Sr*)r&r,rrrrr'r-)r&preparedr&r'r'r'r(rQsz Lookup.searchN)r-r.r/r rdrr'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(rdgs  zPrepared.__init__cCstdd|ddS)zC PEP 503 normalization plus dashes as underscores. z[-_.]+r#r)rssubr%replacer#r'r'r(rnszPrepared.normalizecCs|ddS)z| Normalize the package name as found in the convention in older packaging tools versions and specs. r#r)r%r0r#r'r'r(r*uszPrepared.legacy_normalizecCs t|jSr*)boolr$r%r'r'r(__bool__}szPrepared.__bool__) r-r.r/r0r,r-rdrOrr*r2r'r'r'r(r_s  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$rrBr)r&rfoundr'r'r(rs z%MetadataPathFinder.find_distributionscs(t|tjfddtt|DS)z1Find metadata directories in paths heuristically.c3s|]}|VqdSr*)r)r6rr.r'r(r8sz3MetadataPathFinder._search_paths..)rrrrrBr )r<r$pathsr'r6r(r4sz MetadataPathFinder._search_pathscCstjdSr*)r r r)r<r'r'r(invalidate_cachessz$MetadataPathFinder.invalidate_cachesN) r-r.r/r0rrrrNr4r8r'r'r'r(r3s   r3csTeZdZedddZddZejje_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(rdszPathDistribution.__init__cCsHtttttt$|j|jddWdS1s:0YdS)Nrr) rFileNotFoundErrorIsADirectoryErrorrNotADirectoryErrorPermissionErrorr9rrrr'r'r(rszPathDistribution.read_textcCs |jj|Sr*)r9parentrr'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$rCr9r 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)r@rextr$rrestr'r'r(r?s z PathDistribution._name_from_stem)r-r.r/rrdrrr0rr1rrOr?rr'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. )rrrrDr'r'r(rsrcCs 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"rDr'r'r(r"sr"rrcKs2tjddttD}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)r6r^r'r'r(r8szentry_points..)rrr_uniquerrror)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. )rrrDr'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!rDr'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)rr)Z pkg_to_distr^pkgr'r'r(r -s  r cCs|dp dS)Nz top_level.txtrg)rrkrur'r'r(rH>srHcCsddt|jDS)NcSs:h|]2}|jdkrt|jdkr*|jdn |djqS)z.pyrrrg)suffixlenparts with_suffixr$)r6fr'r'r(rCs z&_top_level_inferred..)r rrur'r'r(rIBsrI)Qrrsr rrrrrr}rKrZrXrrrFrgrr _collectionsrrZ_compatrrr _functoolsr r _itertoolsr r rr contextlibr importlibr importlib.abcrrtypingrrrr__all__ModuleNotFoundErrorrr2rPr]rrrrrr PurePosixPathrrrrr r rr3rrrrr"rYrrErrr!rCr rHrIr'r'r'r(sx     AF=7(I0/$"5