-
Notifications
You must be signed in to change notification settings - Fork 3
/
do_release.py
56 lines (41 loc) · 1.69 KB
/
do_release.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
import sys
import os
import re
filename = 'vwoptimize.py'
version_regex = r"__version__ = '([^']+)'"
versiondev_regex = r"(\.\d)dev(')"
def write(filename, data):
fobj = open(filename, 'wb')
fobj.write(data)
fobj.flush()
os.fsync(fobj.fileno())
fobj.close()
def system(cmd):
sys.stderr.write('+ %s\n' % cmd)
if os.system(cmd) != 0:
sys.exit('%r failed' % cmd)
git_describe = os.popen('git describe --tags --dirty').read().strip()
print 'Version from git: %r' % git_describe
version_from_git = git_describe.split('-')[0]
data = open(filename, 'rb').read()
header, rest = data[:200], data[200:]
version_from_source = re.findall(version_regex, header)
assert len(version_from_source) == 1, version_from_source
version_from_source = version_from_source[0]
print 'Version from source: %r' % version_from_source
assert 'dev' in version_from_source, version_from_source
version_from_source = version_from_source.replace('dev', '')
if version_from_git != version_from_source:
sys.exit('Version in the source (%r) is not the same as from git tag (%r), perhaps you forgot "git tag"' %
(version_from_source, version_from_git))
system("cp %s %s.backup" % (filename, filename))
header, count = re.subn(versiondev_regex, r"\1\2", header)
assert count == 1, (count, version_regex, header)
header, count = re.subn(re.escape("GIT"), git_describe, header)
write(filename, header + rest)
os.system('diff -U 1 %s.backup %s' % (filename, filename))
system("%s setup.py sdist" % sys.executable)
system("cp %s.backup %s" % (filename, filename))
print 'Now use twine to do the upload.'
print 'twine upload dist/vwoptimize-X.X.X.tar.gz'
print 'Check on https://pypi.org/project/vwoptimize/'