From e3e1fea51b3d1f0832986a353101e6a1e49c751d Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 13 Mar 2014 13:33:39 +0100 Subject: [PATCH] setup.py: use get_version --- authentic2_idp_ltpa/__init__.py | 2 ++ setup.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/authentic2_idp_ltpa/__init__.py b/authentic2_idp_ltpa/__init__.py index 3b6ffc0..66154cf 100644 --- a/authentic2_idp_ltpa/__init__.py +++ b/authentic2_idp_ltpa/__init__.py @@ -1,3 +1,5 @@ +__version__ = '1.0' + class Plugin(object): def get_before_urls(self): from . import urls diff --git a/setup.py b/setup.py index 24911e8..0e9602f 100755 --- a/setup.py +++ b/setup.py @@ -4,8 +4,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-ltpa', - version='1.0', + version=get_version(), license='AGPLv3', description='Authentic2 IdP LTPA', author="Entr'ouvert",