Skip to content

Commit

Permalink
Merge pull request astropy/astropy-helpers#1 from embray/master
Browse files Browse the repository at this point in the history
Initial implementation of astropy_helpers
  • Loading branch information
embray committed May 16, 2014
2 parents 55a87ad + 92b6d90 commit f269190
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 51 deletions.
26 changes: 15 additions & 11 deletions sphinx_astropy/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------------
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -183,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.
Expand Down
83 changes: 43 additions & 40 deletions sphinx_astropy/ext/changelog_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f269190

Please sign in to comment.