forked from gitter-badger/hackedit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.py
More file actions
executable file
·40 lines (35 loc) · 1.17 KB
/
pre-commit.py
File metadata and controls
executable file
·40 lines (35 loc) · 1.17 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
#!/usr/bin/env python3
import os
import re
import sys
import subprocess
def bump_version():
with open('hackedit/__init__.py') 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']:
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('hackedit/__init__.py', 'w') as f:
f.write('\n'.join(lines))
f.write('\n')
with open('.commit', 'w') as f:
pass
bump_version()