[Distutils] finding my own version with setuptools

Phillip J. Eby pje at telecommunity.com
Wed Nov 9 05:08:49 CET 2005


At 01:55 PM 11/9/2005 +1000, Ashley Walsh wrote:
>Hi,
>
>Is there an easy way for a module to uses its __name__ to identify
>the Distribution it comes from?  I had a look through pkg_resources
>but I couldn't see a straight forward way to do it, so I thought I'd
>ask.
>
>The reason is that I want a console script log its version.

Well, if you know the *project* name, you can just do:

     pkg_resources.get_distribution("ProjectName").version

to look up the distribution for "ProjectName" and get its version.

However, if you don't know the project name, then figuring out the 
distribution is a lot more work.  However, since it's presumably you 
writing the code, you should probably be aware of what your name for the 
project is.  :)



More information about the Distutils-SIG mailing list