-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Warn on all redirects if linkcheck_allowed_redirects
is an empty dictionary
#13452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn on all redirects if linkcheck_allowed_redirects
is an empty dictionary
#13452
Conversation
config.linkcheck_allowed_redirects = None | ||
return | ||
if not isinstance(config.linkcheck_allowed_redirects, dict): | ||
raise ConfigError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing an explanatory message here?
Perhaps we should update the default |
@@ -178,7 +179,7 @@ def process_result(self, result: CheckResult) -> None: | |||
text = 'with unknown code' | |||
linkstat['text'] = text | |||
redirection = f'{text} to {result.message}' | |||
if self.config.linkcheck_allowed_redirects: | |||
if self.config.linkcheck_allowed_redirects is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line/diff is confusing without context -- but the way I understand this: this code is within the _Status.REDIRECTED
case -- and we can only reach this part of the code if a disallowed redirect occurred, or if no filtering of allowed redirects is configured. So the conditional check here is a shortcut, simply confirming whether allowed redirects are configured or not; if it is configured, we should emit a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me. I'll open a pull request with the two nitpicky suggestions I had (an update default in the config docs, and an exception message).
Hi. Is it possible that this PR introduced a regression? We see a new failure at astropy/sphinx-astropy#80 for sphinx-dev but we have no changed anything related to linkcheck lately. The only specific linkcheck setting we touch is this at https://github.com./astropy/sphinx-astropy/blob/9ee5275a8ccc09f434dc54f66993dbd0356d7200/sphinx_astropy/conf/v2.py#L386 linkcheck_timeout = 60 So the warning below is unexpected unless I missed something?
Hope you can advise. Thanks! |
Thanks @pllim for reporting this - that does seem likely to be related to this pull request, yep. I would have expected the config to use the default sentinel value for |
Thank you for your reply. I opened #13462 |
Thanks @pllim - I'll aim to investigate that within the next day or two. |
Note: two of our existing
Patching them so that --- a/tests/test_builders/test_build_linkcheck.py
+++ b/tests/test_builders/test_build_linkcheck.py
@@ -712,6 +712,7 @@ def log_date_time_string(self):
)
def test_follows_redirects_on_HEAD(app, capsys):
with serve_application(app, make_redirect_handler(support_head=True)) as address:
+ compile_linkcheck_allowed_redirects(app, app.config)
app.build()
_stdout, stderr = capsys.readouterr()
content = (app.outdir / 'output.txt').read_text(encoding='utf8')
@@ -735,6 +736,7 @@ def test_follows_redirects_on_HEAD(app, capsys):
)
def test_follows_redirects_on_GET(app, capsys):
with serve_application(app, make_redirect_handler(support_head=False)) as address:
+ compile_linkcheck_allowed_redirects(app, app.config)
app.build()
_stdout, stderr = capsys.readouterr()
content = (app.outdir / 'output.txt').read_text(encoding='utf8') That's a rough edge in the existing linkcheck builder testsuite -- ideally we'd not require test authors to include that step themselves (it can easily be omitted). |
Purpose
See discussion in #13439, cc @jameslamb.
References
linkcheck_allowed_redirects
is non-empty #13439