From d097509b3f46f5780cf3c72bbca782304c81e479 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 13 Mar 2014 13:42:10 +0100 Subject: [PATCH] setup.py: use get_version --- authentic2_idp_cas/__init__.py | 1 + setup.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/authentic2_idp_cas/__init__.py b/authentic2_idp_cas/__init__.py index ae88d52..575a7f0 100644 --- a/authentic2_idp_cas/__init__.py +++ b/authentic2_idp_cas/__init__.py @@ -1,6 +1,7 @@ from django.utils.timezone import now from django.template.loader import render_to_string +__version__ = '1.0' class Plugin(object): def get_before_urls(self): diff --git a/setup.py b/setup.py index 71b60cc..2fa8c01 100755 --- a/setup.py +++ b/setup.py @@ -2,8 +2,38 @@ from setuptools import setup, find_packages import os +def get_version(): + import glob + import re + import os + + version = None + for d in glob.glob('*'): + if not os.path.isdir(d): + continue + module_file = os.path.join(d, '__init__.py') + if not os.path.exists(module_file): + continue + for v in re.findall("""__version__ *= *['"](.*)['"]""", + open(module_file).read()): + assert version is None + version = v + if version: + break + assert version is not None + if os.path.exists('.git'): + import subprocess + p = subprocess.Popen(['git','describe','--dirty','--match=v*'], + stdout=subprocess.PIPE) + result = p.communicate()[0] + assert p.returncode == 0, 'git returned non-zero' + new_version = result.split()[0][1:] + assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag' + version = new_version.replace('-', '.') + return version + setup(name='authentic2-idp-cas', - version='1.0', + version=get_version(), license='AGPLv3', description='Authentic2 IdP CAS', author="Entr'ouvert",