Skip to content

Commit

Permalink
Simplify logger.error calls in validate_intersphinx_mapping (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz authored Jul 22, 2024
1 parent e174df2 commit 8c6d234
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions sphinx/ext/intersphinx/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,13 @@ def validate_intersphinx_mapping(app: Sphinx, config: Config) -> None:
errors = 0
for name, value in config.intersphinx_mapping.copy().items():
# ensure that intersphinx projects are always named
if not isinstance(name, str):
if not isinstance(name, str) or not name:
errors += 1
msg = __(
'Invalid intersphinx project identifier `%r` in intersphinx_mapping. '
'Project identifiers must be non-empty strings.'
)
LOGGER.error(msg % name)
del config.intersphinx_mapping[name]
continue
if not name:
errors += 1
msg = __(
'Invalid intersphinx project identifier `%r` in intersphinx_mapping. '
'Project identifiers must be non-empty strings.'
)
LOGGER.error(msg % name)
LOGGER.error(msg, name)
del config.intersphinx_mapping[name]
continue

Expand All @@ -78,7 +69,7 @@ def validate_intersphinx_mapping(app: Sphinx, config: Config) -> None:
'Invalid value `%r` in intersphinx_mapping[%r]. '
'Expected a two-element tuple or list.'
)
LOGGER.error(msg % (value, name))
LOGGER.error(msg, value, name)
del config.intersphinx_mapping[name]
continue
try:
Expand All @@ -89,7 +80,7 @@ def validate_intersphinx_mapping(app: Sphinx, config: Config) -> None:
'Invalid value `%r` in intersphinx_mapping[%r]. '
'Values must be a (target URI, inventory locations) pair.'
)
LOGGER.error(msg % (value, name))
LOGGER.error(msg, value, name)
del config.intersphinx_mapping[name]
continue

Expand All @@ -98,7 +89,7 @@ def validate_intersphinx_mapping(app: Sphinx, config: Config) -> None:
errors += 1
msg = __('Invalid target URI value `%r` in intersphinx_mapping[%r][0]. '
'Target URIs must be unique non-empty strings.')
LOGGER.error(msg % (uri, name))
LOGGER.error(msg, uri, name)
del config.intersphinx_mapping[name]
continue
if uri in seen:
Expand All @@ -107,7 +98,7 @@ def validate_intersphinx_mapping(app: Sphinx, config: Config) -> None:
'Invalid target URI value `%r` in intersphinx_mapping[%r][0]. '
'Target URIs must be unique (other instance in intersphinx_mapping[%r]).'
)
LOGGER.error(msg % (uri, name, seen[uri]))
LOGGER.error(msg, uri, name, seen[uri])
del config.intersphinx_mapping[name]
continue
seen[uri] = name
Expand All @@ -123,7 +114,7 @@ def validate_intersphinx_mapping(app: Sphinx, config: Config) -> None:
'Invalid inventory location value `%r` in intersphinx_mapping[%r][1]. '
'Inventory locations must be non-empty strings or None.'
)
LOGGER.error(msg % (target, name))
LOGGER.error(msg, target, name)
del config.intersphinx_mapping[name]
continue

Expand Down

0 comments on commit 8c6d234

Please sign in to comment.