Allow empty toctree in singlehtml builder

We noticed this issue with the 0.2.x release of snide/sphinx_rtd_theme. Because
we are calling toctree unconditionally, we notice a bug in the singlehtml
builder when the docs have an empty/nonexistant toctree. In this case,
`fix_refuris` as being passed `None`, which failed to traverse, throwing an
exception.

This conditionally fixes the refuris instead.
This commit is contained in:
Anthony Johnson 2017-03-05 13:16:37 -08:00
parent f8391ea487
commit 3390b7f499
No known key found for this signature in database
GPG Key ID: C5C79D82F922D604
4 changed files with 21 additions and 1 deletions

View File

@ -968,7 +968,8 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
if 'includehidden' not in kwds:
kwds['includehidden'] = False
toctree = self.env.get_toctree_for(docname, self, collapse, **kwds)
self.fix_refuris(toctree)
if toctree is not None:
self.fix_refuris(toctree)
return self.render_partial(toctree)['fragment']
def assemble_doctree(self):

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
master_doc = 'index'
html_theme = 'classic'
exclude_patterns = ['_build']

View File

@ -0,0 +1,4 @@
test-toctree-empty
==================
.. toctree::

View File

@ -26,3 +26,13 @@ def test_relations(app, status, warning):
assert app.builder.relations['qux/qux_1'] == ['qux/index', 'qux/index', 'qux/qux_2']
assert app.builder.relations['qux/qux_2'] == ['qux/index', 'qux/qux_1', None]
assert 'quux' not in app.builder.relations
@pytest.mark.sphinx('singlehtml', testroot='toctree-empty')
def test_singlehtml_toctree(app, status, warning):
docname = 'index'
app.builder.build_all()
try:
app.builder._get_local_toctree('index')
except AttributeError:
pytest.fail('Unexpected AttributeError in app.builder.fix_refuris')