2

With my Java projects at present, I have full version control by declaring it as a Maven project. However I now have a Python project that I'm about to tag 0.2.0 which has no version control. Therefore should I come accross this code at a later date, I won't no what version it is.

How do I add version control to a Python project, in the same way Maven does it for Java?

Federer
  • 33,677
  • 39
  • 93
  • 121
  • I don't know Maven, but why can't you use some simple version control system not specific to Python (svn, git, bazaar...)? – Makis Nov 24 '09 at 14:03
  • I am using SVN, however that's not the equivalent of maven, it's used *with* maven. – Federer Nov 24 '09 at 14:06
  • Hm, do you want to see the version in the source file? I don't know if svn has tags that you could use (basically they are at check-out time changed to include what data you want, e.g. version number, author etc), but at least with git you could write a very simple hook for that. – Makis Nov 24 '09 at 14:08
  • 4
    I think you are talking about "version numbering" and not "version control". Version control is typically defined as tools that Makis mentions, such as svn, git, hg, bzr. – John Paulett Nov 24 '09 at 14:23
  • Duplicate of this question. Short answer, use `__version__`. – orip Nov 24 '09 at 14:28

3 Answers3

5

First, maven is a build tool and has nothing to do with version control. You don't need a build tool with Python -- there's nothing to "build".

Some folks like to create .egg files for distribution. It's as close to a "build" as you get with Python. This is a simple setup.py file.

You can use SVN keyword replacement in your source like this. Remember to enable keyword replacement for the modules that will have this.

__version__ = "$Revision$"

That will assure that the version or revision strings are forced into your source by SVN.

You should also include version keywords in your setup.py file.

orip
  • 73,323
  • 21
  • 116
  • 148
S.Lott
  • 384,516
  • 81
  • 508
  • 779
3

Create a distutils setup.py file. This is the Python equivalent to maven pom.xml, it looks something like this:

from distutils.core import setup
setup(name='foo',
      version='1.0',
      py_modules=['foo'],
      )

If you want dependency management like maven, take a look at setuptools.

Ants Aasma
  • 53,288
  • 15
  • 90
  • 97
3

Ants's answer is correct, but I would like to add that your modules can define a __version__ variable, according to PEP 8, which can be populated manually or via Subversion or CVS, e.g. if you have a module thingy, with a file thingy/__init__.py:

___version___ = '0.2.0'

You can then import this version in setup.py:

from distutils.core import setup
import thingy
setup(name='thingy',
      version=thingy.__version__,
      py_modules=['thingy'],
      )
orip
  • 73,323
  • 21
  • 116
  • 148
John Paulett
  • 15,596
  • 4
  • 45
  • 38