[intersphinx] allow case-insensitive match of label-refs through intersphinx (#12033)

This commit is contained in:
Michael Goerz
2024-03-02 06:39:51 -05:00
committed by GitHub
parent 9a30ca7da1
commit 265ffeedbd
4 changed files with 17 additions and 2 deletions

View File

@@ -84,6 +84,8 @@ Bugs fixed
Patch by James Addison.
* #11962: Fix target resolution when using ``:paramtype:`` fields.
Patch by Bénédikt Tran.
* #12008: Fix case-sensitive lookup of ``std:label`` names in intersphinx inventory.
Patch by Michael Goerz.
Testing
-------

View File

@@ -334,8 +334,10 @@ def _resolve_reference_in_domain_by_target(
if target in inventory[objtype]:
# Case sensitive match, use it
data = inventory[objtype][target]
elif objtype == 'std:term':
# Check for potential case insensitive matches for terms only
elif objtype in {'std:label', 'std:term'}:
# Some types require case insensitive matches:
# * 'term': https://github.com/sphinx-doc/sphinx/issues/9291
# * 'label': https://github.com/sphinx-doc/sphinx/issues/12008
target_lower = target.lower()
insensitive_matches = list(filter(lambda k: k.lower() == target_lower,
inventory[objtype].keys()))

View File

@@ -236,6 +236,16 @@ def test_missing_reference_stddomain(tmp_path, app, status, warning):
rn = missing_reference(app, app.env, node, contnode)
assert rn.astext() == 'A TERM'
# label reference (normal)
node, contnode = fake_node('std', 'ref', 'The-Julia-Domain', 'The-Julia-Domain')
rn = missing_reference(app, app.env, node, contnode)
assert rn.astext() == 'The Julia Domain'
# label reference (case insensitive)
node, contnode = fake_node('std', 'ref', 'the-julia-domain', 'the-julia-domain')
rn = missing_reference(app, app.env, node, contnode)
assert rn.astext() == 'The Julia Domain'
@pytest.mark.sphinx('html', testroot='ext-intersphinx-cppdomain')
def test_missing_reference_cppdomain(tmp_path, app, status, warning):

View File

@@ -41,6 +41,7 @@ foo.bar js:class 1 index.html#foo.bar -
foo.bar.baz js:method 1 index.html#foo.bar.baz -
foo.bar.qux js:data 1 index.html#foo.bar.qux -
a term including:colon std:term -1 glossary.html#term-a-term-including-colon -
The-Julia-Domain std:label -1 write_inventory/#$ The Julia Domain
''')
inventory_v2_not_having_version = b'''\