Skip to content

Instantly share code, notes, and snippets.

@techtonik
Created March 5, 2013 18:38
Show Gist options
  • Save techtonik/5092917 to your computer and use it in GitHub Desktop.
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)
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