Skip to content

Commit

Permalink
Global arguments and reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Sep 22, 2013
1 parent 819b733 commit 7e3b12c
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions changes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@

log = logging.getLogger(__name__)
CHANGELOG = 'CHANGELOG.md'
arguments = None


def extract_version_arguments(arguments):
version_arguments = extract(arguments, ['--major', '--minor', '--patch'])
return dict([
(key[2:], value) for key, value in version_arguments.items()
])


def extract_version_arguments():
"""
Expand Down Expand Up @@ -158,7 +159,7 @@ def write_new_changelog(app_name, filename, content_lines, dry_run=True):
log.info('New changelog:\n%s' % output)


def changelog(arguments):
def changelog():
dry_run = arguments['--dry-run']
app_name = arguments['<app_name>']
new_version = arguments['new_version']
Expand Down Expand Up @@ -215,7 +216,7 @@ def changelog(arguments):
log.info('Added content to CHANGELOG.md')


def version(arguments):
def version():
dry_run = arguments['--dry-run']
app_name = arguments['<app_name>']
new_version = arguments['new_version']
Expand All @@ -227,7 +228,7 @@ def version(arguments):
dry_run=dry_run)


def commit_version_change(arguments):
def commit_version_change():
dry_run = arguments['--dry-run']
app_name = arguments['<app_name>']
new_version = arguments['new_version']
Expand All @@ -242,8 +243,7 @@ def commit_version_change(arguments):
raise Exception('Version change commit failed')


def test(arguments):
dry_run = arguments['--dry-run']
def test():
command = 'nosetests'
if arguments['--tox']:
command = 'tox'
Expand All @@ -258,14 +258,14 @@ def make_virtualenv():
return tmp_dir


def run_test_command(arguments):
def run_test_command():
if arguments['--test-command']:
test_command = arguments['--test-command'].split(' ')
result = execute(test_command, dry_run=arguments['--dry-run'])
log.info('Test command "%s" result: %s', test_command, result)


def install(arguments):
def install():
dry_run = arguments['--dry-run']
app_name = arguments['<app_name>']
new_version = arguments['new_version']
Expand All @@ -283,14 +283,14 @@ def install(arguments):
'%s/bin/python' % tmp_dir
)
log.info('Successfully installed %s sdist', app_name)
run_test_command(arguments)
run_test_command()
except:
raise Exception('Error installing %s sdist', app_name)

path(tmp_dir).rmtree(path(tmp_dir))


def upload(arguments):
def upload():
dry_run = arguments['--dry-run']
pypi = arguments['--pypi']

Expand All @@ -303,7 +303,7 @@ def upload(arguments):
raise Exception('Error uploading')


def pypi(arguments):
def pypi():
dry_run = arguments['--dry-run']
app_name = arguments['<app_name>']
pypi = arguments['--pypi']
Expand All @@ -326,14 +326,14 @@ def pypi(arguments):
log.error('Failed to install %s from %s',
app_name, package_index)

run_test_command(arguments)
run_test_command()
except:
raise Exception('Error installing %s from %s', app_name, package_index)

path(tmp_dir).rmtree(path(tmp_dir))


def tag(arguments):
def tag():
dry_run = arguments['--dry-run']
new_version = arguments['new_version']

Expand All @@ -344,28 +344,33 @@ def tag(arguments):
execute(['git', 'push', '--tags'], dry_run=dry_run)


def release(arguments):
def release():
try:
if not arguments['--skip-changelog']:
changelog(arguments)
version(arguments)
test(arguments)
commit_version_change(arguments)
install(arguments)
upload(arguments)
pypi(arguments)
tag(arguments)
changelog()
version()
test()
commit_version_change()
install()
upload()
pypi()
tag()
except:
log.exception('Error releasing')


def main():
commands = ['release', 'changelog', 'test', 'version', 'tag', 'upload',
'install', 'pypi']

def initialise():
global arguments
arguments = docopt(__doc__, version=changes.__version__)
debug = arguments['--debug']
logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
log.debug('arguments: %s' % arguments)


def main():
initialise()
commands = ['release', 'changelog', 'test', 'version', 'tag', 'upload',
'install', 'pypi']

suppress_version_prompt_for = ['test', 'upload']

Expand All @@ -382,6 +387,6 @@ def main():
arguments['new_version'] = get_new_version(
app_name,
current_version(app_name),
**extract_version_arguments(arguments)
**extract_version_arguments()
)
globals()[command](arguments)
globals()[command]()

0 comments on commit 7e3b12c

Please sign in to comment.