I would like to define a __version__ variable in my module which should be automatically updated on git commit similarly to what SVN keywords do. Is there a way
For those finding this question in 2018 you can also use Versioneer. Once enabled, it automatically sets version in setup.py and __version__ in your module based on the latest Git tag at time of build.
For example, if you build your project at tag 1.0.0, Versioneer will set the project's version to 1.0.0. If you do two more commits, edit some without checking in, and build, Versioneer will set the version to something like 1.0.0+2.g1076c97.dirty.
Of course you can customize which tags Versioneer recognizes as version tags.
This is also how larger projects like pandas and matplotlib handle their versioning.