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?

5
  • 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, 2009 at 14:03
  • I am using SVN, however that's not the equivalent of maven, it's used with maven.
    – Federer
    Nov 24, 2009 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, 2009 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. Nov 24, 2009 at 14:23
  • Duplicate of <a href="stackoverflow.com/questions/458550/… question</a>. Short answer, use __version__.
    – orip
    Nov 24, 2009 at 14:28

3 Answers 3

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.

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.

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'],
      )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.