Skip to content

Commit cc08854

Browse files
linkcheck: Update configuration defaults for Sphinx 8.0 (sphinx-doc#12630)
- Links that respond with HTTP 401 (unauthorized) responses are now considered ``broken`` by default. - Timeouts that occur when checking a link are now reported with a distinct `timeout` status code, instead of the previous ``broken``. - The previous behaviours are still available and can be configured on an opt-in basis per-project using ``conf.py``. Co-authored-by: Adam Turner <[email protected]>
1 parent 2034f7d commit cc08854

File tree

4 files changed

+25
-73
lines changed

4 files changed

+25
-73
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ Incompatible changes
5151
Patch by Adam Turner.
5252
* Removed the tuple interface to :py:class:`!sphinx.ext.autodoc.ObjectMember`.
5353
Patch by Adam Turner.
54+
* #12630: Sphinx 8 makes two changes to the ``linkcheck`` configuration defaults:
55+
56+
* :confval:`linkcheck_allow_unauthorized` is now ``False`` by default.
57+
* :confval:`linkcheck_report_timeouts_as_broken` is now ``False`` by default.
58+
59+
Patch by James Addison.
5460

5561
Deprecated
5662
----------

doc/usage/configuration.rst

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,20 +3714,17 @@ and the number of workers to use.
37143714

37153715
.. confval:: linkcheck_allow_unauthorized
37163716
:type: :code-py:`bool`
3717-
:default: :code-py:`True`
3717+
:default: :code-py:`False`
37183718

37193719
When a webserver responds with an HTTP 401 (unauthorised) response,
37203720
the current default behaviour of the *linkcheck* builder is
3721-
to treat the link as "working".
3722-
To change that behaviour, set this option to :code-py:`False`.
3721+
to treat the link as "broken".
3722+
To change that behaviour, set this option to :code-py:`True`.
37233723

3724-
.. attention::
3725-
The default value for this option will be changed in Sphinx 8.0;
3726-
from that version onwards,
3727-
HTTP 401 responses to checked hyperlinks will be treated
3728-
as "broken" by default.
3729-
3730-
.. xref RemovedInSphinx80Warning
3724+
.. versionchanged:: 8.0
3725+
The default value for this option changed to :code-py:`False`,
3726+
meaning HTTP 401 responses to checked hyperlinks
3727+
are treated as "broken" by default.
37313728

37323729
.. versionadded:: 7.3
37333730

@@ -3755,21 +3752,18 @@ and the number of workers to use.
37553752

37563753
.. confval:: linkcheck_report_timeouts_as_broken
37573754
:type: :code-py:`bool`
3758-
:default: :code-py:`True`
3755+
:default: :code-py:`False`
37593756

3760-
When an HTTP response is not received from a webserver before the configured
3761-
:confval:`linkcheck_timeout` expires,
3762-
the current default behaviour of the *linkcheck* builder is
3763-
to treat the link as 'broken'.
3764-
To report timeouts using a distinct report code of ``timeout``,
3765-
set :confval:`linkcheck_report_timeouts_as_broken` to :code-py:`False`.
3757+
If :confval:`linkcheck_timeout` expires while waiting for a response from
3758+
a hyperlink, the *linkcheck* builder will report the link as a ``timeout``
3759+
by default. To report timeouts as ``broken`` instead, you can
3760+
set :confval:`linkcheck_report_timeouts_as_broken` to :code-py:`True`.
37663761

3767-
.. attention::
3768-
From Sphinx 8.0 onwards, timeouts that occur while checking hyperlinks
3762+
.. versionchanged:: 8.0
3763+
The default value for this option changed to :code-py:`False`,
3764+
meaning timeouts that occur while checking hyperlinks
37693765
will be reported using the new 'timeout' status code.
37703766

3771-
.. xref RemovedInSphinx80Warning
3772-
37733767
.. versionadded:: 7.3
37743768

37753769
.. confval:: linkcheck_request_headers

sphinx/builders/linkcheck.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import re
88
import socket
99
import time
10-
import warnings
1110
from html.parser import HTMLParser
1211
from os import path
1312
from queue import PriorityQueue, Queue
@@ -20,7 +19,6 @@
2019
from requests.exceptions import Timeout as RequestTimeout
2120

2221
from sphinx.builders.dummy import DummyBuilder
23-
from sphinx.deprecation import RemovedInSphinx80Warning
2422
from sphinx.locale import __
2523
from sphinx.transforms.post_transforms import SphinxPostTransform
2624
from sphinx.util import encode_uri, logging, requests
@@ -66,25 +64,6 @@ def init(self) -> None:
6664
# set a timeout for non-responding servers
6765
socket.setdefaulttimeout(5.0)
6866

69-
if not self.config.linkcheck_allow_unauthorized:
70-
deprecation_msg = (
71-
"The default value for 'linkcheck_allow_unauthorized' will change "
72-
"from `True` in Sphinx 7.3+ to `False`, meaning that HTTP 401 "
73-
"unauthorized responses will be reported as broken by default. "
74-
"See https://github.com/sphinx-doc/sphinx/issues/11433 for details."
75-
)
76-
warnings.warn(deprecation_msg, RemovedInSphinx80Warning, stacklevel=1)
77-
78-
if self.config.linkcheck_report_timeouts_as_broken:
79-
deprecation_msg = (
80-
"The default value for 'linkcheck_report_timeouts_as_broken' will change "
81-
'to False in Sphinx 8, meaning that request timeouts '
82-
"will be reported with a new 'timeout' status, instead of as 'broken'. "
83-
'This is intended to provide more detail as to the failure mode. '
84-
'See https://github.com/sphinx-doc/sphinx/issues/11868 for details.'
85-
)
86-
warnings.warn(deprecation_msg, RemovedInSphinx80Warning, stacklevel=1)
87-
8867
def finish(self) -> None:
8968
checker = HyperlinkAvailabilityChecker(self.config)
9069
logger.info('')
@@ -510,27 +489,6 @@ def _check_uri(self, uri: str, hyperlink: Hyperlink) -> tuple[str, str, int]:
510489

511490
# Unauthorized: the client did not provide required credentials
512491
if status_code == 401:
513-
if self._allow_unauthorized:
514-
deprecation_msg = (
515-
"\n---\n"
516-
"The linkcheck builder encountered an HTTP 401 "
517-
"(unauthorized) response, and will report it as "
518-
"'working' in this version of Sphinx to maintain "
519-
"backwards-compatibility."
520-
"\n"
521-
"This logic will change in Sphinx 8.0 which will "
522-
"report the hyperlink as 'broken'."
523-
"\n"
524-
"To explicitly continue treating unauthorized "
525-
"hyperlink responses as 'working', set the "
526-
"'linkcheck_allow_unauthorized' config option to "
527-
"``True``."
528-
"\n"
529-
"See https://github.com/sphinx-doc/sphinx/issues/11433 "
530-
"for details."
531-
"\n---"
532-
)
533-
warnings.warn(deprecation_msg, RemovedInSphinx80Warning, stacklevel=1)
534492
status = 'working' if self._allow_unauthorized else 'broken'
535493
return status, 'unauthorized', 0
536494

@@ -717,8 +675,8 @@ def setup(app: Sphinx) -> ExtensionMetadata:
717675
app.add_config_value('linkcheck_anchors_ignore', ['^!'], '')
718676
app.add_config_value('linkcheck_anchors_ignore_for_url', (), '', (tuple, list))
719677
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '', (int, float))
720-
app.add_config_value('linkcheck_allow_unauthorized', True, '')
721-
app.add_config_value('linkcheck_report_timeouts_as_broken', True, '', bool)
678+
app.add_config_value('linkcheck_allow_unauthorized', False, '')
679+
app.add_config_value('linkcheck_report_timeouts_as_broken', False, '', bool)
722680

