Background
I'm designing a Sphinx extension called sphinx-uml that tries to improve sphinx-pyreverse. The goal is to output a navigable UML diagram (when you click a class/method/function, you go to the right documentation page).
Problem
In a Sphinx extension, how to resolve the URL of an arbitrary class/method/function (programmatically, during the build process)?
Attempts
Currently, I have a naive heuristic to rebuild those URLs, assuming that any class/method is documented by in the HTML build directory populated by Sphinx. It allows to craft such SVG diagrams (see here). Currently, I use this link when crafting the Graphviz node but this has the following limitations:
- classes that do not belong to the package get a (invalid) link (they should be resolved using
graphviz.ext.intersphinxor not resolved), - this heuristic depends on the naming conventions adopted by
sphinx-build.
I know that graphviz.ext.inheritance_diagram can link its graphviz vertices to the right documentation using pending xrefs, but I don't understand how it works and how to leverage it in my own code.
I guess that graphviz.ext.intersphinx uses similar mechanisms to use the right link.
.rstthesphinx-apidoctool wouldn't merge changes on subsequent runs) and unless you customize the templates the file/anchor structure you'd get would be fixed.conf.pyhacking, when you ask: "How to determine, in a Sphinx extension, how to resolve the URL of an arbitrary class/method/function?" that's a complex question! Somewhere in extending Sphinx you should find a link to the event handlers that can be used to determine the URL/anchor of the object being documented. Anyway, I do by hand what you're proposing to automate, the main drawback being that it needs to be maintained manually but since graphviz's automatic layout isn't to my satisfaction it's a middle grounddoc.rst#fully.qualified.name. Notice that thedoc.rstpart is supposed to be arbitrated by the documentation author, with the anchor being fixed. So your question is simply: how to get the URL programmatically during the build process?graphviz.ext.inheritance_diagramseems to do so for class names but I don't understand how it works and how to adapt/extend it to my case.