setup.py: compute version from git
This commit is contained in:
parent
d10df3a7f0
commit
98339b258f
34
setup.py
34
setup.py
|
@ -38,8 +38,40 @@ class install_lib(_install_lib):
|
|||
self.run_command('compile_translations')
|
||||
_install_lib.run(self)
|
||||
|
||||
def get_version():
|
||||
import glob
|
||||
import re
|
||||
import os
|
||||
|
||||
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:]
|
||||
major_minor_release = new_version.split('-')[0]
|
||||
assert version == major_minor_release, \
|
||||
'__version__ (%s) must match the last git annotated tag (%s)' % (version, major_minor_release)
|
||||
version = new_version.replace('-', '.')
|
||||
return version
|
||||
|
||||
setup(name='django-journal',
|
||||
version='1.17.0',
|
||||
version=get_version(),
|
||||
license='AGPLv3',
|
||||
description='Keep a structured -- i.e. not just log strings -- journal'
|
||||
' of events in your applications',
|
||||
|
|
Loading…
Reference in New Issue