Created
March 7, 2012 15:10
-
-
Save cjmeyer/1993716 to your computer and use it in GitHub Desktop.
Python: Generate version number from Git commit description.
This file contains hidden or 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
import time | |
from subprocess import Popen, PIPE | |
try: | |
describe = 'git describe --abbrev=8 --dirty' | |
version = Popen(describe.split(), stdout=PIPE).communicate()[0].strip() | |
except: | |
version = None | |
else: | |
if version.endswith('dirty'): | |
version = version[:-5] + time.strftime('%Y%m%d%H%M') | |
with open('app/__version__.py', 'w') as f: | |
f.write('# this file is autogenerated by setup.py\n') | |
f.write('version = "{0}"\n'.format(version)) | |
try: | |
from app import __version__ | |
version = __version__.version | |
except ImportError: | |
version = 'unknown' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment