Skip to content

Commit

Permalink
Revert "Ensure deterministic resolution of toctree (sphinx-doc#12888)"
Browse files Browse the repository at this point in the history
This reverts commit 8351936.
  • Loading branch information
AA-Turner committed Oct 10, 2024
1 parent 607ea49 commit 559e092
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 104 deletions.
5 changes: 0 additions & 5 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ Bugs fixed
which always kept the cache for positive values, and always refreshed it for
negative ones.
Patch by Nico Madysa.
* #12888: Add a warning when document is included in multiple toctrees
and ensure deterministic resolution of global toctree in parallel builds
by choosing the lexicographically greatest parent document.
Patch by A. Rafey Khan


Testing
-------
Expand Down
3 changes: 0 additions & 3 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,6 @@ def write(
docnames.add(tocdocname)
docnames.add(self.config.root_doc)

# sort to ensure deterministic toctree generation
self.env.toctree_includes = dict(sorted(self.env.toctree_includes.items()))

with progress_message(__('preparing documents')):
self.prepare_writing(docnames)

Expand Down
25 changes: 0 additions & 25 deletions sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,6 @@ def check_consistency(self) -> None:
logger.warning(
__("document isn't included in any toctree"), location=docname
)
# Call _check_toc_parents here rather than in _get_toctree_ancestors()
# because that method is called multiple times per document and would
# lead to duplicate warnings.
_check_toc_parents(self.toctree_includes)

# call check-consistency for all extensions
self.domains._check_consistency()
Expand Down Expand Up @@ -821,24 +817,3 @@ def _traverse_toctree(
if sub_docname not in traversed:
yield sub_parent, sub_docname
traversed.add(sub_docname)


def _check_toc_parents(toctree_includes: dict[str, list[str]]) -> None:
toc_parents: dict[str, list[str]] = {}
for parent, children in toctree_includes.items():
for child in children:
toc_parents.setdefault(child, []).append(parent)

for doc, parents in sorted(toc_parents.items()):
if len(parents) > 1:
logger.info(
__(
'document is referenced in multiple toctrees: %s, selecting: %s <- %s'
),
parents,
max(parents),
doc,
location=doc,
type='toc',
subtype='multiple_toc_parents',
)
7 changes: 0 additions & 7 deletions tests/roots/test-toctree-multiple-parents/alpha.rst

This file was deleted.

7 changes: 0 additions & 7 deletions tests/roots/test-toctree-multiple-parents/bravo.rst

This file was deleted.

4 changes: 0 additions & 4 deletions tests/roots/test-toctree-multiple-parents/charlie.rst

This file was deleted.

1 change: 0 additions & 1 deletion tests/roots/test-toctree-multiple-parents/conf.py

This file was deleted.

7 changes: 0 additions & 7 deletions tests/roots/test-toctree-multiple-parents/delta.rst

This file was deleted.

8 changes: 0 additions & 8 deletions tests/roots/test-toctree-multiple-parents/index.rst

This file was deleted.

7 changes: 0 additions & 7 deletions tests/roots/test-toctree-multiple-parents/relation_graph.txt

This file was deleted.

8 changes: 0 additions & 8 deletions tests/test_builders/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ def test_numbered_circular_toctree(app):
) in warnings


@pytest.mark.sphinx('text', testroot='toctree-multiple-parents')
def test_multiple_parents_toctree(app):
app.build(force_all=True)
assert (
"document is referenced in multiple toctrees: ['bravo', 'delta'], selecting: delta <- charlie"
) in app.status.getvalue()


@pytest.mark.usefixtures('_http_teapot')
@pytest.mark.sphinx('dummy', testroot='images')
def test_image_glob(app):
Expand Down
22 changes: 0 additions & 22 deletions tests/test_builders/test_build_html_toctree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the HTML builder and check output against XPath."""

import re
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -64,24 +63,3 @@ def test_numbered_toctree(app):
def test_singlehtml_hyperlinks(app, cached_etree_parse, expect):
app.build()
check_xpath(cached_etree_parse(app.outdir / 'index.html'), 'index.html', *expect)


@pytest.mark.sphinx(
'html',
testroot='toctree-multiple-parents',
confoverrides={'html_theme': 'alabaster'},
)
def test_toctree_multiple_parents(app, cached_etree_parse):
# The lexicographically greatest parent of the document in global toctree
# should be chosen, regardless of the order in which files are read
with patch.object(app.builder, '_read_serial') as m:
# Read files in reversed order
_read_serial = type(app.builder)._read_serial
m.side_effect = lambda docnames: _read_serial(app.builder, docnames[::-1])
app.build()
# Check if charlie is a child of delta in charlie.html
xpath_delta_children = (
".//ul[@class='current']//a[@href='delta.html']/../ul/li//a"
)
etree = cached_etree_parse(app.outdir / 'charlie.html')
check_xpath(etree, 'charlie.html', xpath=xpath_delta_children, check='Charlie')

0 comments on commit 559e092

Please sign in to comment.