Last active
August 29, 2015 14:03
-
-
Save kevinkirkup/69f19f320664374f2b6a to your computer and use it in GitHub Desktop.
Generate Version number with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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