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:
|
||||
"""Debug functionality to print out an inventory"""
|
||||
if len(argv) < 1:
|
||||
print("Print out an inventory file.\n"
|
||||
"Error: must specify local path or URL to an inventory file.",
|
||||
print('Print out an inventory file.\n'
|
||||
'Error: must specify local path or URL to an inventory file.',
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
@ -42,10 +42,10 @@ def normalize_intersphinx_mapping(app: Sphinx, config: Config) -> None:
|
||||
name, uri, inv = None, key, value
|
||||
msg = (
|
||||
"The pre-Sphinx 1.0 'intersphinx_mapping' format is "
|
||||
"deprecated and will be removed in Sphinx 8. Update to the "
|
||||
"current format as described in the documentation. "
|
||||
f"Hint: \"intersphinx_mapping = {{'<name>': {(uri, inv)!r}}}\"."
|
||||
"https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_mapping" # NoQA: E501
|
||||
'deprecated and will be removed in Sphinx 8. Update to the '
|
||||
'current format as described in the documentation. '
|
||||
f"Hint: `intersphinx_mapping = {{'<name>': {(uri, inv)!r}}}`."
|
||||
'https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_mapping' # NoQA: E501
|
||||
)
|
||||
LOGGER.warning(msg)
|
||||
|
||||
@ -131,14 +131,14 @@ def fetch_inventory_group(
|
||||
if failures == []:
|
||||
pass
|
||||
elif len(failures) < len(invs):
|
||||
LOGGER.info(__("encountered some issues with some of the inventories,"
|
||||
" but they had working alternatives:"))
|
||||
LOGGER.info(__('encountered some issues with some of the inventories,'
|
||||
' but they had working alternatives:'))
|
||||
for fail in failures:
|
||||
LOGGER.info(*fail)
|
||||
else:
|
||||
issues = '\n'.join(f[0] % f[1:] for f in failures)
|
||||
LOGGER.warning(__("failed to reach any of the inventories "
|
||||
"with the following issues:") + "\n" + issues)
|
||||
LOGGER.warning(__('failed to reach any of the inventories '
|
||||
'with the following issues:') + '\n' + issues)
|
||||
|
||||
|
||||
def fetch_inventory(app: Sphinx, uri: str, inv: str) -> Inventory:
|
||||
@ -218,7 +218,7 @@ def _strip_basic_auth(url: str) -> str:
|
||||
:rtype: ``str``
|
||||
"""
|
||||
frags = list(urlsplit(url))
|
||||
# swap out "user[:pass]@hostname" for "hostname"
|
||||
# swap out 'user[:pass]@hostname' for 'hostname'
|
||||
if '@' in frags[1]:
|
||||
frags[1] = frags[1].split('@')[1]
|
||||
return urlunsplit(frags)
|
||||
|
@ -46,8 +46,7 @@ def _create_element_from_result(domain: Domain, inv_name: str | None,
|
||||
if node.get('refexplicit'):
|
||||
# use whatever title was given
|
||||
newnode.append(contnode)
|
||||
elif dispname == '-' or \
|
||||
(domain.name == 'std' and node['reftype'] == 'keyword'):
|
||||
elif dispname == '-' or (domain.name == 'std' and node['reftype'] == 'keyword'):
|
||||
# use whatever title was given, but strip prefix
|
||||
title = contnode.astext()
|
||||
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
|
||||
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
|
||||
if honor_disabled_refs:
|
||||
@ -151,7 +150,7 @@ def _resolve_reference(env: BuildEnvironment, inv_name: str | None, inventory: I
|
||||
if typ == 'any':
|
||||
for domain_name, domain in env.domains.items():
|
||||
if (honor_disabled_refs
|
||||
and (domain_name + ":*") in env.config.intersphinx_disabled_reftypes):
|
||||
and (domain_name + ':*') in env.config.intersphinx_disabled_reftypes):
|
||||
continue
|
||||
objtypes: Iterable[str] = domain.object_types.keys()
|
||||
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:
|
||||
# only objects in domains are in the inventory
|
||||
return None
|
||||
if honor_disabled_refs \
|
||||
and (domain_name + ":*") in env.config.intersphinx_disabled_reftypes:
|
||||
if (honor_disabled_refs
|
||||
and (domain_name + ':*') in env.config.intersphinx_disabled_reftypes):
|
||||
return None
|
||||
domain = env.get_domain(domain_name)
|
||||
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 2: the inventory name (optional)
|
||||
# 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:
|
||||
self.orig_name = orig_name
|
||||
|
Loading…
Reference in New Issue
Block a user