Skip to content

Commit

Permalink
Bootstrap init command
Browse files Browse the repository at this point in the history
  • Loading branch information
noirbizarre committed Nov 9, 2017
1 parent 428a215 commit 47e4c8e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,2 +1,3 @@
include README.rst CHANGELOG.rst LICENSE MANIFEST.in
recursive-include bumpr *.yml
recursive-include requirements *.pip
19 changes: 18 additions & 1 deletion bumpr/cli.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals

import io
import logging
import pkg_resources

import click

Expand All @@ -13,6 +15,7 @@
from bumpr.vcs import VCS
from bumpr.version import Version

click.disable_unicode_literals_warning = True

log = logging.getLogger(__name__)

Expand All @@ -22,7 +25,7 @@
}


@click.command(context_settings=CONTEXT_SETTINGS)
@click.group(context_settings=CONTEXT_SETTINGS, invoke_without_command=True)
@click.option('-v', '--verbose', is_flag=True, help='Verbose output')
@click.option('--version', is_flag=True, help='Print the current version')
@click.option('-c', '--config', default='bumpr.rc', help='Specify a configuration file')
Expand All @@ -46,6 +49,9 @@ def cli(ctx, verbose, **kwargs):
click.echo(__version__)
ctx.exit()

if ctx.invoked_subcommand:
return

try:
config = Config(parsed_args=ctx.params)
except Exception as e:
Expand All @@ -66,3 +72,14 @@ def cli(ctx, verbose, **kwargs):
except BumprError as error:
log.error(str(error))
ctx.exit(1)


@cli.command()
@click.option('-s', '--source', prompt='Where are you extracting version from', default='__init__.py')
@click.option('-c', '--changelog', prompt='Changelog file', default='CHANGELOG.rst')
def init(**kwargs):
'''Initialize a new project configuration'''
tpl = pkg_resources.resource_string(__name__, 'template.yml').decode('utf8')
with io.open('bumpr.yml', 'wb') as f:
f.write(tpl.format(**kwargs).encode('utf8'))
log.info('Configuration file initialized in bumpr.cfg')
49 changes: 49 additions & 0 deletions bumpr/template.yml
@@ -0,0 +1,49 @@
---
# Base parameters
#################
# The version string is extracted from this file
source: {source}
# using this regexp
# regex: (__version__|VERSION)\s*=\s*(\'|")(?P<version>.+?)(\'|")'

# This files are processed for replacements
files: []

# Version control system
########################
vcs:
push: true
# Annotate tags
# tag_annotation: version {{version}}

# Hooks global configuration
############################
changelog:
file: {changelog}

# Read the doc hook
# readthedoc:
# id: bumpr

# Workflow steps configuration
##############################

clean: python setup.py clean

test: python setup.py test

bump:
unsuffix: true
message: Bumped version {{version}}
changelog: '{{version}} ({{date:%Y-%m-%d}})'
replacements:
'?branch=master': '?tag={{version}}'

publish: python setup.py bdist_wheel upload

prepare:
part: patch
suffix: dev
changelog: Current
replacements:
'?tag={{version}}': '?branch=master'
2 changes: 2 additions & 0 deletions requirements/install.pip
@@ -1,2 +1,4 @@
click==6.7
packaging
setuptools
pyyaml
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -41,6 +41,7 @@ def pip(name):
author='Axel Haustant',
author_email='noirbizarre+github@gmail.com',
packages=find_packages(),
include_package_data=True,
install_requires=install_requires,
license='LGPL',
zip_safe=False,
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Expand Up @@ -43,6 +43,11 @@ def write(self, filename, content):
f.write(content.encode('utf8'))
return target

def read(self, filename):
target = self.root / filename
with target.open() as f:
return f.read()

def mkdir(self, dirname):
try:
self.root.mkdir(dirname)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Expand Up @@ -6,6 +6,7 @@
from bumpr.version import Version

import pytest
import yaml


@pytest.fixture
Expand Down Expand Up @@ -128,3 +129,14 @@ def test_full_run(workspace):
'''))
assert workspace.bumpr().exit_code == 0
assert "__version__ = '1.2.4.dev'" in workspace.module.open().read()


def test_init_with_parameters(workspace):
params = 'init -s bumpr/__init__.py -c CHANGELOG.rst'
assert workspace.bumpr(params).exit_code == 0
assert (workspace.root / 'bumpr.yml').exists()

data = yaml.load(workspace.read('bumpr.yml'))

assert data['source'] == 'bumpr/__init__.py'
assert data['changelog']['file'] == 'CHANGELOG.rst'

0 comments on commit 47e4c8e

Please sign in to comment.