[Distutils] setuptools, how to read metadata programatically?

Phillip J. Eby pje at telecommunity.com
Sat Jun 30 20:24:12 CEST 2007

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.)

>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.

More information about the Distutils-SIG mailing list