
On Sat, Jan 10, 2009 at 6:09 PM, Phillip J. Eby <pje@telecommunity.com> wrote:
At 04:08 PM 1/9/2009 -0600, ray terrill wrote:
Is there a way to ask distutils what version of a package is currently installed? I provided the version number when creating my setup.py, but when this is deployed over 800+ clients, I'd like to have a way to interrogate the system to determine which version is installed.
Distutils has no way to do this, but setuptools does. You can get the version number of "SomePackage" using:
pkg_resources.require("SomePackage")[0].version
Note that "SomePackage" is the name of the *project* (i.e., what its PyPI name and distribution filename are based on), not an individual Python module or package or __version__ string within that package.
Also, for this API call to work, "SomePackage" must have been installed by setuptools, or by Python 2.5's distutils (which installs the metadata setuptools uses for version detection).
(You can consult the pkg_resources and setuptools documentation for more details on these matters.)
Why we wouldn't add in Distutils a simplified API for this since it is already taking care of creating the .egg-info ? So people don't have to install an extra tool (setutptools) to get the version of an package installed by distutils. A simpler API that pkg_resources's one, something like:
from distutils import get_package_version get_package_version('SomePackage')
Regards Tarek -- Tarek Ziadé | Association AfPy | www.afpy.org Blog FR | http://programmation-python.org Blog EN | http://tarekziade.wordpress.com/