Version number in Django applications

I was looking for this exact same question, and found your question. The answer you accepted is not quite satisfactory to me.

I am working with django debugtoolbar, in there you can also show all versions of the apps used. I was wondering how to get the versions of my custom applications to show there as well.

Looking a bit further I found this question and answer:
How to check the version of a installed application in Django in running time?

This answer however does not tell me where to put this __version__

So I looked in to an open application, which does show up in django toolbar.
I looked in to the django restframework code, there I found out:

the version is put in the __init__.py file

(see https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/init.py)

and it is put here as:

__version__ = '2.2.7'
VERSION = __version__  # synonym

And after this, in his setup.py, he gets this version from this __init__.py :
see: https://github.com/tomchristie/django-rest-framework/blob/master/setup.py

like this:

import re

def get_version(package):
    """
    Return package version as listed in `__version__` in `init.py`.
    """
    init_py = open(os.path.join(package, '__init__.py')).read()
    return re.match("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)

version = get_version('rest_framework')

When using buildout and zestreleaser:

By the way, I am using buildout and zest.releaser for building and versioning.

In this case, above is a bit different (but basically the same idea):

see http://zestreleaser.readthedocs.org/en/latest/versions.html#using-the-version-number-in-setup-py-and-as-version

The version in setup.py is automatically numbered by setup.py, so in __init__.py you do:

import pkg_resources

__version__ = pkg_resources.get_distribution("fill in yourpackage name").version
VERSION = __version__  # synonym

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)