click_extra.sphinx.linkcheck moduleΒΆ
Sign the linkcheck requests to github.com with a CI token.
GitHub throttles anonymous requests to about one a minute, which overruns the
link check of a site with many links to github.com. When the environment holds
GITHUB_TOKEN_ENV, as a CI workflow sets it on its link-check step, the
requests to github.com carry that token. A local build has no token, so its
requests stay anonymous.
Release downloads stay anonymous: with an Authorization header, github.com
redirects them to the legacy objects.githubusercontent.com host, whose signed
URL answers 401. A page linking one download per released binary would then
report every one of them as broken. linkcheck_auth carries the exception
because its patterns are regular expressions, where linkcheck_request_headers
matches whole hosts only.
- click_extra.sphinx.linkcheck.GITHUB_TOKEN_ENV = 'GITHUB_TOKEN'ΒΆ
Environment variable holding the token the requests to github.com carry.
- click_extra.sphinx.linkcheck.GITHUB_URL_PATTERN = 'https://github\\.com/(?!.*/releases/(?:latest/)?download/)'ΒΆ
URLs the token signs: every page of github.com, but a release download.
- click_extra.sphinx.linkcheck.github_bearer_auth(request)[source]ΒΆ
Sign
requestwith the tokenGITHUB_TOKEN_ENVholds.The token is read when the request goes out. A function also stays out of the build environment Sphinx pickles, where an object holding the token would have written it to disk.
- Return type:
PreparedRequest- Returns:
the request, as
requestsexpects from anauthcallable.
- click_extra.sphinx.linkcheck.add_github_auth(app, config)[source]ΒΆ
Append the github.com entry to
linkcheck_auth, if a token is set.The entry goes after the ones
conf.pydeclares. Sphinx signs a request with the first entry whose pattern matches its URL, so a project entry keeps precedence.- Return type:
- click_extra.sphinx.linkcheck.setup(app)[source]ΒΆ
Register the github.com authentication on
app.Called from
click_extra.sphinx.setup()so projects only need to list"click_extra.sphinx"in theirextensions.config-initedfires onceconf.pyis read, so its ownlinkcheck_authentries come first.- Return type: