[Distutils] Specifying version information once
jeff at taupro.com
Wed May 20 11:34:33 CEST 2009
A. Cavallo wrote:
>> No, I would say “too much” here is importing a module not guaranteed to
>> be installed, for creating something as simple as a version. I'd prefer
>> the above to be::
>> $ cat _version.py
>> # This is an auto-generated file. Use magicbean to update.
>> version = "0.9.33"
> Or my preferred way:
> $cat foobar/__init__.py
> __version__ = "0.9.33"
> and import foobar should not trigger code execution anyway IMHO so
> $ python -c 'import foobar; print foobar.__version__'
That doesn't work in all cases. Your example is of an external query of the
version of an installed module. You also need to query the version -before-
it is installed (during the packaging phase) on sys.path, and also from
-within- the foobar module itself. Your code does not handle those cases. An
attempt to 'import foobar; print foobar.__version__' from a setup.py inside
foobar won't find foobar.
More information about the Distutils-SIG