723681
app.add_event('linkcheck-process-uri')
724682

tests/test_builders/test_build_linkcheck.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
RateLimit,
2828
compile_linkcheck_allowed_redirects,
2929
)
30-
from sphinx.deprecation import RemovedInSphinx80Warning
3130
from sphinx.util import requests
3231
from sphinx.util.console import strip_colors
3332

@@ -503,7 +502,6 @@ def test_auth_header_uses_first_match(app: Sphinx) -> None:
503502
assert content["status"] == "working"
504503

505504

506-
@pytest.mark.filterwarnings('ignore::sphinx.deprecation.RemovedInSphinx80Warning')
507505
@pytest.mark.sphinx(
508506
'linkcheck', testroot='linkcheck-localserver', freshenv=True,
509507
confoverrides={'linkcheck_allow_unauthorized': False})
@@ -522,18 +520,14 @@ def test_unauthorized_broken(app: Sphinx) -> None:
522520
'linkcheck', testroot='linkcheck-localserver', freshenv=True,
523521
confoverrides={'linkcheck_auth': [(r'^$', ('user1', 'password'))]})
524522
def test_auth_header_no_match(app: Sphinx) -> None:
525-
with (
526-
serve_application(app, custom_handler(valid_credentials=("user1", "password"))),
527-
pytest.warns(RemovedInSphinx80Warning, match='linkcheck builder encountered an HTTP 401'),
528-
):
523+
with serve_application(app, custom_handler(valid_credentials=("user1", "password"))):
529524
app.build()
530525

531526
with open(app.outdir / "output.json", encoding="utf-8") as fp:
532527
content = json.load(fp)
533528

534-
# This link is considered working based on the default linkcheck_allow_unauthorized=true
535529
assert content["info"] == "unauthorized"
536-
assert content["status"] == "working"
530+
assert content["status"] == "broken"
537531

538532

539533
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)

0 commit comments

Comments
 (0)