Way to ask distutils what version of a package is installed?

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. Thanks, -Ray

On Fri, Jan 9, 2009 at 11:08 PM, ray terrill <rayjohnterrill@gmail.com> 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.
Unfortunately not by code, or not in an universal way I know of.. Distutils creates an YOUR-PACKAGE-VERSION.egg-info file in your package-includes folder, that contains the information. If you use setuptools though, it might be located in YOUR-PACKAGE-VERSION.egg/EGG-INFO/PKG-INFO Imho, I think the best way to get the version of your packages would be to maintain a __version__ string in your package to be able to query it from the code. That said, it would make sense to include in Distutils an API that would let people browse by the Metadata of the *.egg-info files for installed packages. Regards Tarek
Thanks, -Ray
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- Tarek Ziadé | Association AfPy | www.afpy.org Blog FR | http://programmation-python.org Blog EN | http://tarekziade.wordpress.com/

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

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/

On Sat, Jan 10, 2009 at 6:21 PM, Tarek Ziadé <ziade.tarek@gmail.com> wrote:
A simpler API that pkg_resources's one, something like:
from distutils import get_package_version get_package_version('SomePackage')
A generic API could be ;
from distutils import get_metadata get_metadata('SomePackage') {'Name' : 'SomePackage', 'Version': 'xxx', ...}
Regards Tarek
participants (3)
-
Phillip J. Eby
-
ray terrill
-
Tarek Ziadé