Fix RuntimeError with numbered circular toctree

This commit is contained in:
tk0miya 2014-08-19 10:44:09 +09:00
parent 60911efe05
commit 57cc7dfa05
2 changed files with 38 additions and 1 deletions

View File

@ -1444,6 +1444,7 @@ class BuildEnvironment:
# a list of all docnames whose section numbers changed # a list of all docnames whose section numbers changed
rewrite_needed = [] rewrite_needed = []
assigned = []
old_secnumbers = self.toc_secnumbers old_secnumbers = self.toc_secnumbers
self.toc_secnumbers = {} self.toc_secnumbers = {}
@ -1483,11 +1484,12 @@ class BuildEnvironment:
if depth == 0: if depth == 0:
return return
for (title, ref) in toctreenode['entries']: 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 # don't mess with those
continue continue
if ref in self.tocs: if ref in self.tocs:
secnums = self.toc_secnumbers[ref] = {} secnums = self.toc_secnumbers[ref] = {}
assigned.append(ref)
_walk_toc(self.tocs[ref], secnums, depth, _walk_toc(self.tocs[ref], secnums, depth,
self.titles.get(ref)) self.titles.get(ref))
if secnums != old_secnumbers.get(ref): if secnums != old_secnumbers.get(ref):

View File

@ -79,3 +79,38 @@ def test_nonascii_path():
app = TestApp(buildername=buildername, _copy_to_temp=True) app = TestApp(buildername=buildername, _copy_to_temp=True)
yield _test_nonascii_path, app yield _test_nonascii_path, app
app.cleanup() 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