Merged in tk0miya/sphinx (pull request #273)

Fix RuntimeError with numbered circular toctree. Closes #1536
This commit is contained in:
Takayuki Shimizukawa 2014-08-20 06:01:27 +09:00
commit a2a39cefe8
2 changed files with 39 additions and 1 deletions

View File

@ -1444,6 +1444,7 @@ class BuildEnvironment:
# a list of all docnames whose section numbers changed
rewrite_needed = []
assigned = set()
old_secnumbers = self.toc_secnumbers
self.toc_secnumbers = {}
@ -1483,17 +1484,19 @@ class BuildEnvironment:
if depth == 0:
return
for (title, ref) in toctreenode['entries']:
if url_re.match(ref) or ref == 'self':
if url_re.match(ref) or ref == 'self' or ref in assigned:
# don't mess with those
continue
if ref in self.tocs:
secnums = self.toc_secnumbers[ref] = {}
assigned.add(ref)
_walk_toc(self.tocs[ref], secnums, depth,
self.titles.get(ref))
if secnums != old_secnumbers.get(ref):
rewrite_needed.append(ref)
for docname in self.numbered_toctrees:
assigned.add(docname)
doctree = self.get_doctree(docname)
for toctreenode in doctree.traverse(addnodes.toctree):
depth = toctreenode.get('numbered', 0)

View File

@ -79,3 +79,38 @@ def test_nonascii_path():
app = TestApp(buildername=buildername, _copy_to_temp=True)
yield _test_nonascii_path, app
app.cleanup()
@with_app(buildername='text', srcdir='(empty)')
def test_circular_toctree(app):
contents = (".. toctree::\n"
"\n"
" sub\n")
(app.srcdir / 'contents.rst').write_text(contents, encoding='utf-8')
contents = (".. toctree::\n"
"\n"
" contents\n")
(app.srcdir / 'sub.rst').write_text(contents, encoding='utf-8')
app.builder.build_all()
warnings = "".join(app._warning.content)
assert 'circular toctree references detected, ignoring: sub <- contents <- sub' in warnings
assert 'circular toctree references detected, ignoring: contents <- sub <- contents' in warnings
@with_app(buildername='text', srcdir='(empty)')
def test_numbered_circular_toctree(app):
contents = (".. toctree::\n"
" :numbered:\n"
"\n"
" sub\n")
(app.srcdir / 'contents.rst').write_text(contents, encoding='utf-8')
contents = (".. toctree::\n"
"\n"
" contents\n")
(app.srcdir / 'sub.rst').write_text(contents, encoding='utf-8')
app.builder.build_all()
warnings = "\n".join(app._warning.content)
assert 'circular toctree references detected, ignoring: sub <- contents <- sub' in warnings
assert 'circular toctree references detected, ignoring: contents <- sub <- contents' in warnings