From 08bfb7515e88da2d0c6de4e667cbbfeac6c4bf42 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 16 Mar 2016 13:42:24 +0100 Subject: [PATCH] setup.py: use our own get_version() --- setup.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 6b8613a..4afa103 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,36 @@ #!/usr/bin/env python +import os +import subprocess from os.path import exists -from version import get_git_version - try: from setuptools import setup except ImportError: from distutils.core import setup +def get_version(): + '''Use the VERSION, if absent generates a version with git describe, if not + tag exists, take 0.0.0- and add the length of the commit log. + ''' + if os.path.exists('VERSION'): + with open('VERSION', 'r') as v: + return v.read() + if os.path.exists('.git'): + p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + result = p.communicate()[0] + if p.returncode == 0: + result = result.split()[0][1:] + else: + result = '0.0.0-%s' % len(subprocess.check_output( + ['git', 'rev-list', 'HEAD']).splitlines()) + return result.replace('-', '.').replace('.g', '+g') + return '0.0.0' + setup( name='django-tenant-schemas', - version=get_git_version(), + version=get_version(), author='Bernardo Pires Carneiro', author_email='carneiro.be@gmail.com', packages=[