From 547ed7a69a94437f65e5dea8d654dcb82a3a4c05 Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Thu, 24 Apr 2014 19:22:41 +0200 Subject: [PATCH] setup updated to compliant with eobuilder --- setup.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 27b2d57..e0cc61d 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,50 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -try: - from setuptools import setup -except ImportError: - from ez_setup import use_setuptools - use_setuptools() - from setuptools import setup +from distutils.command.sdist import sdist +from setuptools import setup + +class eo_sdist(sdist): + + def run(self): + print "creating VERSION file" + 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) + print "removing VERSION file" + if os.path.exists('VERSION'): + os.remove('VERSION') + +def get_version(): + + 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( @@ -30,4 +68,7 @@ setup( 'Programming Language :: Python :: 2', ], zip_safe=False, + cmdclass={ + 'sdist': eo_sdist + }, )