Skip to content

Commit

Permalink
Merge branch 'release/0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
prawn-cake committed Jul 10, 2016
2 parents fe267cd + e8b981b commit d396e21
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.2
current_version = 0.1.3
tag = False
tag_name = {new_version}
commit = True
Expand Down
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Changelog
=========

0.1.2 (2016-07-08)
0.1.3 (2016-07-10)
--------------------
* Remove py27 support, keep only py3, too hassle to maintain it and time to move to be in the new era of python
* [Feature] Added confirmation dialog for 'release' with support of rollback, added --force-yes key to disable it

0.1.2 (2016-07-08)
------------------
* [Improvement] py2/3 compatibility
* [Improvement] implemented changelog.undo()

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
md-changelog
============
[![Build Status](https://travis-ci.org/prawn-cake/md-changelog.svg?branch=master)](https://travis-ci.org/prawn-cake/md-changelog)
[![Coverage Status](https://coveralls.io/repos/github/prawn-cake/md-changelog/badge.svg?branch=master)](https://coveralls.io/github/prawn-cake/md-changelog?branch=master)
![PythonVersions](https://img.shields.io/badge/python-3.4-blue.svg)

Handy command-line tool for managing changelog for your open source projects.

Expand All @@ -13,13 +15,14 @@ Handy command-line tool for managing changelog for your open source projects.
* Git tag integration


## Config

.md-changelog.rc
## Install

pip3 install md-changelog


## Quickstart


# it creates .md-changelog.rc and Changelog.md in the current folder
md-changelog init


Expand Down
22 changes: 14 additions & 8 deletions md_changelog/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def new_entry(self):
:return: LogEntry instance
"""
self._make_backup()
self.make_backup()
log_entry = LogEntry()
if len(self.entries) == 0:
last_version = self.INIT_VERSION
Expand All @@ -212,18 +212,14 @@ def add_entry(self, entry):
if not isinstance(entry, LogEntry):
raise ValueError('Wrong entry type %r, must be %s'
% (entry, LogEntry))
self._make_backup()
self.make_backup()
self.entries.append(entry)

def save(self):
"""Save and sync changes
"""
with open(self.path, 'w') as fd:
fd.write('Changelog\n=========\n\n')
fd.write('\n\n'.join(
[entry.eval() for entry in reversed(self.entries)])
)
fd.write('\n\n')
fd.write(self.eval())

def reload(self):
"""Reload changelog within the same instance
Expand All @@ -238,10 +234,20 @@ def undo(self):
return True
return False

def _make_backup(self):
def make_backup(self):
"""Make deep copy of itself
"""
self._backup = copy.deepcopy(self)

def __repr__(self):
return "%s(entries=%d)" % (self.__class__.__name__, len(self.entries))

def eval(self):
lines = ['Changelog\n=========\n\n']
lines.append(
'\n\n'.join([entry.eval() for entry in reversed(self.entries)]))
lines.append('\n\n')
return ''.join(lines)

def __eq__(self, other):
return self.eval() == other.eval()
37 changes: 27 additions & 10 deletions md_changelog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def get_changelog(config_path):
return Changelog.parse(path=changelog_path)


def get_input(text):
"""Get input wrapper. It basically needs for unittests
:param text: str
:return: input result
"""
return input(text)


def release(args):
"""Make a new release
Expand Down Expand Up @@ -146,15 +155,21 @@ def release(args):
else:
last_entry.set_version(v)

# Backup before release
changelog.make_backup()

last_entry.set_date(tokens.Date())
changelog.save()
subprocess.call([default_editor(), changelog.path])
# confirm = input('Confirm changes? [Y/n]')

# if confirm == 'n':
# changelog.undo()
# logger.info('Undo changes')
# sys.exit(0)
# Skip this step if --force-yes is passed
if not args.force_yes:
subprocess.call([default_editor(), changelog.path])
confirm = get_input('Confirm changes? [Y/n]')
if confirm == 'n':
res = changelog.undo()
logger.info('Undo changes: %s', 'OK' if res else 'Fail')
changelog.save()
sys.exit(0)

changelog.reload()
if not changelog.last_entry.version.released:
Expand Down Expand Up @@ -231,10 +246,10 @@ def add_message(args):
str(changelog.last_entry.version))


def show_current(args):
"""'md-changelog current' command handler
def show_last(args):
"""Show the last changelog log entry
:param args:
:param args: command-line args
"""
changelog = get_changelog(args.config)
print('\n%s\n' % changelog.last_entry.eval())
Expand All @@ -255,6 +270,8 @@ def create_parser():
release_p = subparsers.add_parser(
'release', help='Release current version')
release_p.add_argument('-v', '--version', help='New release version')
release_p.add_argument('-y', '--force-yes', action='store_true',
help="Don't ask changes confirmation")
release_p.set_defaults(func=release)

append_p = subparsers.add_parser(
Expand All @@ -278,7 +295,7 @@ def create_parser():
edit_p.set_defaults(func=edit)

last_p = subparsers.add_parser('last', help='Show last log entry')
last_p.set_defaults(func=show_current)
last_p.set_defaults(func=show_last)

return parser

Expand Down
41 changes: 17 additions & 24 deletions md_changelog/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# -*- coding: utf-8 -*-
import os.path as op
import tempfile
from contextlib import contextmanager

import mock
import pytest

# from six.moves import tempfile
from contextlib import contextmanager

import shutil

from md_changelog import main
from md_changelog.entry import Changelog
from md_changelog.exceptions import ConfigNotFoundError
Expand All @@ -20,20 +16,10 @@ def parser():
return main.create_parser()


@contextmanager
def TemporaryDirectory():
"""Py2/3 tempfile.TemporaryDirectory replacement without external backports
"""
tmp_dir = tempfile.mkdtemp()
yield tmp_dir
shutil.rmtree(tmp_dir)


@contextmanager
def get_test_config():
parser = main.create_parser()
with TemporaryDirectory() as tmp_dir:
with tempfile.TemporaryDirectory() as tmp_dir:
args = parser.parse_args(['init', '--path', tmp_dir])
args.func(args)
cfg_path = op.join(tmp_dir, main.CONFIG_NAME)
Expand All @@ -47,7 +33,7 @@ def test_get_config():


def test_init(parser):
with TemporaryDirectory() as tmp_dir:
with tempfile.TemporaryDirectory() as tmp_dir:
args = parser.parse_args(['init', '--path', tmp_dir])
args.func(args)

Expand Down Expand Up @@ -80,7 +66,8 @@ def test_add_message(parser):
args = parser.parse_args(['-c', cfg_path, 'feature', 'test feature'])
args.func(args)

args = parser.parse_args(['-c', cfg_path, 'bugfix', 'test bugfix'])
# check unicode message
args = parser.parse_args(['-c', cfg_path, 'bugfix', 'багфикс'])
args.func(args)

changelog = Changelog.parse(path=config['md-changelog']['changelog'])
Expand All @@ -94,17 +81,23 @@ def test_release(parser):
with get_test_config() as cfg_path:
args = parser.parse_args(
['-c', cfg_path, 'release'])
args.func(args)
assert call_mock.called is True
args = call_mock.call_args_list[0][0][0]
assert main.default_editor() in args
assert main.CHANGELOG_NAME in args[1]
with mock.patch('md_changelog.main.get_input', return_value='Y') \
as input_mock:
args.func(args)
assert input_mock.called
assert call_mock.called is True
args = call_mock.call_args_list[0][0][0]
assert main.default_editor() in args
assert main.CHANGELOG_NAME in args[1]

# With version '-v'
with get_test_config() as cfg_path:
args = parser.parse_args(
['-c', cfg_path, 'release', '-v', '1.0.0'])
args.func(args)
with mock.patch('md_changelog.main.get_input', return_value='Y') \
as input_mock:
args.func(args)
assert input_mock.called
assert call_mock.called is True
args = call_mock.call_args_list[0][0][0]
assert main.default_editor() in args
Expand Down
2 changes: 1 addition & 1 deletion md_changelog/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def get_user_name(self):
@classmethod
def call_cmd(cls, *args):
output = subprocess.check_output(args)
return str(output.strip())
return str(output).strip()
2 changes: 0 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mock
six
configparser; python_version < '3.2'
pytest
coverage
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[bdist_wheel]
universal=1
universal=0
10 changes: 1 addition & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import sys
from setuptools import setup


req = ['six']
if sys.version_info >= (3, 2):
pass
else:
req.extend(["configparser"])

setup(
name='md-changelog',
version='0.1.2',
version='0.1.3',
packages=['md_changelog'],
url='',
license='MIT',
author='Maksim Ekimovskii',
author_email='ekimovsky.maksim@gmail.com',
description='Changelog command-line tool manager',
install_requires=req,
entry_points={
'console_scripts': [
'md-changelog = md_changelog.main:main'
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py34
envlist = py34

[testenv]
passenv = *
Expand Down

0 comments on commit d396e21

Please sign in to comment.