-
Notifications
You must be signed in to change notification settings - Fork 41
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
Update compatibility of setup_intersphinx module name check with Sphinx-7.4 #302
Update compatibility of setup_intersphinx module name check with Sphinx-7.4 #302
Conversation
…for module names prefix rather than full names Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Thanks a lot for letting us know about this and opening a PR for it. Would you mind adding a test case for this? |
It seems we are not testing for Sphinx 7.4, and that's probably we haven't found this issue. We should update the list from Line 7 in 80252c3
|
Thanks @humitos ! Will have a look at the test side this week |
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Hi @humitos, I've addressed the test and tox points; please let me know your thoughts when you or the team have a chance 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this PR. It's moving forward in a good direction. I requested some changes, but they are minor.
hoverxref/extension.py
Outdated
@@ -174,7 +174,7 @@ def setup_intersphinx(app, config): | |||
|
|||
for listener in app.events.listeners.get('missing-reference'): | |||
module_name = inspect.getmodule(listener.handler).__name__ | |||
if module_name == 'sphinx.ext.intersphinx': | |||
if module_name.startswith('sphinx.ext.intersphinx'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the module_name
is called sphinx.ext.intersphinx._resolve
. Would it be better to be pretty explicit here to avoid disconnecting things we are not expecting to disconnect?
if module_name.startswith('sphinx.ext.intersphinx'): | |
if module_name == 'sphinx.ext.intersphinx._resolve': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explicit name check would be compatible only with Sphinx-7.4+.
We could check explicitly for _resolve
first, then the old name as a fallback for backwards compatibility, or according to the Sphinx version. What do you think?
Initially I was moving towards not having a private module in the name check but what you highlight regarding risk of other listeners being disconnected is true, so happy to make the update!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Yeah, I think it's better to check for the Sphinx version and use one name or the other depending on that 👍🏼
tests/test_internals.py
Outdated
listeners = [] | ||
for listener in app.events.listeners.get('missing-reference'): | ||
module_name = inspect.getmodule(listener.handler).__name__ | ||
if module_name.startswith('sphinx.ext.intersphinx'): | ||
listeners.append((module_name, listener)) | ||
assert not listeners, f"Expected to find zero listeners but found: {listeners}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't copy the exact code we want to test in the test itself. We should instead test the original function for missing-reference
is not present in app.events.listener
and the correct one is present.
Pseudo-code for the test:
from sphinx.ext.intersphinx._resolve import missing_reference as intersphinx_missing_reference
from hoverxref.extension import missing_reference
app.build()
assert EventListener(id=Mock.ANY, priority=Mock.ANY, handler=intersphinx_missing_reference) not in app.events.listeners
assert EventListener(id=Mock.ANY, priority=Mock.ANY, handler=missing_reference) in app.events.listeners
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
…n 7.4+ Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Hi @humitos, while working on improving the test I realized that
which led me to update the implementation of setup_intersphinx to avoid version checking while guaranteeing the intersphinx listener handler we care about is the one being disconnected: sphinx-hoverxref/hoverxref/extension.py Line 176 in c6eb8af
I still have the version that does sphinx version check + module name in previous commits, so please let me know your thoughts on whether this update seems reasonable! 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good! Thanks a lot for working on this.
Would you mind testing this PR with your documentation to double check it works as expected?
Thanks @humitos ! I can confirm this branch works on my intersphinx project (build here), which installs this branch from git:
And can be seen on the two links from grill.cook.UsdAsset's |
Hi hoverxref team,
My tooltips on intersphinx projects stopped working recently. After a while I was able to track down that the break started happening on
sphinx-7.4.0
.It seems to be due to
sphinx.ext.intersphinx
becoming a package since that version (through sphinx-doc/sphinx#12178, undocumented in the changelog), so I've updatedsetup_intersphinx
to check for a prefix in the module name, which should preserve backwards compatibility.Please let me know your thoughts!
To see in action, the
See also
links from grill.cook.UsdAsset:📚 Documentation preview 📚: https://sphinx-hoverxref--302.org.readthedocs.build/en/302/