From 080261c6990d06c4b4bd2ac91207e0bc2d6c2153 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Tue, 25 Mar 2014 18:27:41 -0400 Subject: [PATCH 1/2] Initial import of astropy.sphinx into astropy_helpers.sphinx--mostly the same except for a few small tweaks to get it working under the name 'astropy_helpers' --- sphinx_astropy/conf.py | 21 +++---- sphinx_astropy/ext/changelog_links.py | 83 ++++++++++++++------------- 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/sphinx_astropy/conf.py b/sphinx_astropy/conf.py index 48db1e7..5bcb91c 100644 --- a/sphinx_astropy/conf.py +++ b/sphinx_astropy/conf.py @@ -9,12 +9,13 @@ # All configuration values have a default; values that are commented out # serve to show the default. +import re import warnings + from os import path from distutils.version import LooseVersion -import re -from ..utils.compat import subprocess +from ..compat import subprocess # -- General configuration ---------------------------------------------------- @@ -127,14 +128,14 @@ def get_graphviz_version(): 'sphinx.ext.coverage', 'sphinx.ext.pngmath', 'sphinx.ext.inheritance_diagram', - 'astropy.sphinx.ext.numpydoc', - 'astropy.sphinx.ext.astropyautosummary', - 'astropy.sphinx.ext.automodsumm', - 'astropy.sphinx.ext.automodapi', - 'astropy.sphinx.ext.tocdepthfix', - 'astropy.sphinx.ext.doctest', - 'astropy.sphinx.ext.changelog_links', - 'astropy.sphinx.ext.viewcode' # Use patched version of viewcode + 'astropy_helpers.sphinx.ext.numpydoc', + 'astropy_helpers.sphinx.ext.astropyautosummary', + 'astropy_helpers.sphinx.ext.automodsumm', + 'astropy_helpers.sphinx.ext.automodapi', + 'astropy_helpers.sphinx.ext.tocdepthfix', + 'astropy_helpers.sphinx.ext.doctest', + 'astropy_helpers.sphinx.ext.changelog_links', + 'astropy_helpers.sphinx.ext.viewcode' # Use patched version of viewcode ] # Above, we use a patched version of viewcode rather than 'sphinx.ext.viewcode' diff --git a/sphinx_astropy/ext/changelog_links.py b/sphinx_astropy/ext/changelog_links.py index c928bba..4408547 100644 --- a/sphinx_astropy/ext/changelog_links.py +++ b/sphinx_astropy/ext/changelog_links.py @@ -16,46 +16,49 @@ def process_changelog_links(app, doctree, docname): - if 'changelog' in docname and app.config.github_issues_url is not None: - - for item in doctree.traverse(): - - if isinstance(item, Text): - - # We build a new list of items to replace the current item. If - # a link is found, we need to use a 'reference' item. - children = [] - - # First cycle through blocks of issues (delimited by []) then - # iterate inside each one to find the individual issues. - prev_block_end = 0 - for block in BLOCK_PATTERN.finditer(item): - block_start, block_end = block.start(), block.end() - children.append(Text(item[prev_block_end:block_start])) - block = item[block_start:block_end] - prev_end = 0 - for m in ISSUE_PATTERN.finditer(block): - start, end = m.start(), m.end() - children.append(Text(block[prev_end:start])) - issue_number = block[start:end] - children.append(reference(text=issue_number, - name=issue_number, - refuri=app.config.github_issues_url + issue_number[1:])) - prev_end = end - - prev_block_end = block_end - - # If no issues were found, this adds the whole item, - # otherwise it adds the remaining text. - children.append(Text(block[prev_end:block_end])) - - # If no blocks were found, this adds the whole item, otherwise - # it adds the remaining text. - children.append(Text(item[prev_block_end:])) - - # Replace item by the new list of items we have generated, - # which may contain links. - item.parent.replace(item, children) + if 'changelog' not in docname or app.config.github_issues_url is None: + return + + for item in doctree.traverse(): + + if not isinstance(item, Text): + continue + + # We build a new list of items to replace the current item. If + # a link is found, we need to use a 'reference' item. + children = [] + + # First cycle through blocks of issues (delimited by []) then + # iterate inside each one to find the individual issues. + prev_block_end = 0 + for block in BLOCK_PATTERN.finditer(item): + block_start, block_end = block.start(), block.end() + children.append(Text(item[prev_block_end:block_start])) + block = item[block_start:block_end] + prev_end = 0 + for m in ISSUE_PATTERN.finditer(block): + start, end = m.start(), m.end() + children.append(Text(block[prev_end:start])) + issue_number = block[start:end] + refuri = app.config.github_issues_url + issue_number[1:] + children.append(reference(text=issue_number, + name=issue_number, + refuri=refuri)) + prev_end = end + + prev_block_end = block_end + + # If no issues were found, this adds the whole item, + # otherwise it adds the remaining text. + children.append(Text(block[prev_end:block_end])) + + # If no blocks were found, this adds the whole item, otherwise + # it adds the remaining text. + children.append(Text(item[prev_block_end:])) + + # Replace item by the new list of items we have generated, + # which may contain links. + item.parent.replace(item, children) def setup(app): From 92b6d90e24601355e3c4616bb6a42c77ce1eea2e Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Wed, 26 Mar 2014 12:50:44 -0400 Subject: [PATCH 2/2] For some reason I got complaints that the favicon couldn't be found when I first ran the docs. Not sure why this hasn't come up before, and it seems suspect. But this seems to fix it. --- sphinx_astropy/conf.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sphinx_astropy/conf.py b/sphinx_astropy/conf.py index 5bcb91c..9210fb0 100644 --- a/sphinx_astropy/conf.py +++ b/sphinx_astropy/conf.py @@ -184,7 +184,10 @@ def get_graphviz_version(): # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -html_favicon = 'astropy_logo.ico' # included in the bootstrap-astropy theme + +# included in the bootstrap-astropy theme +html_favicon = path.join(html_theme_path[0], html_theme, 'static', + 'astropy_logo.ico') # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format.