From 6d307c011705efb4c2d440cc11623e55fb238ac9 Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Sun, 12 Nov 2017 18:36:48 +0100 Subject: [PATCH] Auto versioning by git tags. --- people/__init__.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/people/__init__.py b/people/__init__.py index f59afb3..cac05ea 100644 --- a/people/__init__.py +++ b/people/__init__.py @@ -1,4 +1,32 @@ -VERSION = (1, 0, 0) -__version__ = '.'.join(map(str, VERSION)) +import subprocess + + +try: + git_describe = subprocess.check_output(['git', 'describe', '--tags'], universal_newlines=True, stderr=subprocess.DEVNULL).strip() + # v0.2-69-g181f854 + if git_describe[0] in "vr": + git_describe = git_describe[1:] + parts = git_describe.split("-") + VERSION = parts[0].split(".")[:3] + VERSION += [0] * (3 - len(VERSION)) + git_version = parts[1:] + +except subprocess.CalledProcessError: + # Not yet tagged + VERSION = [0, 0, 0] + git_version = [] + try: + git_version = ( + subprocess.check_output(['git', 'rev-list', '--count', 'HEAD'], universal_newlines=True).strip(), + subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], universal_newlines=True).strip() + ) + except subprocess.CalledProcessError: + git_version = [] + + +# 1.3.0-64-g1f9a30 +__version__ = '-'.join(map(str, ['.'.join(map(str, VERSION)), *git_version])) +VERSION.extend(git_version) + default_app_config = 'people.apps.PeopleConfig'