-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepare_commit.py
More file actions
executable file
·29 lines (21 loc) · 968 Bytes
/
prepare_commit.py
File metadata and controls
executable file
·29 lines (21 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
"""Prepare build for commit, including version number updating"""
import sys, os
from os.path import join as pjoin
from string import Template
from subprocess import check_output
from smallsocc.version import VERSION_FULL
cdir = pjoin(os.path.dirname(os.path.abspath(__file__)), 'smallsocc')
def commits_since_tag():
return int(check_output('git rev-list $(git rev-list --tags --no-walk --max-count=1)..HEAD --count', shell=True, cwd=cdir).decode('utf-8'))
def git_hash():
if commits_since_tag() > 0:
return check_output('git rev-parse --verify --short=7 HEAD', shell=True, cwd=cdir).decode('utf-8').strip(' \n')
else: return ''
if __name__ == '__main__':
f = pjoin(cdir, "version")
with open(f+'.in', "r") as fd:
temp = Template(fd.read())
with open(f+'.py', 'w') as fd:
fd.writelines(temp.substitute({'version_hash': git_hash()}))
print("Setting version to: {}".format(VERSION_FULL))