Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.

Commit e61a839

Browse files
authored
Merge pull request #195 from readthedocs/humitos/intersphinx-exception
2 parents a1255c5 + d69dffa commit e61a839

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

hoverxref/extension.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def missing_reference(app, env, node, contnode):
197197
198198
See https://github.com/sphinx-doc/sphinx/blob/4d90277c/sphinx/ext/intersphinx.py#L244-L250
199199
"""
200-
if not app.config.hoverxref_intersphinx:
200+
if not app.config.hoverxref_intersphinx or 'sphinx.ext.intersphinx' not in app.config.extensions:
201201
# Do nothing if the user doesn't have hoverxref intersphinx enabled
202202
return
203203

@@ -239,7 +239,13 @@ def missing_reference(app, env, node, contnode):
239239
inventory = inventories.named_inventory.get(inventory_name, {})
240240
# Logic of `.objtypes_for_role` stolen from
241241
# https://github.com/sphinx-doc/sphinx/blob/b8789b4c/sphinx/ext/intersphinx.py#L397
242-
for objtype in env.get_domain(domain).objtypes_for_role(reftype):
242+
objtypes_for_role = env.get_domain(domain).objtypes_for_role(reftype)
243+
244+
# If the reftype is not defined on the domain, we skip it
245+
if not objtypes_for_role:
246+
continue
247+
248+
for objtype in objtypes_for_role:
243249
inventory_member = inventory.get(f'{domain}:{objtype}')
244250

245251
if inventory_member and inventory_member.get(target) is not None:

tests/examples/python-domain/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ This is an example page with a Python Domain role usage.
88
:py:mod:`hoverxref.extension`
99

1010
:py:func:`hoverxref.extension.setup`
11+
12+
Note that ``:py:const:`` does not exist in the Python domain, but it shouldn't make the build to fail.
13+
"Constant" should be rendered in the same way as the other Python objects: :py:const:`Constant`

tests/test_htmltag.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,38 @@ def test_python_domain(app, status, warning):
118118
'<a class="hoverxref tooltip reference internal" href="api.html#hoverxref.extension.HoverXRefStandardDomainMixin" title="hoverxref.extension.HoverXRefStandardDomainMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:py:class:</span> <span class="pre">role</span> <span class="pre">to</span> <span class="pre">a</span> <span class="pre">Python</span> <span class="pre">object</span></code></a>',
119119
'<a class="hoverxref tooltip reference internal" href="api.html#module-hoverxref.extension" title="hoverxref.extension"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hoverxref.extension</span></code></a>',
120120
'<a class="hoverxref tooltip reference internal" href="api.html#hoverxref.extension.setup" title="hoverxref.extension.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.extension.setup()</span></code></a>',
121+
'<code class="xref py py-const docutils literal notranslate"><span class="pre">Constant</span></code>',
122+
]
123+
124+
for chunk in chunks:
125+
assert chunk in content
126+
127+
128+
@pytest.mark.sphinx(
129+
srcdir=pythondomainsrcdir,
130+
confoverrides={
131+
'hoverxref_domains': ['py'],
132+
'hoverxref_intersphinx': ['python'],
133+
'hoverxref_auto_ref': True,
134+
'extensions': [
135+
'sphinx.ext.autodoc',
136+
'sphinx.ext.autosectionlabel',
137+
'sphinx.ext.intersphinx',
138+
'hoverxref.extension',
139+
],
140+
},
141+
)
142+
def test_python_domain_intersphinx(app, status, warning):
143+
app.build()
144+
path = app.outdir / 'index.html'
145+
assert path.exists() is True
146+
content = open(path).read()
147+
148+
chunks = [
149+
'<a class="hoverxref tooltip reference internal" href="api.html#hoverxref.extension.HoverXRefStandardDomainMixin" title="hoverxref.extension.HoverXRefStandardDomainMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:py:class:</span> <span class="pre">role</span> <span class="pre">to</span> <span class="pre">a</span> <span class="pre">Python</span> <span class="pre">object</span></code></a>',
150+
'<a class="hoverxref tooltip reference internal" href="api.html#module-hoverxref.extension" title="hoverxref.extension"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hoverxref.extension</span></code></a>',
151+
'<a class="hoverxref tooltip reference internal" href="api.html#hoverxref.extension.setup" title="hoverxref.extension.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.extension.setup()</span></code></a>',
152+
'<code class="xref py py-const docutils literal notranslate"><span class="pre">Constant</span></code>',
121153
]
122154

123155
for chunk in chunks:

0 commit comments

Comments
 (0)