Use PEP440-compatible versions

Fixes #1310
This commit is contained in:
ZyX 2015-02-15 01:04:58 +03:00
parent fc7057c85b
commit 99830bad49
2 changed files with 50 additions and 14 deletions

View File

@ -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'])

View File

@ -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(