On Jan 29, 2010, at 7:32 PM, Ben Finney wrote:
"P.J. Eby"
writes: At 04:05 PM 1/29/2010 -0500, Barry Warsaw wrote:
The important thing is to have exactly one place to set the package's version number.
Put it in setup.py, then. If you absolutely must have a __version__ at runtime, use this to extract it from the installation metadata:
__version__ = pkg_resources.require('MyProject')[0].version
Mostly, though, I don't bother with having a __version__ in my modules or packages any more, since you can just do the above if you want to check the installed version of something.
That assumes that the only things that will need to query the package's version are Python modules. That's often not the case, especially when there are other tools (e.g. shell programs, make files, or any program not written in Python) that are part of the same package.
Better would be to have a *non-executable* data file containing the version string and other such package meta-data. “Query the metadata” should not necessarily imply “parse or execute a bunch of Python code”.
I'd love to have a standard, documented way to set/query module versions. I actually started this e-mail about a week ago when I went looking for a "standard" way to version something the other day and, after I couldn't find a definitive answer by Googling, went looking in the stdlib for guidance. I started with two core modules, sys and distutils, and tried just doing the same things to both modules:
import sys
sys.version '2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) \n[GCC 4.0.1 (Apple Inc. build 5493)]'
sys.version_info (2, 6, 4, 'final', 0)
sys.__version__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute '__version__'
#--------------------------------------------
import distutils
distutils.version
distutils.version_info Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'version_info'
distutils.__version__ '2.6.4'
The standard library, and modules in PyPI, are all over the place on it so maybe a completely new API/method is in order. S