mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Rename linkcheck_ignore_redirects to linkcheck_allowed_redirects
This commit is contained in:
parent
707319aab2
commit
ce9e2e6c74
4
CHANGES
4
CHANGES
@ -38,8 +38,8 @@ Features added
|
|||||||
:confval:`locale_dirs`
|
:confval:`locale_dirs`
|
||||||
* #6525: linkcheck: Add :confval:`linkcheck_warn_redirects` to emit a warning
|
* #6525: linkcheck: Add :confval:`linkcheck_warn_redirects` to emit a warning
|
||||||
when the hyperlink is redirected
|
when the hyperlink is redirected
|
||||||
* #6525: linkcheck: Add :confval:`linkcheck_ignore_redirects` to ignore
|
* #6525: linkcheck: Add :confval:`linkcheck_allowed_redirects` to mark
|
||||||
hyperlinks that are redirected to expected URLs
|
hyperlinks that are redirected to expected URLs as "working"
|
||||||
* #9097: Optimize the paralell build
|
* #9097: Optimize the paralell build
|
||||||
* #9131: Add :confval:`nitpick_ignore_regex` to ignore nitpicky warnings using
|
* #9131: Add :confval:`nitpick_ignore_regex` to ignore nitpicky warnings using
|
||||||
regular expressions
|
regular expressions
|
||||||
|
@ -2522,17 +2522,17 @@ Options for the linkcheck builder
|
|||||||
|
|
||||||
.. versionadded:: 1.1
|
.. versionadded:: 1.1
|
||||||
|
|
||||||
.. confval:: linkcheck_ignore_redirects
|
.. confval:: linkcheck_allowed_redirects
|
||||||
|
|
||||||
A dictionary that maps a pattern of the source URI to a pattern of the canonical
|
A dictionary that maps a pattern of the source URI to a pattern of the canonical
|
||||||
URI. If set, linkcheck builder treated as "ignored" if a hyperlink in the source
|
URI. If set, linkcheck builder treated as "working" if a hyperlink in the source
|
||||||
document that matches to the pattern of the source URI, and it redirects to the
|
document that matches to the pattern of the source URI, and it redirects to the
|
||||||
URL that matches to the pattern of the canonical URI. Example:
|
URL that matches to the pattern of the canonical URI. Example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
linkcheck_ignore_redirects = {
|
linkcheck_working_redirects = {
|
||||||
# All HTTP redirections from the source URI to the canonical URI will be ignored.
|
# All HTTP redirections from the source URI to the canonical URI will be treated as "working".
|
||||||
'http://sphinx-doc.org/.*': 'https://sphinx-doc.org/en/master/.*'
|
'http://sphinx-doc.org/.*': 'https://sphinx-doc.org/en/master/.*'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ class HyperlinkAvailabilityCheckWorker(Thread):
|
|||||||
if anchor:
|
if anchor:
|
||||||
new_url += '#' + anchor
|
new_url += '#' + anchor
|
||||||
|
|
||||||
if ignored_redirect(req_url, new_url):
|
if allowed_redirect(req_url, new_url):
|
||||||
return 'working', '', 0
|
return 'working', '', 0
|
||||||
elif response.history:
|
elif response.history:
|
||||||
# history contains any redirects, get last
|
# history contains any redirects, get last
|
||||||
@ -508,8 +508,8 @@ class HyperlinkAvailabilityCheckWorker(Thread):
|
|||||||
else:
|
else:
|
||||||
return 'redirected', new_url, 0
|
return 'redirected', new_url, 0
|
||||||
|
|
||||||
def ignored_redirect(url: str, new_url: str) -> bool:
|
def allowed_redirect(url: str, new_url: str) -> bool:
|
||||||
for from_url, to_url in self.config.linkcheck_ignore_redirects.items():
|
for from_url, to_url in self.config.linkcheck_allowed_redirects.items():
|
||||||
if from_url.match(url) and to_url.match(new_url):
|
if from_url.match(url) and to_url.match(new_url):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -656,17 +656,17 @@ class HyperlinkCollector(SphinxPostTransform):
|
|||||||
hyperlinks[uri] = uri_info
|
hyperlinks[uri] = uri_info
|
||||||
|
|
||||||
|
|
||||||
def compile_linkcheck_ignore_redirects(app: Sphinx, config: Config) -> None:
|
def compile_linkcheck_allowed_redirects(app: Sphinx, config: Config) -> None:
|
||||||
"""Compile patterns in linkcheck_ignore_redirects to the regexp objects."""
|
"""Compile patterns in linkcheck_allowed_redirects to the regexp objects."""
|
||||||
for url, pattern in list(app.config.linkcheck_ignore_redirects.items()):
|
for url, pattern in list(app.config.linkcheck_allowed_redirects.items()):
|
||||||
try:
|
try:
|
||||||
app.config.linkcheck_ignore_redirects[re.compile(url)] = re.compile(pattern)
|
app.config.linkcheck_allowed_redirects[re.compile(url)] = re.compile(pattern)
|
||||||
except re.error as exc:
|
except re.error as exc:
|
||||||
logger.warning(__('Failed to compile regex in linkcheck_ignore_redirects: %r %s'),
|
logger.warning(__('Failed to compile regex in linkcheck_allowed_redirects: %r %s'),
|
||||||
exc.pattern, exc.msg)
|
exc.pattern, exc.msg)
|
||||||
finally:
|
finally:
|
||||||
# Remove the original regexp-string
|
# Remove the original regexp-string
|
||||||
app.config.linkcheck_ignore_redirects.pop(url)
|
app.config.linkcheck_allowed_redirects.pop(url)
|
||||||
|
|
||||||
|
|
||||||
def setup(app: Sphinx) -> Dict[str, Any]:
|
def setup(app: Sphinx) -> Dict[str, Any]:
|
||||||
@ -674,7 +674,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||||||
app.add_post_transform(HyperlinkCollector)
|
app.add_post_transform(HyperlinkCollector)
|
||||||
|
|
||||||
app.add_config_value('linkcheck_ignore', [], None)
|
app.add_config_value('linkcheck_ignore', [], None)
|
||||||
app.add_config_value('linkcheck_ignore_redirects', {}, None)
|
app.add_config_value('linkcheck_allowed_redirects', {}, None)
|
||||||
app.add_config_value('linkcheck_auth', [], None)
|
app.add_config_value('linkcheck_auth', [], None)
|
||||||
app.add_config_value('linkcheck_request_headers', {}, None)
|
app.add_config_value('linkcheck_request_headers', {}, None)
|
||||||
app.add_config_value('linkcheck_retries', 1, None)
|
app.add_config_value('linkcheck_retries', 1, None)
|
||||||
@ -687,7 +687,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||||||
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, None)
|
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, None)
|
||||||
app.add_config_value('linkcheck_warn_redirects', False, None)
|
app.add_config_value('linkcheck_warn_redirects', False, None)
|
||||||
|
|
||||||
app.connect('config-inited', compile_linkcheck_ignore_redirects, priority=800)
|
app.connect('config-inited', compile_linkcheck_allowed_redirects, priority=800)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'version': 'builtin',
|
'version': 'builtin',
|
||||||
|
@ -300,9 +300,9 @@ def test_linkcheck_warn_redirects(app, warning):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True,
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True,
|
||||||
confoverrides={
|
confoverrides={
|
||||||
'linkcheck_ignore_redirects': {'http://localhost:.*/': '.*'}
|
'linkcheck_allowed_redirects': {'http://localhost:.*/': '.*'}
|
||||||
})
|
})
|
||||||
def test_linkcheck_ignore_redirects(app):
|
def test_linkcheck_allowed_redirects(app):
|
||||||
with http_server(make_redirect_handler(support_head=False)):
|
with http_server(make_redirect_handler(support_head=False)):
|
||||||
app.build()
|
app.build()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user