summaryrefslogtreecommitdiff
path: root/release.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-07-13 21:51:15 -0400
committerJason R. Coombs <jaraco@jaraco.com>2013-07-13 21:51:15 -0400
commited2d346fc30360bd319bccab34b770ffa60ca4f1 (patch)
tree94e69730b57f84a8dde15427ea5043c24d90c654 /release.py
parent4c1da41c296e7a5ddb9882a545f9a05859ef21e5 (diff)
downloadpython-setuptools-bitbucket-ed2d346fc30360bd319bccab34b770ffa60ca4f1.tar.gz
Re-wrote link inference to now respect specific patterns and generate links to known issue trackers.
Diffstat (limited to 'release.py')
-rw-r--r--release.py75
1 files changed, 26 insertions, 49 deletions
diff --git a/release.py b/release.py
index 0e1a5397..5e99e74c 100644
--- a/release.py
+++ b/release.py
@@ -13,7 +13,7 @@ except AttributeError:
zip_longest = itertools.izip_longest
def before_upload():
- _linkify('CHANGES.txt', 'CHANGES (linked).txt')
+ _linkify('CHANGES.txt', 'CHANGES (links).txt')
files_with_versions = (
'ez_setup.py', 'setuptools/__init__.py',
@@ -23,56 +23,33 @@ test_info = "Travis-CI tests: http://travis-ci.org/#!/jaraco/setuptools"
os.environ["SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES"] = "1"
+link_patterns = [
+ r"(Issue )?#(?P<issue>\d+)",
+ r"Distribute #(?P<distribute>\d+)",
+ r"Buildout #(?P<buildout>\d+)",
+ r"Old Setuptools #(?P<old_setuptools>\d+)",
+ r"Jython #(?P<jython>\d+)",
+]
+
+issue_urls = dict(
+ issue='https://bitbucket.org/pypa/setuptools/issue/{issue}',
+ distribute='https://bitbucket.org/tarek/distribute/issue/{distribute}',
+ buildout='https://github.com/buildout/buildout/issues/{buildout}',
+ old_setuptools='http://bugs.python.org/setuptools/issue{old_setuptools}',
+ jython='http://bugs.jython.org/issue{jython}',
+)
+
def _linkify(source, dest):
+ pattern = '|'.join(link_patterns)
with open(source) as source:
- out = _linkified_text(source.read())
+ out = re.sub(pattern, replacer, source.read())
with open(dest, 'w') as dest:
dest.write(out)
-def _linkified(rst_path):
- "return contents of reStructureText file with linked issue references"
- rst_file = open(rst_path)
- rst_content = rst_file.read()
- rst_file.close()
-
- return _linkified_text(rst_content)
-
-def _linkified_text(rst_content):
- # 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 = zip_longest(
- linkified_parts,
- HREF_pattern.findall(rst_content),
- fillvalue='',
- )
- rst_content = ''.join(flatten(pairs))
-
- anchors = sorted(anchors)
-
- bitroot = 'https://bitbucket.org/tarek/distribute'
- rst_content += "\n"
- for x in anchors:
- issue = re.findall(r'\d+', x)[0]
- rst_content += '.. _`%s`: %s/issue/%s\n' % (x, bitroot, issue)
- rst_content += "\n"
- return rst_content
-
-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)
+def replacer(match):
+ text = match.group(0)
+ match_dict = match.groupdict()
+ for key in match_dict:
+ if match_dict[key]:
+ url = issue_urls[key].format(**match_dict)
+ return "`{text} <{url}>`_".format(text=text, url=url)