a d>I@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZddl mZgdZGdd d eZGd d d e d d ZGdddejZGdddZGdddZGdddeZ GdddZ!GdddZ"Gddde Z#GdddeZ$ddZ%d d!Z&d"d#Z'd$d%Z(d&d'Z)d(d)Z*d*d+Z+dS),N) ConfigParser)suppress) import_module)MetaPathFinder)starmap) DistributionDistributionFinderPackageNotFoundError distribution distributions entry_pointsfilesmetadatarequiresversionc@seZdZdZdS)r zThe package was not found.N)__name__ __module__ __qualname____doc__rr*/usr/lib64/python3.9/importlib/metadata.pyr %sr c@sneZdZdZedZddZeddZ eddZ ed d Z e d d Z e d dZddZddZdS) 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*)?$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.) patternmatchvaluergroupfiltersplit functoolsreducegetattr)selfrrattrsrrrloadPszEntryPoint.loadcCs|j|j}|dS)Nrrrrrr%rrrrrZszEntryPoint.modulecCs|j|j}|dS)Nrr(r)rrrr_szEntryPoint.attrcCs$|j|j}td|dp dS)Nz\w+extrasr)rrrrefindallrr)rrrr*dszEntryPoint.extrascsfddDS)Ncs,g|]$}|D]\}}|||qqSritems).0rnamerclsconfigrr ksz+EntryPoint._from_config..)sectionsr1rr1r _from_configis zEntryPoint._from_configcCsLtdd}t|_z||Wn"ty@|t|Yn0t |S)N=) delimiters) rstr optionxform read_stringAttributeErrorreadfpioStringIOrr6)r2textr3rrr _from_textqs  zEntryPoint._from_textcCst|j|fS)zO Supply iter so one may construct dicts of EntryPoints easily. )iterr0r%rrr__iter__}szEntryPoint.__iter__cCs|j|j|j|jffSN) __class__r0rrrCrrr __reduce__szEntryPoint.__reduce__N)rrrrr+compilerr'propertyrrr* classmethodr6rArDrGrrrrr)s"      rEntryPointBasezname value groupc@s*eZdZdZd ddZddZddZd S) PackagePathz"A reference to a path in a packageutf-8cCs<|j|d}|WdS1s.0YdS)Nencodinglocateopenread)r%rOstreamrrr read_textszPackagePath.read_textcCs:|d}|WdS1s,0YdS)NrbrP)r%rTrrr read_binaryszPackagePath.read_binarycCs |j|S)z'Return a path-like object for this path)dist locate_filerCrrrrQszPackagePath.locateN)rM)rrrrrUrWrQrrrrrLs rLc@seZdZddZddZdS)FileHashcCs|d\|_}|_dS)Nr7) partitionmoder)r%spec_rrr__init__szFileHash.__init__cCsd|j|jS)Nz)formatr\rrCrrr__repr__szFileHash.__repr__N)rrrr_rarrrrrZsrZc@seZdZdZejddZejddZeddZ edd Z e d d Z e d d Z ed*ddZeddZeddZeddZeddZddZddZeddZdd Zd!d"Zed#d$Ze d%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. Nrr%filenamerrrrUszDistribution.read_textcCsdS)z[ Given a path to a file in this distribution, return a path to it. Nrr%pathrrrrYszDistribution.locate_filecCsH|D]2}|tj|d}tt|d}|dur|Sqt|dS)afReturn 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. r0N)_discover_resolversrContextnextrBr )r2r0resolverdistsrXrrr from_names  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|]}|VqdSrEr)r/rjrmrr sz(Distribution.discover..)pop ValueErrorrrh itertoolschain from_iterablerg)r2kwargsrrnrdiscovers 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 )PathDistributionpathlibPath)rerrratszDistribution.atcCsddtjD}td|S)z#Search the meta_path for resolvers.css|]}t|ddVqdS)find_distributionsN)r$)r/finderrrrrosz3Distribution._discover_resolvers..N)sys meta_pathr )declaredrrrrgsz Distribution._discover_resolversrcCs@ddlm}m}||}tj|j||d}tt| |S)Nr)buildmeta) source_dirsystem) pep517rr compat_systemr"partialrwzipfilery build_as_zip)r2rootrrrbuilderrrr_locals zDistribution._localcCs(|dp|dp|d}t|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. METADATAzPKG-INFOr)rUemailmessage_from_stringr%r@rrrrs  zDistribution.metadatacCs |jdS)z;Return the 'Version' metadata for the distribution package.Version)rrCrrrrszDistribution.versioncCst|dS)Nzentry_points.txt)rrArUrCrrrr szDistribution.entry_pointscs6p}dfdd }|o4tt|t|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|_|_|SrE)rLrZhashintsizerX)r0rsize_strresultrCrr make_files z%Distribution.files..make_file)NN)_read_files_distinfo_read_files_egginfolistrcsvreader)r% file_linesrrrCrr s zDistribution.filescCs|d}|o|S)z* Read the lines of RECORD RECORD)rU splitlinesrrrrr&s z!Distribution._read_files_distinfocCs|d}|otdj|S)z` SOURCES.txt might contain literal commas, so wrap each line in quotes. z SOURCES.txtz"{}")rUmapr`rrrrrr-s z Distribution._read_files_egginfocCs|p|}|ot|S)z6Generated requirements specified for this Distribution)_read_dist_info_reqs_read_egg_info_reqsr)r%reqsrrrr5szDistribution.requirescCs |jdS)Nz Requires-Dist)rget_allrCrrrr;sz!Distribution._read_dist_info_reqscCs |d}|durdS||S)Nz requires.txt)rU_deps_from_requires_text)r%sourcerrrr>s z Distribution._read_egg_info_reqscCs4||}ddt|tdD}||S)NcSs&i|]\}}|tttd|qS)line)rroperator itemgetter)r/sectionresultsrrr Esz9Distribution._deps_from_requires_text..r)_read_sectionsrrrgroupbyrr%_convert_egg_info_reqs_to_simple_reqs)r2r section_pairsr5rrrrBs z%Distribution._deps_from_requires_textccs<d}td|D](}td|}|r.|d}qtVqdS)Nz \[(.*)\]$)r r+rrlocals)linesrr section_matchrrrrLs  zDistribution._read_sectionsc#sVddfdd}dd}|D],\}}|D]}||}||||Vq0q$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|odj|dS)Nzextra == "{name}"rf)r`rfrrrmake_conditionaszJDistribution._convert_egg_info_reqs_to_simple_reqs..make_conditioncsX|pd}|d\}}}|r,|r,d|d}ttd||g}|rTdd|SdS)Nr:()z; z and )r[rr join)rextrasepmarkers conditionsrrr quoted_markerds  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)reqrrr url_req_spacelszIDistribution._convert_egg_info_reqs_to_simple_reqs..url_req_spaceNr-)r5rrrdepsdepspacerrrrVs  z2Distribution._convert_egg_info_reqs_to_simple_reqsN)r)rrrrabcabstractmethodrUrYrJrlrv staticmethodrzrgrrIrrr r rrrrrrrrrrrrrsF              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||dSrE)varsupdate)r%rurrrr_sz#DistributionFinder.Context.__init__cCst|dtjS)z The path that a distribution finder should search. Typically refers to Python package paths and defaults to ``sys.path``. re)rgetr}rerCrrrreszDistributionFinder.Context.path)rrrrr0r_rIrerrrrrhs  rhcCsdS)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%rmrrrr{sz%DistributionFinder.find_distributionsN)rrrrrhrrr{rrrrrzsrc@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)FastPathzF Micro-optimized class for searching a path for children. cCs||_tj|j|_dSrE)rosrebasenamelowerbase)r%rrrrr_szFastPath.__init__cCst|j|SrE)rxryr)r%childrrrjoinpathszFastPath.joinpathcCsltt t|jpdWdS1s.0Ytt|WdS1s^0YgS)Nr)r Exceptionrlistdirr zip_childrenrCrrrchildrens  . &zFastPath.childrencCs2t|j}|j}|j|_tdd|DS)Ncss |]}|tjddVqdS)rrN)r! posixpathr)r/rrrrrosz(FastPath.zip_children..)rryrnamelistrdictfromkeys)r%zip_pathnamesrrrrs    zFastPath.zip_childrencCs&|j}||jkp$||jo$|dS)N.egg)rversionless_egg_name startswithprefixendswith)r%searchrrrris_eggs   zFastPath.is_eggccsZ|D]L}|}||jvsH||jr6||jsH||r|dkr||VqdS)Nzegg-info) rr exact_matchesrrrsuffixesrr)r%r0rn_lowrrrrs    zFastPath.searchN) rrrrr_rrrrrrrrrrs rc@s6eZdZdZdZdZdZdgddZdZddZ dS)PreparedzE A prepared search for metadata on a possibly-named package. r)z .dist-infoz .egg-infoNrcsV|_|durdS|dd_jd_fddjD_jd_dS)N-r^csg|]}j|qSr) normalized)r/suffixrCrrr4sz%Prepared.__init__..r)r0rreplacerrrrr)r%r0rrCrr_s  zPrepared.__init__) rrrrrrrrrr_rrrrrsrc@s,eZdZeefddZeddZdS)MetadataPathFindercCs||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_pathsr0rerrw)r2rmfoundrrrr{s z%MetadataPathFinder.find_distributionscs tjfddtt|DS)z1Find metadata directories in paths heuristically.c3s|]}|tVqdSrE)rr)r/rerfrrrosz3MetadataPathFinder._search_paths..)rrrsrtrr)r2r0pathsrrfrrsz MetadataPathFinder._search_pathsN)rrrrJrrhr{rrrrrrs rc@s.eZdZddZddZejje_ddZdS)rwcCs ||_dS)zConstruct a distribution from a path to the metadata directory. :param path: A pathlib.Path or similar object supporting .joinpath(), __div__, .parent, and .read_text(). N)_pathrdrrrr_szPathDistribution.__init__cCsHtttttt$|j|jddWdS1s:0YdS)NrMrN) rFileNotFoundErrorIsADirectoryErrorKeyErrorNotADirectoryErrorPermissionErrorrrrUrbrrrrUszPathDistribution.read_textcCs |jj|SrE)rparentrdrrrrYszPathDistribution.locate_fileN)rrrr_rUrrrYrrrrrws rwcCs 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). )rrldistribution_namerrrr sr cKstjfi|S)z|Get all ``Distribution`` instances in the current environment. :return: An iterable of ``Distribution`` instances. )rrv)rurrrr !sr cCs t|jS)zGet the metadata for the named package. :param distribution_name: The name of the distribution package to query. :return: An email.Message containing the parsed metadata. )rrlrrrrrr)srcCs 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. )r rrrrrr2srcCsHtjddtD}td}t||d}t||}dd|DS)zwReturn EntryPoint objects for all installed packages. :return: EntryPoint objects for all installed packages. css|] }|jVqdSrE)r )r/rXrrrroAszentry_points..r)keycSsi|]\}}|t|qSr)tuple)r/repsrrrrFsz entry_points..)rrrsrtr r attrgettersortedr)rby_grouporderedgroupedrrrr <s    r cCs 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. )r r rrrrr Lsr cCs t|jS)z Return a list of requirements for the named package. :return: An iterator of requirements, suitable for packaging.requirement.Requirement. )r rrrrrrUsr),r>rr+rrr}rrxrrr"rrr collections configparserr contextlibr importlibr importlib.abcrr__all__ModuleNotFoundErrorr namedtupler PurePosixPathrLrZrrrrrrwr r rrr r rrrrrsN       aY/0