This repository was archived by the owner on Apr 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Update compatibility of setup_intersphinx module name check with Sphinx-7.4 #302
Merged
humitos
merged 10 commits into
readthedocs:main
from
chrizzFTD:update_setup_intersphinx_module_check
Sep 6, 2024
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
65524c4
Starting sphinx-7.4.0, sphinx.ext.intersphinx is a package, so check …
chrizzFTD ee8c126
Adding test for disconnecting the intersphinx listener
chrizzFTD 8e38477
removing unused imports
chrizzFTD ce0d675
adding sphinx 74 to tox
chrizzFTD 102703e
Merge branch 'readthedocs:main' into update_setup_intersphinx_module_…
chrizzFTD d19ae73
target explicit intersphinx module name depending on sphinx version
chrizzFTD a242bbf
check for explicit event listeners presence for missing-reference
chrizzFTD 79e07e3
check handler against sphinx_missing_reference explicitly
chrizzFTD c6eb8af
sphinx.ext.intersphinx.missing_reference continues to be public API i…
chrizzFTD 8d2edf4
Merge branch 'main' into update_setup_intersphinx_module_check
chrizzFTD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
import inspect | ||
import os | ||
import pytest | ||
import shutil | ||
from unittest import mock | ||
|
||
from .utils import srcdir | ||
|
||
|
@@ -34,3 +31,26 @@ def _get_docpath(self, builder, docname): | |
content = open(path).read() | ||
|
||
assert app.builder.format == 'latex' | ||
|
||
|
||
@pytest.mark.sphinx( | ||
srcdir=srcdir, | ||
confoverrides={ | ||
'hoverxref_domains': ['py'], | ||
'hoverxref_intersphinx': ['python'], | ||
'hoverxref_auto_ref': True, | ||
'extensions': [ | ||
'sphinx.ext.intersphinx', | ||
'hoverxref.extension', | ||
], | ||
}, | ||
) | ||
def test_disconnect_intersphinx_listener(app, status, warning): | ||
"""Confirm that disconnecting the ``missing-reference`` listener from ``sphinx.ext.intershinx`` is successful.""" | ||
app.build() | ||
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 commentThe 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 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 calledsphinx.ext.intersphinx._resolve
. Would it be better to be pretty explicit here to avoid disconnecting things we are not expecting to disconnect?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 👍🏼