diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-05 09:36:55 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-05 09:36:55 -0400 |
commit | b78ecd63d5c206a5cd0b065656a4493ffe496fe5 (patch) | |
tree | 7876224450cb989aa39fca9fa825f63c2810612e /setup.py | |
parent | a0f5752e58db3a0eaaa68b22f0b1f878e824a117 (diff) | |
download | external_python_setuptools-b78ecd63d5c206a5cd0b065656a4493ffe496fe5.tar.gz external_python_setuptools-b78ecd63d5c206a5cd0b065656a4493ffe496fe5.tar.bz2 external_python_setuptools-b78ecd63d5c206a5cd0b065656a4493ffe496fe5.zip |
Fix linkification of CHANGES.txt (broken due to buildout issue reference)
--HG--
branch : distribute
extra : rebase_source : a331dda293481f2cf121956070f94bfe6c9e0a0c
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -142,12 +142,24 @@ def _linkified(rst_path): return _linkified_text(rst_content) def _linkified_text(rst_content): - bitroot = 'http://bitbucket.org/tarek/distribute' - revision = re.compile(r'\b(issue\s+#?\d+)\b', re.M | re.I) + # first identify any existing HREFs so they're not changed + HREF_pattern = re.compile('`.*?`_', re.MULTILINE | re.DOTALL) + + # split on the HREF pattern, returning the parts to be linkified + plain_text_parts = HREF_pattern.split(rst_content) + anchors = [] + linkified_parts = [_linkified_part(part, anchors) + for part in plain_text_parts] + pairs = itertools.izip_longest( + linkified_parts, + HREF_pattern.findall(rst_content), + fillvalue='', + ) + rst_content = ''.join(flatten(pairs)) + + anchors = sorted(anchors) - anchors = revision.findall(rst_content) # ['Issue #43', ...] - anchors = sorted(set(anchors)) - rst_content = revision.sub(r'`\1`_', rst_content) + bitroot = 'http://bitbucket.org/tarek/distribute' rst_content += "\n" for x in anchors: issue = re.findall(r'\d+', x)[0] @@ -155,6 +167,21 @@ def _linkified_text(rst_content): rst_content += "\n" return rst_content +import itertools +def flatten(listOfLists): + "Flatten one level of nesting" + return itertools.chain.from_iterable(listOfLists) + + +def _linkified_part(text, anchors): + """ + Linkify a part and collect any anchors generated + """ + revision = re.compile(r'\b(issue\s+#?\d+)\b', re.M | re.I) + + anchors.extend(revision.findall(text)) # ['Issue #43', ...] + return revision.sub(r'`\1`_', text) + readme_file = open('README.txt') long_description = readme_file.read() + _linkified('CHANGES.txt') readme_file.close() |