title: Automatic version number both in setup.py (setuptools) AND source code?
body: <p><strong>SITUATION:</strong></p>
  
  <p>I have a python library, which is controlled by git, and bundled with distutils/setuptools. And I want to automatically generate version number based on git tags, both for <code>setup.py sdist</code> and alike commands, and for the library itself.</p>
  
  <p>For the first task I can use <code>git describe</code> or alike solutions (see  <a href="https://stackoverflow.com/questions/2058802/how-can-i-get-the-version-defined-in-setup-py-setuptools-in-my-package">How can I get the version defined in setup.py (setuptools) in my package?</a>).</p>
  
  <p>And when, for example, I am in a tag '0.1' and call for 'setup.py sdist', I get 'mylib-0.1.tar.gz'; or 'mylib-0.1-3-abcd.tar.gz' if I altered the code after tagging. This is fine.</p>
  
  <p><strong>THE PROBLEM IS:</strong></p>
  
  <p>The problem comes when I want to have this version number available for the library itself, so it could send it in User-Agent HTTP header as 'mylib/0.1-3-adcd'.</p>
  
  <p>If I add <code>setup.py version</code> command as in <a href="https://stackoverflow.com/questions/2058802/how-can-i-get-the-version-defined-in-setup-py-setuptools-in-my-package">How can I get the version defined in setup.py (setuptools) in my package?</a>, then this version.py is generated AFTER the tag is made, since it uses the tag as a value. But in this case I need to make one more commit after the version tag is made to make the code consistent. Which, in turns, requires a new tag for further bundling.</p>
  
  <p><strong>THE QUESTION IS:</strong></p>
  
  <p>How to break this circle of dependencies (generate-commit-tag-generate-commit-tag-...)?</p>