Skip to content

Instantly share code, notes, and snippets.

@kevinkirkup
Last active August 29, 2015 14:03
Show Gist options
  • Save kevinkirkup/69f19f320664374f2b6a to your computer and use it in GitHub Desktop.
Save kevinkirkup/69f19f320664374f2b6a to your computer and use it in GitHub Desktop.
Generate Version number with Python
#
# Taken from:
# https://github.com/fusionbox/django-authtools
#
import subprocess
version = (0, 2, 0, 'alpha')
def get_version():
number = '.'.join(map(str, version[:3]))
stage = version[3]
if stage == 'final':
return number
# If it's an alpha release, append the first 8 characters of the git sha-1
elif stage == 'alpha':
process = subprocess.Popen('git rev-parse HEAD'.split(), stdout=subprocess.PIPE)
stdout, stderr = process.communicate()
return number + '-' + stdout.decode('utf-8').strip()[:8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment