On Wed, Aug 12, 2009 at 2:31 PM, Hanno Schlichting<[email protected]> wrote: > On Wed, Aug 12, 2009 at 2:18 PM, Barry Warsaw<[email protected]> wrote: >> On Aug 12, 2009, at 4:35 AM, Tarek Ziadé wrote: >> >> One feature I would love to see make standard is the ability to import a >> package and check its __version__. Version information must be available >> from Python, and it seems like __version__ is the standard place to put it. >> Too many times I've had to figure out the version of foo.bar that I'm >> using. When I can do >> >>>>> import foo.bar >>>>> foo.bar.__version__ >> 3.2.1 >> >> I am a much happier camper. > > The easiest way I could find right now seems to be: > >>>> import pkg_resources >>>> dist = pkg_resources.get_distribution('foo') >>>> dist.version > 3.2.1 > > Which isn't too bad and could be simplified into an even simpler API call. > > If the package author doesn't set a __version__ attribute in his own > code, I'd be hesitant to magically make it available from the > accompanying metadata. If it's part of the metadata, an explicit API > that makes it clear that you are querying the package metadata seems > cleaner to me.
yes, and with PEP 376 (which I need to work back in asap), it will be similar and we will have that explicit, clean, get_metadata api. Notice that I think it's better to use pkg_resources (and PEP 376) tehcnique because it grabs the version number in the PKG-INFO file which is static, and doesn't forces you to import a module in the execution context just to get the version. You never know what gets executed when you import a module Cheers Tarek > > Hanno > _______________________________________________ > Distutils-SIG maillist - [email protected] > http://mail.python.org/mailman/listinfo/distutils-sig > -- Tarek Ziadé | http://ziade.org _______________________________________________ Distutils-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/distutils-sig
