mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Style `sphinx.ext.intersphinx
`
This commit is contained in:
parent
14c1bc7fbe
commit
3edf2a2c6b
@ -10,8 +10,8 @@ from sphinx.ext.intersphinx._load import fetch_inventory
|
|||||||
def inspect_main(argv: list[str], /) -> int:
|
def inspect_main(argv: list[str], /) -> int:
|
||||||
"""Debug functionality to print out an inventory"""
|
"""Debug functionality to print out an inventory"""
|
||||||
if len(argv) < 1:
|
if len(argv) < 1:
|
||||||
print("Print out an inventory file.\n"
|
print('Print out an inventory file.\n'
|
||||||
"Error: must specify local path or URL to an inventory file.",
|
'Error: must specify local path or URL to an inventory file.',
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -42,10 +42,10 @@ def normalize_intersphinx_mapping(app: Sphinx, config: Config) -> None:
|
|||||||
name, uri, inv = None, key, value
|
name, uri, inv = None, key, value
|
||||||
msg = (
|
msg = (
|
||||||
"The pre-Sphinx 1.0 'intersphinx_mapping' format is "
|
"The pre-Sphinx 1.0 'intersphinx_mapping' format is "
|
||||||
"deprecated and will be removed in Sphinx 8. Update to the "
|
'deprecated and will be removed in Sphinx 8. Update to the '
|
||||||
"current format as described in the documentation. "
|
'current format as described in the documentation. '
|
||||||
f"Hint: \"intersphinx_mapping = {{'<name>': {(uri, inv)!r}}}\"."
|
f"Hint: `intersphinx_mapping = {{'<name>': {(uri, inv)!r}}}`."
|
||||||
"https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_mapping" # NoQA: E501
|
'https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_mapping' # NoQA: E501
|
||||||
)
|
)
|
||||||
LOGGER.warning(msg)
|
LOGGER.warning(msg)
|
||||||
|
|
||||||
@ -131,14 +131,14 @@ def fetch_inventory_group(
|
|||||||
if failures == []:
|
if failures == []:
|
||||||
pass
|
pass
|
||||||
elif len(failures) < len(invs):
|
elif len(failures) < len(invs):
|
||||||
LOGGER.info(__("encountered some issues with some of the inventories,"
|
LOGGER.info(__('encountered some issues with some of the inventories,'
|
||||||
" but they had working alternatives:"))
|
' but they had working alternatives:'))
|
||||||
for fail in failures:
|
for fail in failures:
|
||||||
LOGGER.info(*fail)
|
LOGGER.info(*fail)
|
||||||
else:
|
else:
|
||||||
issues = '\n'.join(f[0] % f[1:] for f in failures)
|
issues = '\n'.join(f[0] % f[1:] for f in failures)
|
||||||
LOGGER.warning(__("failed to reach any of the inventories "
|
LOGGER.warning(__('failed to reach any of the inventories '
|
||||||
"with the following issues:") + "\n" + issues)
|
'with the following issues:') + '\n' + issues)
|
||||||
|
|
||||||
|
|
||||||
def fetch_inventory(app: Sphinx, uri: str, inv: str) -> Inventory:
|
def fetch_inventory(app: Sphinx, uri: str, inv: str) -> Inventory:
|
||||||
@ -218,7 +218,7 @@ def _strip_basic_auth(url: str) -> str:
|
|||||||
:rtype: ``str``
|
:rtype: ``str``
|
||||||
"""
|
"""
|
||||||
frags = list(urlsplit(url))
|
frags = list(urlsplit(url))
|
||||||
# swap out "user[:pass]@hostname" for "hostname"
|
# swap out 'user[:pass]@hostname' for 'hostname'
|
||||||
if '@' in frags[1]:
|
if '@' in frags[1]:
|
||||||
frags[1] = frags[1].split('@')[1]
|
frags[1] = frags[1].split('@')[1]
|
||||||
return urlunsplit(frags)
|
return urlunsplit(frags)
|
||||||
|
@ -46,8 +46,7 @@ def _create_element_from_result(domain: Domain, inv_name: str | None,
|
|||||||
if node.get('refexplicit'):
|
if node.get('refexplicit'):
|
||||||
# use whatever title was given
|
# use whatever title was given
|
||||||
newnode.append(contnode)
|
newnode.append(contnode)
|
||||||
elif dispname == '-' or \
|
elif dispname == '-' or (domain.name == 'std' and node['reftype'] == 'keyword'):
|
||||||
(domain.name == 'std' and node['reftype'] == 'keyword'):
|
|
||||||
# use whatever title was given, but strip prefix
|
# use whatever title was given, but strip prefix
|
||||||
title = contnode.astext()
|
title = contnode.astext()
|
||||||
if inv_name is not None and title.startswith(inv_name + ':'):
|
if inv_name is not None and title.startswith(inv_name + ':'):
|
||||||
@ -113,7 +112,7 @@ def _resolve_reference_in_domain(env: BuildEnvironment,
|
|||||||
|
|
||||||
# the inventory contains domain:type as objtype
|
# the inventory contains domain:type as objtype
|
||||||
domain_name = domain.name
|
domain_name = domain.name
|
||||||
obj_types = {f"{domain_name}:{obj_type}": None for obj_type in obj_types}
|
obj_types = {f'{domain_name}:{obj_type}': None for obj_type in obj_types}
|
||||||
|
|
||||||
# now that the objtypes list is complete we can remove the disabled ones
|
# now that the objtypes list is complete we can remove the disabled ones
|
||||||
if honor_disabled_refs:
|
if honor_disabled_refs:
|
||||||
@ -151,7 +150,7 @@ def _resolve_reference(env: BuildEnvironment, inv_name: str | None, inventory: I
|
|||||||
if typ == 'any':
|
if typ == 'any':
|
||||||
for domain_name, domain in env.domains.items():
|
for domain_name, domain in env.domains.items():
|
||||||
if (honor_disabled_refs
|
if (honor_disabled_refs
|
||||||
and (domain_name + ":*") in env.config.intersphinx_disabled_reftypes):
|
and (domain_name + ':*') in env.config.intersphinx_disabled_reftypes):
|
||||||
continue
|
continue
|
||||||
objtypes: Iterable[str] = domain.object_types.keys()
|
objtypes: Iterable[str] = domain.object_types.keys()
|
||||||
res = _resolve_reference_in_domain(env, inv_name, inventory,
|
res = _resolve_reference_in_domain(env, inv_name, inventory,
|
||||||
@ -166,8 +165,8 @@ def _resolve_reference(env: BuildEnvironment, inv_name: str | None, inventory: I
|
|||||||
if not domain_name:
|
if not domain_name:
|
||||||
# only objects in domains are in the inventory
|
# only objects in domains are in the inventory
|
||||||
return None
|
return None
|
||||||
if honor_disabled_refs \
|
if (honor_disabled_refs
|
||||||
and (domain_name + ":*") in env.config.intersphinx_disabled_reftypes:
|
and (domain_name + ':*') in env.config.intersphinx_disabled_reftypes):
|
||||||
return None
|
return None
|
||||||
domain = env.get_domain(domain_name)
|
domain = env.get_domain(domain_name)
|
||||||
objtypes = domain.objtypes_for_role(typ) or ()
|
objtypes = domain.objtypes_for_role(typ) or ()
|
||||||
@ -264,7 +263,7 @@ class IntersphinxRole(SphinxRole):
|
|||||||
# group 1: just for the optionality of the inventory name
|
# group 1: just for the optionality of the inventory name
|
||||||
# group 2: the inventory name (optional)
|
# group 2: the inventory name (optional)
|
||||||
# group 3: the domain:role or role part
|
# group 3: the domain:role or role part
|
||||||
_re_inv_ref = re.compile(r"(\+([^:]+))?:(.*)")
|
_re_inv_ref = re.compile(r'(\+([^:]+))?:(.*)')
|
||||||
|
|
||||||
def __init__(self, orig_name: str) -> None:
|
def __init__(self, orig_name: str) -> None:
|
||||||
self.orig_name = orig_name
|
self.orig_name = orig_name
|
||||||
|
Loading…
Reference in New Issue
Block a user