-
Notifications
You must be signed in to change notification settings - Fork 66
/
fabfile.py
51 lines (36 loc) · 1.45 KB
/
fabfile.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
# -*- coding: utf-8 -*-
import re
import subprocess
from fabric.api import *
@task
def push():
local('git push')
@task
def upload():
local('python setup.py sdist upload')
def get_last_version_from_tags():
versions = subprocess.check_output(["git", "tag"])
versions = versions.split('\n')
version_regex = re.compile('(\d+)\.(\d+)\.(\d+)')
versions = [map(int, v.split('.')) for v in versions if version_regex.match(v)]
versions.sort(reverse=True)
return versions[0]
@task
def inc_version():
if 'nothing to commit' not in subprocess.check_output(["git", "status"]):
print 'Error: You must commit current changes first'
return
last_version = get_last_version_from_tags()
with open('setup.py', 'r') as file:
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 f:
f.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 '\nVersion %s created. Push it to origin with "git push --tags"' % new_version