intersphinx: Don't warn about pure-duplicate ambiguous definitions when loading inventory entries (#12586)

This commit is contained in:
James Addison
2024-07-15 18:37:46 +01:00
committed by GitHub
parent afaddd3c45
commit cfd3645eb7
3 changed files with 15 additions and 5 deletions

View File

@@ -126,7 +126,8 @@ class InventoryFile:
invdata: Inventory = {}
projname = stream.readline().rstrip()[11:]
version = stream.readline().rstrip()[11:]
potential_ambiguities = set()
# definition -> priority, location, display name
potential_ambiguities: dict[str, tuple[str, str, str]] = {}
actual_ambiguities = set()
line = stream.readline()
if 'zlib' not in line:
@@ -155,10 +156,16 @@ class InventoryFile:
# * 'term': https://github.com/sphinx-doc/sphinx/issues/9291
# * 'label': https://github.com/sphinx-doc/sphinx/issues/12008
definition = f"{type}:{name}"
if definition.lower() in potential_ambiguities:
actual_ambiguities.add(definition)
content = prio, location, dispname
lowercase_definition = definition.lower()
if lowercase_definition in potential_ambiguities:
if potential_ambiguities[lowercase_definition] != content:
actual_ambiguities.add(definition)
else:
logger.debug(__("inventory <%s> contains duplicate definitions of %s"),
uri, definition, type='intersphinx', subtype='external')
else:
potential_ambiguities.add(definition.lower())
potential_ambiguities[lowercase_definition] = content
if location.endswith('$'):
location = location[:-1] + name
location = join(uri, location)

View File

@@ -59,4 +59,6 @@ INVENTORY_V2_AMBIGUOUS_TERMS: Final[bytes] = b'''\
''' + zlib.compress(b'''\
a term std:term -1 glossary.html#term-a-term -
A term std:term -1 glossary.html#term-a-term -
b term std:term -1 document.html#id5 -
B term std:term -1 document.html#B -
''')

View File

@@ -53,7 +53,8 @@ def test_ambiguous_definition_warning(warning):
f = BytesIO(INVENTORY_V2_AMBIGUOUS_TERMS)
InventoryFile.load(f, '/util', posixpath.join)
assert 'contains multiple definitions for std:term:a' in warning.getvalue().lower()
assert 'contains multiple definitions for std:term:a' not in warning.getvalue().lower()
assert 'contains multiple definitions for std:term:b' in warning.getvalue().lower()
def _write_appconfig(dir, language, prefix=None):