From 7d2ea47fd3ad04e736078d7ef69983b97ab20a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 28 Feb 2018 09:32:47 +0100 Subject: [PATCH] add required versioning code to setup.py --- setup.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/setup.py b/setup.py index 4491618..44dfd8f 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,38 @@ #! /usr/bin/env python +import os +import subprocess + from setuptools import setup, find_packages +from distutils.command.sdist import sdist + +class eo_sdist(sdist): + def run(self): + if os.path.exists('VERSION'): + os.remove('VERSION') + version = get_version() + version_file = open('VERSION', 'w') + version_file.write(version) + version_file.close() + sdist.run(self) + if os.path.exists('VERSION'): + os.remove('VERSION') + +def get_version(): + if os.path.exists('VERSION'): + version_file = open('VERSION', 'r') + version = version_file.read() + version_file.close() + return version + if os.path.exists('.git'): + p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE) + result = p.communicate()[0] + if p.returncode == 0: + version = result.split()[0][1:] + version = version.replace('-', '.') + return version + return '0' + setup( name='grandlyon-iodas', @@ -8,4 +40,7 @@ setup( author_email='toto@example.net', url='http://example.net/', packages=find_packages(), + cmdclass={ + 'sdist': eo_sdist, + } )