-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpre-commit.py
More file actions
executable file
·41 lines (36 loc) · 1.21 KB
/
pre-commit.py
File metadata and controls
executable file
·41 lines (36 loc) · 1.21 KB
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
#!/usr/bin/env python3
import os
import re
import sys
import subprocess
VERSION_FILE = 'pyqode/python/__init__.py'
def bump_version():
with open(VERSION_FILE) as f:
lines = f.read().splitlines()
new_lines = f.newlines
for i, l in enumerate(lines):
if '__version__' in l:
string = l.split('=')[1].strip().replace('"', '').replace("'", '')
for prefix in ['dev', 'a', 'b', 'rc']:
try:
suffix = re.findall(r'%s\d*' % prefix, string)[0]
except IndexError:
suffix = None
version = None
else:
version = int(suffix.replace(prefix, ''))
break
if None in [suffix, version]:
return # stable version, nothing to do
version += 1
new_suffix = '%s%d' % (prefix, version)
new_string = string.replace(suffix, new_suffix)
lines[i] = "__version__ = '%s'" % new_string
print(lines[i])
break
with open(VERSION_FILE, 'w') as f:
f.write('\n'.join(lines))
f.write('\n')
with open('.commit', 'w') as f:
pass
bump_version()