[linkcheck] Allow integer for linkcheck_rate_limit_timeout (#12470)

Eliminate type-related warnings when users configure a valid integer value for the `linkcheck_rate_limit_timeout` config setting.

Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
This commit is contained in:
James Addison
2024-06-24 18:26:24 +01:00
committed by GitHub
parent 2ccae70089
commit 6b237d9a70
4 changed files with 11 additions and 6 deletions

View File

@@ -58,6 +58,9 @@ Bugs fixed
Patch by Bénédikt Tran.
* #12220: Fix loading custom template translations for ``en`` locale.
Patch by Nicolas Peugnet.
* #12459: Add valid-type arguments to the ``linkcheck_rate_limit_timeout``
configuration setting.
Patch by James Addison.
Improvements
------------

View File

@@ -2950,8 +2950,8 @@ Options for the linkcheck builder
Otherwise, ``linkcheck`` waits for a minute before to retry and keeps
doubling the wait time between attempts until it succeeds or exceeds the
``linkcheck_rate_limit_timeout``. By default, the timeout is 300 seconds
and custom timeouts should be given in seconds.
``linkcheck_rate_limit_timeout``. By default, the timeout is 300 seconds.
Custom timeouts should be given as a number of seconds.
.. _Retry-After: https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.3

View File

@@ -708,7 +708,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
# commonly used for dynamic pages
app.add_config_value('linkcheck_anchors_ignore', ['^!'], '')
app.add_config_value('linkcheck_anchors_ignore_for_url', (), '', (tuple, list))
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '')
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '', (int, float))
app.add_config_value('linkcheck_allow_unauthorized', True, '')
app.add_config_value('linkcheck_report_timeouts_as_broken', True, '', bool)

View File

@@ -936,21 +936,23 @@ def test_limit_rate_doubles_previous_wait_time(app: Sphinx) -> None:
assert next_check == 120.0
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90.0})
def test_limit_rate_clips_wait_time_to_max_time(app: Sphinx) -> None:
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90})
def test_limit_rate_clips_wait_time_to_max_time(app: Sphinx, warning: StringIO) -> None:
rate_limits = {"localhost": RateLimit(60.0, 0.0)}
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
with mock.patch('time.time', return_value=0.0):
next_check = worker.limit_rate(FakeResponse.url, FakeResponse.headers.get("Retry-After"))
assert next_check == 90.0
assert warning.getvalue() == ''
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90.0})
def test_limit_rate_bails_out_after_waiting_max_time(app: Sphinx) -> None:
def test_limit_rate_bails_out_after_waiting_max_time(app: Sphinx, warning: StringIO) -> None:
rate_limits = {"localhost": RateLimit(90.0, 0.0)}
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
next_check = worker.limit_rate(FakeResponse.url, FakeResponse.headers.get("Retry-After"))
assert next_check is None
assert warning.getvalue() == ''
@mock.patch('sphinx.util.requests.requests.Session.get_adapter')