[Distutils] Specifying version information once

Wheat wheatix at gmail.com
Thu May 21 02:34:30 CEST 2009

To chime in here with my two cents,

The version information for a Python distribution should be specified
in setup.py (or setup.py can read this information from somewhere in
the project's files). It should *not* be specified inside a Python
package or module that is part of the distribution itself.

One area where embedding the version inside the module is problematic
is a distribution which provides multiple modules or pacakges.
Remember, one package (or module) does not have to equal one
distribution! A distribution can provide many modules and packages.
Let's say you have the Python project 'foobar'. A 'foobar'
distribution provides the 'foo' package and the 'bar' package. If you
are putting the distribution version in the package, should it be in
foo.__version__ or bar.__version__? Does foo.__version__ and
bar.__version__ both get updated to reflect the version of the foobar
disribution, or are they for more fine grained versioning where they
each specify additional version's beyond the distribution version?

Also it's worth mentioning that PEP 376 (http://www.python.org/dev/
peps/pep-0376/) proposes to solve some of this problem, by providing
an API for reading the version of an installed distribution - and does
so without needing to import any part of that installed distribution.
For the 'foobar' distribution this would be:

import pkgutil
foobar_metadata = pkgutil.get_metadata('foobar')
print foobar_metadata.version

With this API one will be able to consistently query for the version
of an installed *distribution*, and you don't run into the nasty
chicken-and-egg problem of needing to import a package before you
install it to determine it's version, or other weirdness or corner
cases that this approach can cause.

More information about the Distutils-SIG mailing list