forked from whitespy/django_audit_trail
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bump_version.py
executable file
·57 lines (41 loc) · 1.86 KB
/
bump_version.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# Encoding: utf-8
import re
import subprocess
def get_last_version_from_tags():
versions = subprocess.check_output(["git", "tag"])
versions = versions.split('\n')
version_regex = re.compile(r'(\d+)\.(\d+)\.(\d+)')
versions = [map(int, v.split('.')) for v in versions if version_regex.match(v)]
versions.sort(reverse=True)
return versions[0]
def generate_version():
if 'nothing to commit' not in subprocess.check_output(["git", "status"]):
print 'Error: You must commit current changes first'
exit()
last_version = get_last_version_from_tags()
with open('setup.py', 'r') as setup_py_file:
setup_py = setup_py_file.read()
new_version = last_version[:]
new_version[2] += 1
last_version = '.'.join(map(str, last_version))
new_version = '.'.join(map(str, new_version))
print 'upgrading from %s to %s' % (last_version, new_version)
version_line_re = re.compile(r'''(__version__ =)(\s*['"]\d+\.\d+\.\d+["'])''', flags=re.M)
with open('setup.py', 'w') as setup_file:
setup_file.write(version_line_re.sub('\\1 "%s"' % new_version, setup_py))
subprocess.check_output(["git", 'commit', '-m', '"version %s"' % new_version, '-a'])
subprocess.check_output(["git", 'tag', '%s' % new_version])
print
print 'Version %s created.' % new_version
push = raw_input('Do you want to push it to origin? YES/no: ')
if (push or 'YES').lower() == 'yes':
deploy = raw_input('Do you want to deploy it to pypi? YES/no: ')
subprocess.check_output(["git", 'push'])
subprocess.check_output(["git", 'push', '--tags'])
if (deploy or 'YES').lower() == 'yes':
subprocess.check_output(["python", 'setup.py', 'sdist', 'upload'])
else:
print 'Push it to origin with "git push --tags"'
if __name__ == '__main__':
generate_version()