diff --git a/CHANGES b/CHANGES index 4cd8ac3d335..2291738cdff 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,9 @@ Bugs fixed * Fix regression in ``autodoc.Documenter.parse_name()``. * Fix regression in JSON serialisation. +* #11634: Fixed two more bugs in inheritance diagrams that resulted in + broken links. + Patch by Albert Shih. Release 7.2.2 (released Aug 17, 2023) ===================================== diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 00c9e0b4164..cfab47efead 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -235,10 +235,11 @@ def fix_svg_relative_paths(self: SphinxTranslator, filepath: str) -> None: # not a relative link continue - old_path = path.join(self.builder.outdir, url) + docdir = path.dirname(path.join(self.builder.outdir, self.builder.current_docname)) + old_path = path.join(docdir, url) new_path = path.relpath( old_path, - start=path.join(self.builder.outdir, self.builder.imgpath), + start=path.join(docdir, self.builder.imgpath), ) modified_url = urlunsplit((scheme, hostname, new_path, query, fragment)) diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index 838fe40bc74..24d147b50b0 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -34,6 +34,7 @@ class E(B): pass import hashlib import inspect import re +from os import path from collections.abc import Iterable, Sequence from importlib import import_module from typing import TYPE_CHECKING, Any, cast @@ -417,7 +418,7 @@ def html_visit_inheritance_diagram(self: HTML5Translator, node: inheritance_diag # Create a mapping from fully-qualified class names to URLs. graphviz_output_format = self.builder.env.config.graphviz_output_format.upper() - current_filename = self.builder.current_docname + self.builder.out_suffix + current_filename = path.basename(self.builder.current_docname + self.builder.out_suffix) urls = {} pending_xrefs = cast(Iterable[addnodes.pending_xref], node) for child in pending_xrefs: diff --git a/tests/roots/test-ext-inheritance_diagram/subdir/index.rst b/tests/roots/test-ext-inheritance_diagram/subdir/index.rst index bfd4aa88a2d..a3b79730eb7 100644 --- a/tests/roots/test-ext-inheritance_diagram/subdir/index.rst +++ b/tests/roots/test-ext-inheritance_diagram/subdir/index.rst @@ -4,4 +4,6 @@ test-ext-inheritance_diagram subdirectory .. inheritance-diagram:: test.DocMainLevel +.. inheritance-diagram:: test.DocLowerLevel + .. py:class:: test.DocLowerLevel