Somewhat more efficient fix.

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.
This commit is contained in:
Tom Oinn 2021-06-04 20:51:02 +01:00 committed by Tom Oinn
parent 732a7d673d
commit 676983e177

View File

@ -305,19 +305,28 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
to_try.append((inventories.named_inventory[setname], full_qualified_name)) to_try.append((inventories.named_inventory[setname], full_qualified_name))
for inventory, target in to_try: for inventory, target in to_try:
for objtype in objtypes: for objtype in objtypes:
# Special case handling for term to search in a case insensitive fashion if objtype not in inventory:
if objtype == 'std:term' and objtype in inventory: # Continue if there's nothing of this kind in the inventory
cased_keys = {k.lower(): k for k in inventory[objtype].keys()} continue
if target.lower() in cased_keys: if target in inventory[objtype]:
corrected_target = cased_keys[target.lower()] # Case sensitive match, use it
proj, version, uri, dispname = inventory[objtype][corrected_target] 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: else:
# No case insensitive match either, continue to the next candidate
continue continue
else: else:
# Default behaviour pre-patch # Could reach here if we're not a term but have a case insensitive match.
if objtype not in inventory or target not in inventory[objtype]: # This is a fix for terms specifically, but potentially should apply to
continue # other types.
proj, version, uri, dispname = inventory[objtype][target] continue
if '://' not in uri and node.get('refdoc'): if '://' not in uri and node.get('refdoc'):
# get correct path in case of subdirectories # get correct path in case of subdirectories
uri = path.join(relative_path(node['refdoc'], '.'), uri) uri = path.join(relative_path(node['refdoc'], '.'), uri)