Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:term: referenced via intersphinx is case sensitive #9291

Closed
tomoinn opened this issue Jun 3, 2021 · 4 comments
Closed

:term: referenced via intersphinx is case sensitive #9291

tomoinn opened this issue Jun 3, 2021 · 4 comments

Comments

@tomoinn
Copy link
Contributor

tomoinn commented Jun 3, 2021

Describe the bug

When a doc website A contains a term in a glossary, that term can be referenced without case sensitivity applied. If, however, that term is referenced from a second doc build B, by adding an intersphinx reference to A, only exact cases match.

To Reproduce
Steps to reproduce the behavior:

Add the following intersphinx reference:

'oe': ('https://icebreakerone.github.io/open-energy-technical-docs/main/', None)

Then attempt to reference a term within the glossary from a second project, i.e.

:term:`data provider` - this fails
:term:`Data Provider` - this correctly references back into the external glossary

Expected behavior

References to terms in external projects linked through intersphinx resolve in the same way as those defined locally.

Your project

https://github.com/icebreakerone/open-energy-technical-docs contains source, https://icebreakerone.github.io/open-energy-technical-docs/main/index.html is the site containing the manifest from which I'm trying to import terms.

Environment info

Sphinx build run from linux, python 3.8.6, sphinx 4.0.2

@jhuitema
Copy link

jhuitema commented Jun 3, 2021

I've also just run into this. From my (non-exhaustive) testing, it looks like the case-insensitive intersphinx term linking stopped working with Sphinx v3. The term links work correctly in Sphinx 2.4.4 and under.

@AWhetter
Copy link
Contributor

AWhetter commented Jun 4, 2021

A git bisect indicates that this was an intentional change made in a5dadeb to address #7418.
It's documented that terms are now case sensitive, and this was a breaking change introduced for Sphinx v3.
There was a change made in 61f00bf (v3.0.2) to fall back to case insensitive matching and to raise a warning when this happens, but from testing it seems like this doesn't happen for matches against an intersphinx mapping.

@tomoinn
Copy link
Contributor Author

tomoinn commented Jun 4, 2021

Yup, it looks like the resolver for :term: isn't used when loading references from intersphinx? If anyone has better knowledge of how things are structured they'd probably have a better idea, but as far as I can tell the resolution in intersphinx is happening in

def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
and just doing a straight 'is X in Y' check

@tomoinn
Copy link
Contributor Author

tomoinn commented Jun 4, 2021

I've had a play patching intersphinx.py, adding the following within missing_reference(...) and it does what I need, in that it allows for case insensitive match of terms from intersphinx:

This is inside the loop on line 319 of the current version

            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]
                else:
                    continue
            else:
                if objtype not in inventory or target not in inventory[objtype]:
                    continue
                proj, version, uri, dispname = inventory[objtype][target]

tomoinn added a commit to tomoinn/sphinx that referenced this issue Jun 4, 2021
@tk0miya tk0miya added this to the 4.1.0 milestone Jun 6, 2021
@tk0miya tk0miya closed this as completed Jul 11, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants