views:

227

answers:

4

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?

+2  A: 

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
+5  A: 

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.

S.Lott
+2  A: 

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'],
      )
John Paulett
A: 

Duplicate of this question.

Short answer, use __version__.

orip