From e5a9e3ae7f2f3aad733d7b1b7a84047a1ef1ab03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 13 Mar 2018 09:15:03 +0100 Subject: [PATCH] add required versioning code to setup.py --- setup.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/setup.py b/setup.py index 6d92d7e..b6afb95 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,47 @@ #! /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='CartADS', + version=get_version(), author='Grand Lyon', author_email='toto@example.net', url='http://example.net/', packages=find_packages(), + cmdclass={ + 'sdist': eo_sdist, + } )