From d641927ad865ff5e627f750ad03cffd295d94d51 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 6 May 2014 15:57:04 -0700 Subject: [PATCH 1/3] Fix formatted.get calls --- beets/ui/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 00b217850..e798fed2d 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -576,8 +576,8 @@ def _field_diff(field, old, new): return None # Get formatted values for output. - oldstr = old.formatted.get(field, u'') - newstr = new.formatted.get(field, u'') + oldstr = old.formatted.get(field) or u'' + newstr = new.formatted.get(field) or u'' # For strings, highlight changes. For others, colorize the whole # thing. From 611be7b4b5dcfad406fc54a05cc2226ffe81b24d Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 6 May 2014 22:06:28 -0700 Subject: [PATCH 2/3] Release script: convert changelog to Markdown --- extra/release.py | 55 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/extra/release.py b/extra/release.py index 3efbe3d3a..c8fe7f50c 100644 --- a/extra/release.py +++ b/extra/release.py @@ -61,6 +61,7 @@ VERSION_LOCS = [ ), ] + @release.command() @click.argument('version') def bump(version): @@ -85,7 +86,9 @@ def bump(version): old_version = match.group(1) old_parts = [int(p) for p in old_version.split('.')] assert version_parts > old_parts, \ - "version must be newer than {}".format(old_version) + "version must be newer than {}".format( + old_version + ) # Insert the new version. out_lines.append(template.format( @@ -95,7 +98,7 @@ def bump(version): ) + '\n') break - + else: # Normal line. out_lines.append(line) @@ -103,7 +106,7 @@ def bump(version): # Write the file back. with open(filename, 'w') as f: f.write(''.join(out_lines)) - + # Generate bits to insert into changelog. header_line = '{} (in development)'.format(version) header = '\n\n' + header_line + '\n' + '-' * len(header_line) + '\n\n' @@ -128,11 +131,9 @@ def build(): subprocess.check_call(['python2', 'setup.py', 'sdist']) -@release.command() -def changelog(): - """Translate the most recent version's changelog to Markdown using Pandoc. +def get_latest_changelog(): + """Extract the first section of the changelog. """ - # Extract the first section of the changelog. started = False lines = [] with open(CHANGELOG) as f: @@ -149,9 +150,45 @@ def changelog(): elif started: lines.append(line) - changelog = ''.join(lines).strip() + return ''.join(lines).strip() - print(changelog) + +def rst2md(text): + """Use Pandoc to convert text from ReST to Markdown. + """ + pandoc = subprocess.Popen( + ['pandoc', '--from=rst', '--to=markdown', '--no-wrap'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + stdout, _ = pandoc.communicate(text.encode('utf8')) + md = stdout.decode('utf8').strip() + + # Fix up odd spacing in lists. + return re.sub(r'^- ', '- ', md, flags=re.M) + + +def changelog_as_markdown(): + """Get the latest changelog entry as hacked up Markdown. + """ + rst = get_latest_changelog() + + # Replace plugin links with plugin names. + rst = re.sub(r':doc:`/plugins/(\w+)`', r'``\1``', rst) + + # References with text. + rst = re.sub(r':ref:`([^<]+)(<[^>]+>)`', r'\1', rst) + + # Other backslashes with verbatim ranges. + rst = re.sub(r'(\s)`([^`]+)`([^_])', r'\1``\2``\3', rst) + + return rst2md(rst) + + +@release.command() +def changelog(): + """Get the most recent version's changelog as Markdown. + """ + print(changelog_as_markdown()) if __name__ == '__main__': From 6ecf4ef6edf2bc1671083cb4a9c3159f1905d1e4 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 6 May 2014 22:16:19 -0700 Subject: [PATCH 3/3] Release script: upload command --- extra/release.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extra/release.py b/extra/release.py index c8fe7f50c..bf62127f4 100644 --- a/extra/release.py +++ b/extra/release.py @@ -191,5 +191,14 @@ def changelog(): print(changelog_as_markdown()) +@release.command() +@click.argument('version') +def upload(version): + """Upload the release to PyPI. + """ + path = os.path.join(BASE, 'dist', 'beets-{}.tar.gz') + subprocess.check_call(['twine', 'upload', path]) + + if __name__ == '__main__': release()