get version from git

This commit is contained in:
j 2015-11-15 14:52:59 +01:00
parent 98d83192ce
commit c5f5262a96
2 changed files with 8 additions and 9 deletions

View file

@ -1,4 +0,0 @@
build
dist
oxutils.egg-info
ox/__version.py

View file

@ -1,21 +1,24 @@
#!/usr/bin/env python #!/usr/bin/env python
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
# encoding: utf-8 # encoding: utf-8
try: try:
from setuptools import setup from setuptools import setup
except: except:
from distutils.core import setup from distutils.core import setup
def get_revision():
import subprocess
return subprocess.check_output(['git', 'rev-list', 'HEAD', '--count']).strip()
def get_version(): def get_version():
import os import os
import re import re
info = os.path.join(os.path.dirname(__file__), '.bzr/branch/last-revision') _git = os.path.join(os.path.dirname(__file__), '.git')
__version = os.path.join(os.path.dirname(__file__), 'ox/__version.py') __version = os.path.join(os.path.dirname(__file__), 'ox/__version.py')
changelog = os.path.join(os.path.dirname(__file__), 'debian/changelog') changelog = os.path.join(os.path.dirname(__file__), 'debian/changelog')
if os.path.exists(info): if os.path.exists(_git):
f = open(info) rev = get_revision()
rev = int(f.read().split()[0])
f.close()
if rev: if rev:
version = "2.3.%d" % rev version = "2.3.%d" % rev
with open(__version, 'w') as fd: with open(__version, 'w') as fd: