Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganisation #45

Merged
merged 31 commits into from
Oct 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b797fdc
Add config module
michaeljoseph Oct 18, 2013
12a975e
Alias config.arguments and setup from docopt
michaeljoseph Oct 18, 2013
091f0b0
Refactor changelog
michaeljoseph Oct 18, 2013
e3121c8
Cleanup and linting
michaeljoseph Oct 18, 2013
3243197
Correct english
michaeljoseph Oct 18, 2013
ea1454e
Move and generalise `extract_version_arguments`
michaeljoseph Oct 18, 2013
91d24f6
Test config
michaeljoseph Oct 18, 2013
9fae7a5
Refactor vcs functions
michaeljoseph Oct 18, 2013
6275e71
Refactor testing module
michaeljoseph Oct 18, 2013
de3b939
Improve attributes coverage
michaeljoseph Oct 18, 2013
de1741d
Renamed run_tests command
michaeljoseph Oct 18, 2013
bd9beae
Refactor packaging module
michaeljoseph Oct 18, 2013
17d5f9f
Refactor bump_version
michaeljoseph Oct 18, 2013
95d424d
Cleanup
michaeljoseph Oct 18, 2013
0e0505b
Use subshell to avoid changing directories
michaeljoseph Oct 23, 2013
7d27e37
Wrap sh calls to check for dry_run
michaeljoseph Oct 23, 2013
cf36094
Rename testing to verification
michaeljoseph Oct 24, 2013
9abb0ca
Port attributes to sh
michaeljoseph Oct 24, 2013
95c6b71
Port changelog to sh
michaeljoseph Oct 24, 2013
ab8bd20
iterpipes => sh
michaeljoseph Oct 24, 2013
5b20588
Migrate vcs to sh
michaeljoseph Oct 24, 2013
0d45807
Migrate probe to sh
michaeljoseph Oct 24, 2013
182fb0a
Fix versioning
michaeljoseph Oct 24, 2013
e22b2d5
Port packaging to sh
michaeljoseph Oct 24, 2013
756cd63
Add subprocess execution for testing installation in a virtualenv
michaeljoseph Oct 24, 2013
7561d38
Dry runs
michaeljoseph Oct 24, 2013
ea3b6d2
Merge pull request #46 from michaeljoseph/replace-iterpipes-with-sh
michaeljoseph Oct 24, 2013
e2e97d1
Linting
michaeljoseph Oct 24, 2013
2426764
abc
michaeljoseph Oct 24, 2013
79361ee
Add noinput option
michaeljoseph Oct 24, 2013
d958a9f
Stop defaulting patch to true
michaeljoseph Oct 25, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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