[Distutils] Specifying version information once
ben+python at benfinney.id.au
Thu May 21 04:59:37 CEST 2009
Wheat <wheatix at gmail.com> writes:
> 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).
Yes, agreed completely.
> It should *not* be specified inside a Python package or module that is
> part of the distribution itself.
Why not? It certainly makes sense for the programs to be able to
discover their own version. I hope you don't advocate duplicating the
version in another place for this purpose?
> 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.
In this case, I'm of the opinion that each Python package should know
its own version (via a simple module that declares or discovers it, with
no dependency on anything but standard Python), and the package
distribution tools should choose one of those Python packages to be the
one which determines the distribution version.
> 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__?
I'd say the distribution version should be identical to one of the
packages, as chosen by whoever's maintaining the distribution
> 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
Sure. This fits my constraint that the version should be discoverable by
importing a Python module without any dependencies on anything except
standard Python. It just means that “standard Python” would need to
include that ‘pkgutil’ module.
\ “I don't care to belong to a club that accepts people like me |
`\ as members.” —Groucho Marx |
More information about the Distutils-SIG