Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4df6239
rST: add warning about duplicate anonymous hyperlink targets
jayaddison Mar 1, 2025
2dcdbce
Add CHANGES.rst entry
jayaddison Mar 1, 2025
7f561ff
rST: reduce false-positive warnings about duplicate hyperlink declara…
jayaddison Mar 2, 2025
e98d5b4
Merge branch 'master' into warn-about-duplicate-anonymous-hyperlinks
jayaddison Mar 24, 2025
f95f62e
Tests: add an anonymous hyperlink included from multiple documents
jayaddison Mar 24, 2025
0a93fa4
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison May 7, 2025
5f9b703
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Jun 2, 2025
5edb56d
tests: build-warnings: fix shared-hyperlink warning match expectations
jayaddison Jun 2, 2025
f54dc08
tests: build-warnings: adjust expected exception-raiser warning message
jayaddison Jun 2, 2025
f78dff0
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Oct 15, 2025
4f3bf7f
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Nov 9, 2025
07b5ed7
rST: remove duplicate anonymous label from `warn` to `info` severity
jayaddison Nov 29, 2025
ea23ca8
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Nov 29, 2025
69b53bc
Apply `ruff format`
jayaddison Nov 29, 2025
a3335e9
Adapt test case to anticipated feature rollout schedule
jayaddison Nov 30, 2025
accc8cf
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Dec 16, 2025
316124a
Tests: apply a more sensible deprecation strategy to duplicate-label …
jayaddison Dec 16, 2025
74f0e01
Tests: typo/syntax fixups in comment
jayaddison Dec 16, 2025
cdbf375
Tests: retain `unindent_warning` test coverage
jayaddison Dec 16, 2025
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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Features added

Bugs fixed
----------
* #13383: Emit an info-level message about duplicate internal hyperlink
declarations.
Patch by James Addison.

Testing
-------
7 changes: 7 additions & 0 deletions sphinx/domains/std/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,13 @@ def process_doc(
env.doc2path(self.labels[name][0]),
location=node,
)
elif name in self.anonlabels:
logger.info(
__('duplicate label %s, other instance in %s'),
name,
env.doc2path(self.anonlabels[name][0]),
location=node,
)
self.anonlabels[name] = docname, labelid
if node.tagname == 'section':
title = cast('nodes.title', node[0])
Expand Down
9 changes: 9 additions & 0 deletions tests/roots/test-warnings/hyperlinks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:orphan:

.. _ambiguous_hyperlink:

This hyperlink target is declared with the same name in two files.

.. include:: includes/shared-hyperlinks.rst

This is one of two places where the shared-hyperlinks file is included.
5 changes: 5 additions & 0 deletions tests/roots/test-warnings/includes/shared-hyperlinks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:orphan:

.. _ambiguous_shared_hyperlink:

This hyperlink target is declared once and is included by multiple documents.
8 changes: 8 additions & 0 deletions tests/roots/test-warnings/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ This used to crash: :option:`&option`
.. missing citation

[missing]_ citation

.. _ambiguous_hyperlink:

This hyperlink target is declared with the same name in two files.

.. include:: includes/shared-hyperlinks.rst

This is one of two places where the shared-hyperlinks file is included.
28 changes: 25 additions & 3 deletions tests/test_builders/test_build_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

from sphinx import version_info
from sphinx._cli.util.errors import strip_escape_sequences
from sphinx.errors import SphinxError

Expand All @@ -17,15 +18,35 @@

from sphinx.testing.util import SphinxTestApp

ENV_WARNINGS = """\
{root}/autodoc_fodder.py:docstring of autodoc_fodder.MarkupError:\\d+: \
# xref RemovedInSphinx11Warning
# From Sphinx 10, duplicate labels should always warn by default
DUPLICATE_LABEL_WARNINGS = version_info >= (10, 0, 0)

ENV_WARNINGS = (
(
"""
{root}/includes/shared-hyperlinks.rst:\\d+: WARNING: duplicate label ambiguous_shared_hyperlink, other instance in {root}/hyperlinks.rst
"""
if DUPLICATE_LABEL_WARNINGS
else ''
)
+ """{root}/autodoc_fodder.py:docstring of autodoc_fodder.MarkupError:\\d+: \
WARNING: Explicit markup ends without a blank line; unexpected unindent. \\[docutils\\]
{root}/index.rst:\\d+: WARNING: Encoding 'utf-8-sig' used for reading included \
file '{root}/wrongenc.inc' seems to be wrong, try giving an :encoding: option \\[docutils\\]
{root}/index.rst:\\d+: WARNING: invalid single index entry '' \\[index\\]
{root}/index.rst:\\d+: WARNING: invalid single index entry '' \\[index\\]"""
+ (
"""
{root}/index.rst:\\d+: WARNING: duplicate label ambiguous_hyperlink, other instance in {root}/hyperlinks.rst
{root}/includes/shared-hyperlinks.rst:\\d+: WARNING: duplicate label ambiguous_shared_hyperlink, other instance in {root}/includes/shared-hyperlinks.rst"""
if DUPLICATE_LABEL_WARNINGS
else ''
)
+ """
{root}/index.rst:\\d+: WARNING: image file not readable: foo.png \\[image.not_readable\\]
{root}/index.rst:\\d+: WARNING: download file not readable: {root}/nonexisting.png \\[download.not_readable\\]
"""
)

HTML_WARNINGS = (
ENV_WARNINGS
Expand Down Expand Up @@ -94,6 +115,7 @@ def test_html_warnings_exception_on_warning(app: SphinxTestApp) -> None:
tb = traceback.format_exc()
assert 'unindent_warning' in tb
assert 'pending_warnings' not in tb
assert 'duplicate label' in tb or not DUPLICATE_LABEL_WARNINGS


@pytest.mark.sphinx(
Expand Down
Loading