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

Make :any: work with unknown object types in intersphinx. #5598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions sphinx/ext/intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ def missing_reference(app, env, node, contnode):
inventories = InventoryAdapter(env)
objtypes = None # type: List[str]
if node['reftype'] == 'any':
# we search anything!
objtypes = ['%s:%s' % (domain.name, objtype)
for domain in env.domains.values()
for objtype in domain.object_types]
domain = None
else:
domain = node.get('refdomain')
Expand All @@ -280,9 +276,9 @@ def missing_reference(app, env, node, contnode):
if not objtypes:
return None
objtypes = ['%s:%s' % (domain, objtype) for objtype in objtypes]
if 'std:cmdoption' in objtypes:
# until Sphinx-1.6, cmdoptions are stored as std:option
objtypes.append('std:option')
if 'std:cmdoption' in objtypes:
# until Sphinx-1.6, cmdoptions are stored as std:option
objtypes.append('std:option')
to_try = [(inventories.main_inventory, target)]
if domain:
full_qualified_name = env.get_domain(domain).get_full_qualified_name(node)
Expand All @@ -301,10 +297,15 @@ def missing_reference(app, env, node, contnode):
if full_qualified_name:
to_try.append((inventories.named_inventory[setname], full_qualified_name))
for inventory, target in to_try:
for objtype in objtypes:
if objtype not in inventory or target not in inventory[objtype]:
items = (
inventory.items()
if objtypes is None else
((t, inventory[t]) for t in objtypes if t in inventory)
)
for objtype, targets in items:
if target not in targets:
continue
proj, version, uri, dispname = inventory[objtype][target]
proj, version, uri, dispname = targets[target]
if '://' not in uri and node.get('refdoc'):
# get correct path in case of subdirectories
uri = path.join(relative_path(node['refdoc'], '.'), uri)
Expand Down
29 changes: 29 additions & 0 deletions tests/test_ext_intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,32 @@ def fake_read(*args, **kwargs):
stdout, stderr = capsys.readouterr()
assert stdout.startswith("c:function\n")
assert stderr == ""


def test_missing_reference_role_any_custom_type(tempdir, app, status, warning):
inv_file = tempdir / 'inventory'
inv_file.write_bytes(inventory_v2)
app.config.intersphinx_mapping = {
'sphinx': ('http://www.sphinx-doc.org/en/stable/', inv_file),
}
app.config.intersphinx_cache_limit = 0

# load the inventory and check if it's done correctly
normalize_intersphinx_mapping(app, app.config)
load_mappings(app)
inv = app.env.intersphinx_inventory
assert inv['std:confval']['gettext_uuid'] == \
('foo', '2.0', 'http://www.sphinx-doc.org/en/stable/usage/configuration.html', '-')
assert 'confval' not in app.env.get_domain('std').object_types

rn = reference_check(app, '', 'any', 'gettext_uuid', 'gettext_uuid')
assert isinstance(rn, nodes.reference)
assert rn['refuri'] == 'http://www.sphinx-doc.org/en/stable/usage/configuration.html'
assert rn['reftitle'] == '(in foo v2.0)'
assert rn[0].astext() == 'gettext_uuid'

rn = reference_check(app, '', 'any', 'sphinx:gettext_uuid', 'sphinx:gettext_uuid')
assert isinstance(rn, nodes.reference)
assert rn['refuri'] == 'http://www.sphinx-doc.org/en/stable/usage/configuration.html'
assert rn['reftitle'] == '(in foo v2.0)'
assert rn[0].astext() == 'gettext_uuid'
1 change: 1 addition & 0 deletions tests/test_util_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
foo.bar.baz js:method 1 index.html#foo.bar.baz -
foo.bar.qux js:data 1 index.html#foo.bar.qux -
a term including:colon std:term -1 glossary.html#term-a-term-including-colon -
gettext_uuid std:confval 0 usage/configuration.html -
'''.encode())

inventory_v2_not_having_version = '''\
Expand Down