From 57cc7dfa057a4a044a5df6e172a7fef7197b5334 Mon Sep 17 00:00:00 2001 From: tk0miya Date: Tue, 19 Aug 2014 10:44:09 +0900 Subject: [PATCH] Fix RuntimeError with numbered circular toctree --- sphinx/environment.py | 4 +++- tests/test_build.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/sphinx/environment.py b/sphinx/environment.py index 72f5d240e..9c197477b 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -1444,6 +1444,7 @@ class BuildEnvironment: # a list of all docnames whose section numbers changed rewrite_needed = [] + assigned = [] old_secnumbers = self.toc_secnumbers self.toc_secnumbers = {} @@ -1483,11 +1484,12 @@ 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.append(ref) _walk_toc(self.tocs[ref], secnums, depth, self.titles.get(ref)) if secnums != old_secnumbers.get(ref): diff --git a/tests/test_build.py b/tests/test_build.py index c8001271e..56fdf826b 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -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