Skip to content

Commit 733e8b1

Browse files
authored
PYTHON-5847 Fix intermittent linkcheck failures due to rate-limiting (#2833)
1 parent 0ad3c2f commit 733e8b1

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

.github/workflows/test-python.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ jobs:
172172
run: just install
173173
- name: Build docs
174174
run: just docs-linkcheck
175+
env:
176+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175177

176178
typing:
177179
name: Typing Tests

doc/conf.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This file is execfile()d with the current directory set to its containing dir.
55
from __future__ import annotations
66

7+
import os
78
import sys
89
from pathlib import Path
910

@@ -86,18 +87,28 @@
8687
# sourceforge.net is giving a 403 error, but is still accessible from the browser.
8788
# Links to release notes in jira give 401 error: unauthorized. PYTHON-5585
8889
linkcheck_ignore = [
89-
"https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.md#requesting-an-immediate-check",
90-
"https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback",
91-
"https://github.com/mongodb/specifications/blob/master/source/uri-options/uri-options.md",
92-
"https://github.com/mongodb/specifications/blob/master/source/uri-options/uri-options.md",
93-
"https://github.com/mongodb/libmongocrypt/blob/master/bindings/python/README.rst#installing-from-source",
9490
r"https://wiki.centos.org/[\w/]*",
9591
r"https://sourceforge.net/",
9692
r"https://jira\.mongodb\.org/secure/ReleaseNote\.jspa.*",
9793
]
9894

9995
# Allow for flaky links.
10096
linkcheck_retries = 3
97+
# Serialize requests to dochub.mongodb.org to avoid rate-limiting (PYTHON-5847).
98+
linkcheck_workers = 1
99+
# Give slow redirects more time before retrying.
100+
linkcheck_timeout = 60
101+
102+
# Ignore anchors in links since they may not be added to the page right away.
103+
linkcheck_anchors_ignore_for_url = [r"https://github.com/.*"]
104+
105+
# Pass GitHub token to avoid rate-limiting on GitHub links.
106+
if github_token := os.environ.get("GITHUB_TOKEN"):
107+
linkcheck_request_headers = {
108+
"https://github.com/": {"Authorization": f"token {github_token}"},
109+
"https://api.github.com/": {"Authorization": f"token {github_token}"},
110+
}
111+
101112

102113
# -- Options for extensions ----------------------------------------------------
103114
autoclass_content = "init"

0 commit comments

Comments
 (0)