diff --git a/scripts/powerline-release.py b/scripts/powerline-release.py index 0c3eba10..2d3a7f10 100755 --- a/scripts/powerline-release.py +++ b/scripts/powerline-release.py @@ -48,24 +48,56 @@ def parse_version(s): return tuple(map(int, s.split('.'))) +def setup_py_filter(filter_func): + with codecs.open('.setup.py.new', 'w', encoding='utf-8') as NS: + with codecs.open('setup.py', 'r', encoding='utf-8') as OS: + for line in OS: + line = filter_func(line) + NS.write(line) + + os.unlink('setup.py') + os.rename('.setup.py.new', 'setup.py') + + +def setup_py_develop_filter(line, version_string): + if line.startswith('\tbase_version = '): + line = '\tbase_version = \'' + version_string + '\'\n' + return line + + +def setup_py_master_filter(line, version_string): + if line.startswith('\tversion='): + line = '\tversion=\'' + version_string + '\',\n' + elif 'Development Status' in line: + line = '\t\t\'Development Status :: 5 - Production/Stable\',\n' + return line + + def merge(version_string, rev, **kwargs): + check_call(['git', 'checkout', rev]) + + temp_branch_name = 'release-' + version_string + check_call(['git', 'checkout', '-b', temp_branch_name]) + setup_py_filter(lambda line: setup_py_develop_filter(line, version_string)) + check_call(['git', 'add', 'setup.py']) + check_call(['git', 'commit', '-m', 'Update base version']) + check_call(['git', 'checkout', rev]) + check_call(['git', 'merge', '--no-ff', + '--strategy', 'recursive', + '--strategy-option', 'theirs', + '--commit', + '-m', 'Merge branch \'{0}\' into {1}'.format(temp_branch_name, rev)]) + check_call(['git', 'branch', '-d', temp_branch_name]) + + rev = check_output(['git', 'rev-parse', 'HEAD']).strip() + check_call(['git', 'checkout', 'master']) try: check_call(['git', 'merge', '--no-ff', '--no-commit', '--log', rev]) except CalledProcessError: check_call(['git', 'mergetool', '--tool', 'vimdiff2']) - with codecs.open('.setup.py.new', 'w', encoding='utf-8') as NS: - with codecs.open('setup.py', 'r', encoding='utf-8') as OS: - for line in OS: - if line.startswith('\tversion='): - line = '\tversion=\'' + version_string + '\',\n' - elif 'Development Status' in line: - line = '\t\t\'Development Status :: 5 - Production/Stable\',\n' - NS.write(line) - - os.unlink('setup.py') - os.rename('.setup.py.new', 'setup.py') + setup_py_filter(lambda line: setup_py_master_filter(line, version_string)) check_call(['git', 'add', 'setup.py']) check_call(['git', 'commit']) diff --git a/setup.py b/setup.py index 7dbf0217..5160c19f 100755 --- a/setup.py +++ b/setup.py @@ -8,6 +8,7 @@ import subprocess import logging import shlex +from traceback import print_exc from setuptools import setup, find_packages @@ -58,10 +59,13 @@ else: def get_version(): + base_version = '2.0' + base_version += '.dev9999' try: - return 'dev-' + subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() - except Exception as e: - return 'dev' + return base_version + '+git.' + str(subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()) + except Exception: + print_exc() + return base_version setup(