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__' 0.9.33
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. -Jeff