Skip to content

Commit

Permalink
Fuzzy matching to associate classes with URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshih committed Sep 27, 2022
1 parent 772d376 commit df1faf5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sphinx/ext/inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class E(B): pass
import pathlib
import re
from importlib import import_module
from operator import itemgetter
from typing import Any, Dict, Iterable, List, Optional, Tuple, cast

from docutils import nodes
Expand Down Expand Up @@ -299,9 +300,15 @@ def generate_dot(self, name: str, urls: Dict[str, str] = {},
for name, fullname, bases, tooltip in sorted(self.class_info):
# Write the node
this_node_attrs = n_attrs.copy()
if fullname in urls:
this_node_attrs['URL'] = '"%s"' % urls[fullname]
this_node_attrs['target'] = '"_top"'

# Fuzzy matching in case the reference is at a different level of the namespace
fullname_ends = itemgetter(0, -1)(fullname.split('.'))
for refname, url in urls.items():
if itemgetter(0, -1)(refname.split('.')) == fullname_ends:
this_node_attrs['URL'] = '"%s"' % url
this_node_attrs['target'] = '"_top"'
break

if tooltip:
this_node_attrs['tooltip'] = tooltip
res.append(' "%s" [%s];\n' %
Expand Down

0 comments on commit df1faf5

Please sign in to comment.