Skip to content

Commit

Permalink
Ported release script improvements from mycli.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bennet committed Mar 21, 2018
1 parent 97475bf commit a1864ff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
53 changes: 33 additions & 20 deletions release.py
@@ -1,10 +1,14 @@
#!/usr/bin/env python
"""A script to publish a release of pgcli to PyPI."""

from __future__ import print_function
import io
from optparse import OptionParser
import re
import ast
import subprocess
import sys
from optparse import OptionParser

import click

DEBUG = False
CONFIRM_STEPS = False
Expand All @@ -19,9 +23,7 @@ def skip_step():
global CONFIRM_STEPS

if CONFIRM_STEPS:
choice = raw_input("--- Confirm step? (y/N) [y] ")
if choice.lower() == 'n':
return True
return not click.confirm('--- Run this step?', default=True)
return False


Expand All @@ -44,31 +46,32 @@ def run_step(*args):


def version(version_file):
_version_re = re.compile(r'__version__\s+=\s+(.*)')
_version_re = re.compile(
r'__version__\s+=\s+(?P<quote>[\'"])(?P<version>.*)(?P=quote)')

with open(version_file, 'rb') as f:
ver = str(ast.literal_eval(_version_re.search(
f.read().decode('utf-8')).group(1)))
with io.open(version_file, encoding='utf-8') as f:
ver = _version_re.search(f.read()).group('version')

return ver


def commit_for_release(version_file, ver):
run_step('git', 'reset')
run_step('git', 'add', version_file)
run_step('git', 'commit', '--message', 'Releasing version %s' % ver)
run_step('git', 'commit', '--message',
'Releasing version {}'.format(ver))


def create_git_tag(tag_name):
run_step('git', 'tag', '-s', '-m', tag_name, tag_name)
run_step('git', 'tag', tag_name)


def create_source_tarball():
run_step('python', 'setup.py', 'sdist')
def create_distribution_files():
run_step('python', 'setup.py', 'sdist', 'bdist_wheel')


def upload_source_tarball():
run_step('python', 'setup.py', 'sdist', 'upload')
def upload_distribution_files():
run_step('twine', 'upload', 'dist/*')


def push_to_github():
Expand All @@ -79,10 +82,21 @@ def push_tags_to_github():
run_step('git', 'push', '--tags', 'origin')


def checklist(questions):
for question in questions:
if not click.confirm('--- {}'.format(question), default=False):
sys.exit(1)


if __name__ == '__main__':
if DEBUG:
subprocess.check_output = lambda x: x

checks = ['Have you updated the AUTHORS file?',
'Have you updated the `Usage` section of the README?',
]
checklist(checks)

ver = version('pgcli/__init__.py')
print('Releasing Version:', ver)

Expand All @@ -101,13 +115,12 @@ def push_tags_to_github():
CONFIRM_STEPS = popts.confirm_steps
DRY_RUN = popts.dry_run

choice = raw_input('Are you sure? (y/N) [n] ')
if choice.lower() != 'y':
if not click.confirm('Are you sure?', default=False):
sys.exit(1)

commit_for_release('pgcli/__init__.py', ver)
create_git_tag('v%s' % ver)
create_source_tarball()
create_git_tag('v{}'.format(ver))
create_distribution_files()
push_to_github()
push_tags_to_github()
upload_source_tarball()
upload_distribution_files()
2 changes: 2 additions & 0 deletions requirements-dev.txt
Expand Up @@ -9,3 +9,5 @@ docutils>=0.13.1
autopep8==1.3.3
# we want the latest possible version of pep8radius
git+https://github.com/hayd/pep8radius.git
click==6.7
twine==1.11.0

0 comments on commit a1864ff

Please sign in to comment.