Skip to content

Commit

Permalink
update version.py
Browse files Browse the repository at this point in the history
should fix #23
  • Loading branch information
Changaco committed Nov 24, 2015
1 parent a5e968c commit bfe61de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version.py export-subst
20 changes: 15 additions & 5 deletions version.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
# This program is placed into the public domain.

__all__ = ('get_version')
# Source: https://github.com/Changaco/version.py

from os.path import dirname, isdir, join
import re
from subprocess import CalledProcessError, check_output

__all__ = ('get_version')

tag_re = re.compile(r'\btag: ([0-9][^,]*)\b')
version_re = re.compile('^Version: (.+)$', re.M)


def get_version():
# Return the version if it has been injected into the file by git-archive
version = tag_re.search('$Format:%D$')
if version:
return version.group(1)

d = dirname(__file__)

if isdir(join(d, '.git')):
# Get the version using "git describe".
cmd = 'git describe --tags --match [0-9]*'.split()
cmd = 'git describe --tags --match [0-9]* --dirty'.split()
try:
version = check_output(cmd).decode().strip()
except CalledProcessError:
print('Unable to get version number from git tags')
exit(1)

# PEP 386 compatibility
# PEP 440 compatibility
if '-' in version:
if version.endswith('-dirty'):
print('The working tree is dirty')
exit(1)
version = '.post'.join(version.split('-')[:2])

else:
Expand Down

0 comments on commit bfe61de

Please sign in to comment.