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

👌 Handle external references pointing to object types #12133

Merged
merged 15 commits into from
Mar 19, 2024

Conversation

chrisjsewell
Copy link
Member

This PR fixes the issue of objects.inv denoting object names, whilst the external role only allows for role names.

As an example, take the objects.inv for the sphinx documentation, which contains:

py:function
    compile                  : usage/domains/python.html#compile

A user might understandably expect that they could reference this using :external:py:function:`compile`, but actually this would currently error with:

WARNING: role for external cross-reference not found: py:function

this is because, function is the object type, yet external expects the related role name func 😒
It should not be necessary for the user to know about this distinction, and in fact all the documentation talks about object types, not role names: https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#explicitly-reference-external-objects

In this PR, we add logic, to first look if the name relates to a role name (as previously, to not be back-breaking) but, if not, then also look if the name relates to an object that has a known role and, if so, use that.

@chrisjsewell chrisjsewell changed the title 👌 Handle handle external references pointing to object types 👌 Handle external references pointing to object types Mar 18, 2024
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
tests/test_extensions/test_ext_intersphinx.py Show resolved Hide resolved
tests/test_extensions/test_ext_intersphinx.py Outdated Show resolved Hide resolved
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
chrisjsewell and others added 2 commits March 19, 2024 12:56
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz picnixz self-requested a review March 19, 2024 12:03
tests/test_extensions/test_ext_intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
chrisjsewell and others added 3 commits March 19, 2024 13:18
@chrisjsewell chrisjsewell merged commit 565d410 into sphinx-doc:master Mar 19, 2024
22 checks passed
@chrisjsewell chrisjsewell deleted the intersphinx branch March 19, 2024 12:42
chrisjsewell added a commit that referenced this pull request Mar 25, 2024
The key issue this commit seeks to address, is that existing tools / documentation often lead users to mistakenly use object types and not role names, a classic example being `function` not `func`

Previously, the warning message for using e.g. `` external:function`target` `` (with `py` as the default domain), would be:

```
WARNING: role for external cross-reference not found: function
```

This gives no information to the user on how to fix the issue, even though there is actually quite an easy fix

This commit adds logic to create more specific / helpful warning messages, e.g.

```
WARNING: role for external cross-reference not found in domains 'py', 'std': 'function' (perhaps you meant one of: 'py:func', 'py:obj')
```

This goes through the same original logic but, if the role is not found, it will look if the role name is actually an available object type on the domain(s), and then suggest its related roles.

This commit also reverts #12133, which provided a (silent) fallback to auto convert an object type to a role name.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
@AA-Turner AA-Turner added this to the 7.3.0 milestone Jul 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants