1
0
Fork 0
pgcli/release.py

65 lines
1.6 KiB
Python
Raw Normal View History

2014-12-15 00:06:25 +00:00
#!/usr/bin/env python
2014-12-18 18:33:14 +00:00
from __future__ import print_function
2014-12-15 00:06:25 +00:00
import re
import ast
import subprocess
2014-12-18 18:30:58 +00:00
import sys
2014-12-15 00:06:25 +00:00
2014-12-15 00:21:17 +00:00
DEBUG = False
def version(version_file):
2014-12-15 00:06:25 +00:00
_version_re = re.compile(r'__version__\s+=\s+(.*)')
2014-12-15 00:21:17 +00:00
with open(version_file, 'rb') as f:
ver = str(ast.literal_eval(_version_re.search(
2014-12-15 00:06:25 +00:00
f.read().decode('utf-8')).group(1)))
2014-12-15 00:21:17 +00:00
return ver
def commit_for_release(version_file, ver):
cmd = ['git', 'reset']
2014-12-18 18:33:14 +00:00
print(' '.join(cmd))
2014-12-15 00:21:17 +00:00
subprocess.check_output(cmd)
cmd = ['git', 'add', version_file]
2014-12-18 18:33:14 +00:00
print(' '.join(cmd))
2014-12-15 00:21:17 +00:00
subprocess.check_output(cmd)
cmd = ['git', 'commit', '--message', 'Releasing version %s' % ver]
2014-12-18 18:33:14 +00:00
print(' '.join(cmd))
2014-12-15 00:21:17 +00:00
subprocess.check_output(cmd)
2014-12-15 00:06:25 +00:00
def create_git_tag(tag_name):
cmd = ['git', 'tag', tag_name]
2014-12-18 18:33:14 +00:00
print(' '.join(cmd))
2014-12-15 00:06:25 +00:00
subprocess.check_output(cmd)
def register_with_pypi():
cmd = ['python', 'setup.py', 'register']
2014-12-18 18:33:14 +00:00
print(' '.join(cmd))
2014-12-15 00:06:25 +00:00
subprocess.check_output(cmd)
def create_source_tarball():
cmd = ['python', 'setup.py', 'sdist']
2014-12-18 18:33:14 +00:00
print(' '.join(cmd))
2014-12-15 00:06:25 +00:00
subprocess.check_output(cmd)
2015-01-31 23:28:38 +00:00
def push_tags_to_github():
cmd = ['git', 'push', '--tags', 'origin']
print(' '.join(cmd))
subprocess.check_output(cmd)
2014-12-15 00:06:25 +00:00
if __name__ == '__main__':
2014-12-15 00:21:17 +00:00
if DEBUG:
subprocess.check_output = lambda x: x
ver = version('pgcli/__init__.py')
2014-12-18 18:33:14 +00:00
print('Releasing Version:', ver)
choice = raw_input('Are you sure? (y/N)')
2014-12-18 18:30:58 +00:00
if choice.lower() != 'y':
sys.exit(1)
2014-12-15 00:21:17 +00:00
commit_for_release('pgcli/__init__.py', ver)
2014-12-15 00:06:25 +00:00
create_git_tag('v%s' % ver)
register_with_pypi()
create_source_tarball()
2015-01-31 23:28:38 +00:00
push_tags_to_github()