Created
March 5, 2013 18:38
-
-
Save techtonik/5092917 to your computer and use it in GitHub Desktop.
Python - setup.py - auto link issues in reST files (such as CHANGES.rst)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# tested with BitBucket | |
TRACKER = 'http://bitbucket.org/tarek/distribute' | |
# return contents of reStructureText file with linked issue references | |
def _linkified(rstfile): | |
revision = re.compile(r'\b(issue\s*#?\d+)\b', re.M | re.I) | |
rstext = open(rstfile).read() | |
anchors = revision.findall(rstext) # ['Issue #43', ...] | |
anchors = sorted(set(anchors)) | |
rstext = revision.sub(r'`\1`_', rstext) | |
rstext += "\n" | |
for x in anchors: | |
issue = re.findall(r'\d+', x)[0] | |
rstext += '.. _`%s`: %s/issue/%s\n' % (x, TRACKER, issue) | |
rstext += "\n" | |
return rstext | |
print(_linkified('CHANGES.txt')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment