Skip to content

Commit

Permalink
Somewhat more efficient fix.
Browse files Browse the repository at this point in the history
Only looks for case insensitive match if there isn't a case sensitive one, and uses filter to build a list of case insensitive matches rather than building a dict.
  • Loading branch information
tomoinn committed Jun 4, 2021
1 parent 732a7d6 commit 676983e
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions sphinx/ext/intersphinx.py
Expand Up @@ -305,19 +305,28 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
to_try.append((inventories.named_inventory[setname], full_qualified_name))
for inventory, target in to_try:
for objtype in objtypes:
# Special case handling for term to search in a case insensitive fashion
if objtype == 'std:term' and objtype in inventory:
cased_keys = {k.lower(): k for k in inventory[objtype].keys()}
if target.lower() in cased_keys:
corrected_target = cased_keys[target.lower()]
proj, version, uri, dispname = inventory[objtype][corrected_target]
if objtype not in inventory:
# Continue if there's nothing of this kind in the inventory
continue
if target in inventory[objtype]:
# Case sensitive match, use it
proj, version, uri, dispname = inventory[objtype][target]
elif objtype == 'std:term':
# Check for potential case insensitive matches for terms only
target_lower = target.lower()
insensitive_matches = list(filter(lambda k: k.lower() == target_lower,
inventory[objtype].keys()))
if insensitive_matches:
proj, version, uri, dispname = inventory[objtype][insensitive_matches[0]]
else:
# No case insensitive match either, continue to the next candidate
continue
else:
# Default behaviour pre-patch
if objtype not in inventory or target not in inventory[objtype]:
continue
proj, version, uri, dispname = inventory[objtype][target]
# Could reach here if we're not a term but have a case insensitive match.
# This is a fix for terms specifically, but potentially should apply to
# other types.
continue

if '://' not in uri and node.get('refdoc'):
# get correct path in case of subdirectories
uri = path.join(relative_path(node['refdoc'], '.'), uri)
Expand Down

0 comments on commit 676983e

Please sign in to comment.