Versioning a Django project ¶
define __version___ and __build__ into "PROJECT/__init__.py":
from __future__ import absolute_import __version__ = '1.0.0' __build__ = ''
automatic build update (file "settings.py"):
import subprocess import PROJECT BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..',)) try: PROJECT.__build__ = subprocess.check_output(["git", "describe", "--tags", "--always"], cwd=BASE_DIR).decode('utf-8').strip() except: PROJECT.__build__ = PROJECT.__version__ + " ?"
update "PROJECT_settings" context processor (file "PROJECT/context_processors.py"):
from django.conf import settings import PROJECT def PROJECT_settings(request): return { 'PROJECT_VERSION': PROJECT.__version__, 'PROJECT_BUILD': PROJECT.__build__, }
then, in settings:
TEMPLATES = [ { ... 'OPTIONS': { 'context_processors': [ ... 'PROJECT.context_processors.PROJECT_settings', ], }, }, ]
add config file ".bumpversion.cfg":
[bumpversion] current_version = 1.0.0 commit = True tag = True [bumpversion:file:PROJECT/__init__.py]
create a CHANGELOG.rst file:
1.0.1 ----- * versioning added * ...
test bumpversion:
bumpversion patch --dry-run --verbose Would prepare Git commit Would add changes in file 'PROJECT/__init__.py' to Git Would add changes in file '.bumpversion.cfg' to Git Would commit to Git with message 'Bump version: 1.0.0 → 1.0.1' Would tag 'v1.0.1' in Git
- when approriate, bump version and push onto upstream:
(develop)$ bumpversion patch --verbose (develop)$ git checkout master (master)$ git merge develop (master)$ git push (master)$ git push --tags