From caea578cd02a7cb2f7cfa453dfabff66e56aff8d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 30 Dec 2014 11:39:07 -0500 Subject: Moved linkify logic to documentation builder as Sphinx extension. --- docs/conf.py | 2 +- linkify.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ release.py | 40 ---------------------------------------- 3 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 linkify.py diff --git a/docs/conf.py b/docs/conf.py index 8be5c3dd..6cb8f636 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ import setup as setup_script # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = [] +extensions = ['linkify'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/linkify.py b/linkify.py new file mode 100644 index 00000000..1d925aba --- /dev/null +++ b/linkify.py @@ -0,0 +1,52 @@ +""" +Sphinx plugin to add links to the changelog. +""" + +import re +import os + + +link_patterns = [ + r"(Issue )?#(?P\d+)", + r"Pull Request ?#(?P\d+)", + r"Distribute #(?P\d+)", + r"Buildout #(?P\d+)", + r"Old Setuptools #(?P\d+)", + r"Jython #(?P\d+)", + r"Python #(?P\d+)", +] + +issue_urls = dict( + pull_request='https://bitbucket.org' + '/pypa/setuptools/pull-request/{pull_request}', + 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}', + python='http://bugs.python.org/issue{python}', +) + + +def _linkify(source, dest): + pattern = '|'.join(link_patterns) + with open(source) as source: + out = re.sub(pattern, replacer, source.read()) + with open(dest, 'w') as dest: + dest.write(out) + + +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) + +def setup(app): + _linkify('CHANGES.txt', 'CHANGES (links).txt') + app.connect('build-finished', remove_file) + +def remove_file(app, exception): + os.remove('CHANGES (links).txt') diff --git a/release.py b/release.py index d2f82775..d067930b 100644 --- a/release.py +++ b/release.py @@ -3,7 +3,6 @@ Setuptools is released using 'jaraco.packaging.release'. To make a release, install jaraco.packaging and run 'python -m jaraco.packaging.release' """ -import re import os import subprocess @@ -14,7 +13,6 @@ pkg_resources.require('wheel') def before_upload(): - _linkify('CHANGES.txt', 'CHANGES (links).txt') BootstrapBookmark.add() @@ -33,44 +31,6 @@ test_info = "Travis-CI tests: http://travis-ci.org/#!/jaraco/setuptools" os.environ["SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES"] = "1" -link_patterns = [ - r"(Issue )?#(?P\d+)", - r"Pull Request ?#(?P\d+)", - r"Distribute #(?P\d+)", - r"Buildout #(?P\d+)", - r"Old Setuptools #(?P\d+)", - r"Jython #(?P\d+)", - r"Python #(?P\d+)", -] - -issue_urls = dict( - pull_request='https://bitbucket.org' - '/pypa/setuptools/pull-request/{pull_request}', - 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}', - python='http://bugs.python.org/issue{python}', -) - - -def _linkify(source, dest): - pattern = '|'.join(link_patterns) - with open(source) as source: - out = re.sub(pattern, replacer, source.read()) - with open(dest, 'w') as dest: - dest.write(out) - - -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) - class BootstrapBookmark: name = 'bootstrap' -- cgit v1.2.1