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

Improve external role warnings (and revert object fallback) #12193

Merged
merged 14 commits into from
Mar 25, 2024

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Mar 23, 2024

Ok @jakobandersen @picnixz, this is compromise for discussion in https://github.com/orgs/sphinx-doc/discussions/12152 😄

The key issue this 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

In #12133, I handled this by falling back to looking for the object type, then obtaining a role from that.
There has been some push back on this fallback 😬

So, in this PR, I revert that, but instead, create much 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.


Note, in doing this, I've removed some methods of IntersphinxRole because they are just not useful any more. (added back and deprecated)

@chrisjsewell chrisjsewell changed the title 👌 Make external role warnings more helpful (revert object fallback) 👌 Improve external role warnings (and revert object fallback) Mar 23, 2024
@picnixz
Copy link
Member

picnixz commented Mar 23, 2024

I do like the suggestion approach. It doesn't implicitly choose but rather suggest so I think it's a good approach. Now, I would go even further by suggesting the one of close Levenshtein distance.

Note, in doing this, I've removed some methods of IntersphinxRole because they are just not useful any more.

Let's keep it backward compatible as much as possible. So keep the methods but make them deprecated.

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
Copy link
Member Author

Let's keep it backward compatible as much as possible. So keep the methods but make them deprecated.

done

@chrisjsewell
Copy link
Member Author

chrisjsewell commented Mar 24, 2024

now, I would go even further by suggesting the one of close Levenshtein distance.

good idea, but can I delay this to another PR, it seems a bit more "involved" 😅

@picnixz
Copy link
Member

picnixz commented Mar 24, 2024

good idea, but can I delay this to another PR, it seems a bit more "involved" 😅

We can open an issue for that.

@chrisjsewell
Copy link
Member Author

We can open an issue for that.

yeh I could certainly see this also being applicable to other areas of reference resolution 😄

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
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
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 24, 2024 02:20
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the final nitpicks I can think of. Otherwise it's good for me. I'd be happy to work on the suggestion logic if you don't want to btw.

sphinx/ext/intersphinx.py Show resolved Hide resolved
sphinx/ext/intersphinx.py Outdated Show resolved Hide resolved
sphinx/ext/intersphinx.py Show resolved Hide resolved
@jakobandersen
Copy link
Contributor

I like this solution, it keeps the core logic strict while helping users. Could the functionality be applied to role lookup in general? E.g., if you write :external:function: or just :function: it would do the same thing?

@chrisjsewell
Copy link
Member Author

I like this solution, it keeps the core logic strict while helping users.

great 😄

Could the functionality be applied to role lookup in general? E.g., if you write :external:function: or just :function: it would do the same thing?

good idea, but if you don't mind, I would delay that to a separate PR

@jakobandersen
Copy link
Contributor

good idea, but if you don't mind, I would delay that to a separate PR

Sure, though perhaps it could already be moved to another file as preparation?

@chrisjsewell
Copy link
Member Author

Sure, though perhaps it could already be moved to another file as preparation?

😬 I'd prefer to keep this PR "self-encapsulated", and not prematurely generalise (and get in to questions about what the file would be etc).
The code in this PR does not introduce any new public API, so I feel there will be no problem in a future PR if the code needs to be moved

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@chrisjsewell
Copy link
Member Author

@picnixz since you marked your recent comments as resolved, I assume these are ok now?

@picnixz
Copy link
Member

picnixz commented Mar 25, 2024

@chrisjsewell Bit of unrelated, but in general:

  • do you prefer that I review bit by bit, possibly addressing different points in different reviews or everything in one go?
  • do you prefer that I let you update your branches if I push on master or can I press the "update branch" button if there are no conflicts? (I will not solve conflicts myself since you might have local changes not yet committed).

@chrisjsewell
Copy link
Member Author

Bit of unrelated, but in general:

thanks for asking @picnixz

do you prefer that I review bit by bit, possibly addressing different points in different reviews or everything in one go?

I guess whatever you have time for in the moment;
if you only have time for a quick partial review, thats fine and its good to get early feedback (at least whether you think the PR is a good idea in principle),
but maybe just mention that there will probably be more to come

do you prefer that I let you update your branches if I push on master or can I press the "update branch" button if there are no conflicts? (I will not solve conflicts myself since you might have local changes not yet committed).

yeh this is fine, feel free to press the update

Also, if you have any requests for me, feel free to say 😄

@chrisjsewell chrisjsewell merged commit 04bd0df into sphinx-doc:master Mar 25, 2024
22 checks passed
@chrisjsewell chrisjsewell deleted the external-suggest-roles branch March 25, 2024 13:39
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2024
@AA-Turner AA-Turner added this to the 7.3.0 milestone Jul 13, 2024
@AA-Turner
Copy link
Member

@chrisjsewell I've just noticed this PR added several new deprecations but didn't document them as deprecated -- please could you resolve?

A

@AA-Turner AA-Turner changed the title 👌 Improve external role warnings (and revert object fallback) Improve external role warnings (and revert object fallback) Jul 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants