diff --git a/setup.py b/setup.py index 222859e..4a086e5 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,11 @@ #!/usr/bin/env python -import glob -import re -import sys import os +import subprocess from setuptools import setup, find_packages -from setuptools.command.install_lib import install_lib as _install_lib -from distutils.command.build import build as _build -from distutils.command.sdist import sdist -from distutils.cmd import Command +from setuptools.command.sdist import sdist -from eobuilder import VERSION class eo_sdist(sdist): @@ -28,37 +22,25 @@ class eo_sdist(sdist): if os.path.exists('VERSION'): os.remove('VERSION') -def get_version(): - version = VERSION +def get_version(): + '''Use the VERSION, if absent generates a version with git describe, if not + tag exists, take 0.0.0- and add the length of the commit log. + ''' if os.path.exists('VERSION'): - version_file = open('VERSION', 'r') - version = version_file.read() - version_file.close() - return version - 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 + with open('VERSION', 'r') as v: + return v.read() if os.path.exists('.git'): - import subprocess - p = subprocess.Popen(['git','describe','--dirty','--match=v*'], - stdout=subprocess.PIPE) + p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE, + stderr=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 + if p.returncode == 0: + result = result.split()[0][1:] + else: + result = '0.0.0-%s' % len(subprocess.check_output( + ['git', 'rev-list', 'HEAD']).splitlines()) + return result.replace('-', '.').replace('.g', '+g') + return '0.0.0' setup(name="eobuilder", @@ -69,13 +51,9 @@ setup(name="eobuilder", author_email="info@entrouvert.org", maintainer="Jerome Schneider", maintainer_email="info@entrouvert.com", - install_requires=['pytz', - 'GitPython' - ], + install_requires=['pytz', 'GitPython'], include_package_data=True, url='https://dev.entrouvert.org/projects/eobuilder', packages=find_packages(), scripts=('eobuilder-ctl', 'eobuildall'), - cmdclass={'sdist': eo_sdist}, -) - + cmdclass={'sdist': eo_sdist})