-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure deterministic resolution of toctree #12888
base: master
Are you sure you want to change the base?
Conversation
afd81d9
to
ec51d9a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd have a test for this, but I'm not sure how easy it would be, so I don't mind as much not having one.
Please could you add an entry to CHANGES, though?
A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work guys!
This PR only resolves the issue of non-determinism, however users may still have their own expectations of what parent should be chosen which is not trivial to solve. I think we should warn the user when a document is included in multiple toctrees (different files). What do you think? Edit: I have added the warning in the recent commit but feel free to discard. |
bdeb4e0
to
909b161
Compare
5d40fc3
to
1b08b66
Compare
@@ -758,6 +758,7 @@ def check_consistency(self) -> None: | |||
continue | |||
logger.warning(__("document isn't included in any toctree"), | |||
location=docname) | |||
_check_toc_parents(self.toctree_includes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the consistency check here instead of doing it while resolution in _get_toctree_ancestors()
because _get_toctree_ancestors()
is being called multiple times for the same document while writing.
__("document is referenced in multiple toctrees: %s, " | ||
"selecting: %s <- %s"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably have to put translations for this (I'm not sure how).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along the lines of "correctness first, performance / etc second", I like this and would suggest that we merge it and gather feedback 👍
There are two thoughts I had while reviewing this:
- Whether tree depth might be better than lexicographic order as a sort key (@khanxmetu has also noted this as a possibility in an updated comment)
- A question really: it puzzles me slightly that we have nondeterminism here and not in the breadcrumb navigation trail (e.g.
System Emulation > QEMU System Emulator Targets > PowerPC System emulator > pSeries family boards (pseries) > ...
in the header of the referencedqemu
page). Does that component gather the navtree differently? (I should, and will eventually, check)
This seems a better approach than solely relying upon lexicographic order. However note that sorting and lexicographic order is still required to break the tie in case of equal path depths. Besides that, are you proposing for minimum or maximum path depth to be chosen?
Thank you for bringing this up. I found two important issues:
I propose that shortest depth path should be chosen. We can add a BFS traversal function similar to |
Thanks @khanxmetu, that makes sense that a tiebreaker will still be required if we use a path-depth approach. To answer whether I'm suggesting to include path-depth in the sorting: initially I say no, let's continue to use solely lexicographic sorting -- because whatever method we choose, I think some projects/pages will still emit sidebar navigation menus that seem unexpected to some people, because the origin of the ambiguity is in the source files. Even so, I think additional discussion of the navtree is worthwhile:
I wouldn't worry too much about ensuring that the navtree is always consistent with the sidebar toctree; as you've noticed in #12926, table-of-contents displays can be customized by themes and layout; my sense is that it could be difficult to get them to correspond precisely, and also that additional tree traversals might introduce unpredictable build performance changes (especially for large projects). To resolve the bug we can focus on making the build output stable (ensuring that it stays the same for two or more subsequent builds) - and your changeset here already does that. If it seems easy to re-use logic between |
Subject: Ensure deterministic toctree generation
Feature or Bugfix
Purpose
Detail
Relates