[Distutils] setuptools, how to read metadata programatically?
jorge.vargas at gmail.com
Sat Jun 30 22:31:37 CEST 2007
On 6/30/07, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 02:02 PM 6/30/2007 -0400, Jorge Vargas wrote:
> >I'm building a plugin manager on top of setuptools and I'll like to
> >know how could I read the package metadata if I got it's EntryPoint.
> Use entrypoint.dist.get_metadata('PKG-INFO') to get the PKG-INFO file
> as a string. See the PKG-INFO format PEPs to understand what's in there.
> Use entrypoint.dist.version to get the version, without needing to
> parse PKG-INFO. (Well, it may get parsed for you, if it's a
> "develop" egg. But the point is, you don't need to explicitly mess
> with PKG-INFO unless you want to get other data than the version.)
I went with the parser since I'm building a UI for users to
enable/disable plugins I n eed all the metadata.
> >basically what I need is get the author, version,etc. I found a
> >pkg_resources.EggMetadata but i'm not sure how to instantiate it
> >because I don't know what a "importer" means in this context.
> You don't need to instantiate those metadata classes; that's done for
> you automatically by functions like 'find_distributions()'. The
> entrypoint.dist attribute will give you a distribution with the right
> type of metadata already attached. Likewise, distribution objects
> obtained from a WorkingSet or Environment will be properly initialized as well.
great thanks for the pointer, I have worked an attr based class which
turned out to be a bit more complicated than what I though in the
first place but it does the job nice (and not that cleanly) here is a
copy if someone is interested.
fields= ['name' ,'version' ,'platform' ,'summary' ,'description'
,'keywords' ,'home_page' ,'author' ,'author_email' ,'license']
for field in fields:
if field in ['home_page','author_email']:
if not value or value == 'UNKNOWN':
More information about the Distutils-SIG