Skip to content

Commit

Permalink
Merge pull request #45 from michaeljoseph/reorganisation
Browse files Browse the repository at this point in the history
Reorganisation
  • Loading branch information
michaeljoseph committed Oct 25, 2013
2 parents 33cbebb + dd06b22 commit 345ef53
Show file tree
Hide file tree
Showing 24 changed files with 523 additions and 295 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Usage:
changes [options] <app_name> changelog
changes [options] <app_name> release
changes [options] <app_name> bump_version
changes [options] <app_name> test
changes [options] <app_name> run_tests
changes [options] <app_name> install
changes [options] <app_name> upload
changes [options] <app_name> pypi
Expand All @@ -68,12 +68,15 @@ Options:
--tox Use `tox` instead of the default: `nosetests`
--test-command=<cmd> Command to use to test the newly installed package
--version-prefix=<prefix> Specify a prefix for version number tags
--noinput To be used in conjuction with one of the increment
options above, this option stops `changes` from
confirming the new version number.
--debug Debug output.
The commands do the following:
changelog Generates an automatic changelog from your commit messages
bump_version Increments the __version__ attribute of your module's __init__
test Runs your tests with nosetests
run_tests Runs your tests with nosetests
install Attempts to install the sdist
tag Tags your git repo with the new version number
upload Uploads your project with setup.py clean sdist upload
Expand Down Expand Up @@ -176,7 +179,7 @@ Lint the project with:

Generate the documentation with:

cd docs && PYTHONPATH=.. make singlehtml
(cd docs && make singlehtml)

To monitor changes to Python files and execute flake8 and nosetests
automatically, execute the following from the root project directory:
Expand Down
2 changes: 1 addition & 1 deletion changes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@


from .cli import main # noqa
from .pandoc import md2rst
from .pandoc import md2rst # noqa
7 changes: 2 additions & 5 deletions changes/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from path import path

from changes import shell
import sh

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -32,10 +32,7 @@ def replace_attribute(app_name, attribute_name, new_value, dry_run=True):
if not dry_run:
path(tmp_file).move(init_file)
else:
log.debug(shell.execute(
'diff %s %s' % (tmp_file, init_file),
dry_run=False
))
log.debug(sh.diff(tmp_file, init_file, _ok_code=1))


def has_attribute(app_name, attribute_name):
Expand Down
102 changes: 102 additions & 0 deletions changes/changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import logging
import re

import sh
from changes import attributes, config, version

log = logging.getLogger(__name__)


def write_new_changelog(app_name, filename, content_lines, dry_run=True):
heading_and_newline = (
'# [Changelog](%s/releases)\n' %
attributes.extract_attribute(app_name, '__url__')
)

with open(filename, 'r+') as f:
existing = f.readlines()

output = existing[2:]
output.insert(0, '\n')

for index, line in enumerate(content_lines):
output.insert(0, content_lines[len(content_lines) - index - 1])

output.insert(0, heading_and_newline)

output = ''.join(output)

if not dry_run:
with open(filename, 'w+') as f:
f.write(output)
else:
log.info('New changelog:\n%s', ''.join(content_lines))


def replace_sha_with_commit_link(git_log_content):
repo_url = attributes.extract_attribute(
config.common_arguments()[0],
'__url__'
)

for index, line in enumerate(git_log_content):
# http://stackoverflow.com/a/468378/5549
sha1_re = re.match(r'^[0-9a-f]{5,40}\b', line)
if sha1_re:
sha1 = sha1_re.group()

new_line = line.replace(
sha1,
'[%s](%s/commit/%s)' % (sha1, repo_url, sha1)
)
log.debug('old line: %s\nnew line: %s', line, new_line)
git_log_content[index] = new_line

return git_log_content


def changelog():
app_name, dry_run, new_version = config.common_arguments()

changelog_content = [
'\n## [%s](%s/compare/%s...%s)\n\n' % (
new_version, attributes.extract_attribute(app_name, '__url__'),
version.current_version(app_name), new_version,
)
]

git_log_content = sh.git.log(
'--oneline',
'--no-merges',
'%s..master' % version.current_version(app_name),
_tty_out=False
).split('\n')
log.debug('content: %s' % git_log_content)

if not git_log_content:
log.debug('sniffing initial release, drop tags')
git_log_content = sh.git.log(
'--oneline',
'--no-merges',
_tty_out=False
).split('\n')

git_log_content = replace_sha_with_commit_link(git_log_content)

log.debug('content: %s' % git_log_content)

# makes change log entries into bullet points
if git_log_content:
[
changelog_content.append('* %s\n' % line)
if line else line
for line in git_log_content[:-1]
]

write_new_changelog(
app_name,
config.CHANGELOG,
changelog_content,
dry_run=dry_run
)
log.info('Added content to CHANGELOG.md')
Loading

0 comments on commit 345ef53

Please sign in to comment.