Skip to content

Commit 57744f4

Browse files
committed
Improve sphinx-build-compatibility not calling RTD API on link checks
1 parent 1056414 commit 57744f4

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

src/crate/theme/vendor/rtd_compat/extension.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
from sphinx import version_info
45
from sphinx.util import logging
@@ -61,21 +62,25 @@ def manipulate_config(app, config):
6162
language = "en"
6263

6364
# Project versions. Acquire them from RTD's API.
64-
try:
65-
response_versions = requests.get(
66-
f"{scheme}://{production_domain}/api/v3/projects/{project_slug}/versions/?active=true",
67-
timeout=2,
68-
).json()
69-
versions = [
70-
(version["slug"], f"/{language}/{version['slug']}/")
71-
for version in response_versions["results"]
72-
]
73-
except Exception:
74-
logger.warning(
75-
"An error ocurred when hitting API to fetch active versions. Defaulting to an empty list.",
76-
exc_info=True,
77-
)
78-
versions = []
65+
# Note this skips acquiring project versions when running the link checker.
66+
# This avoids hammering the RTD API when rebuilding _all_ docs.
67+
versions = []
68+
if "linkcheck" not in sys.argv:
69+
try:
70+
response_versions = requests.get(
71+
f"{scheme}://{production_domain}/api/v3/projects/{project_slug}/versions/?active=true",
72+
timeout=2,
73+
).json()
74+
versions = [
75+
(version["slug"], f"/{language}/{version['slug']}/")
76+
for version in response_versions["results"]
77+
]
78+
except Exception:
79+
logger.warning(
80+
"An error occurred when hitting API to fetch active versions. Defaulting to an empty list.",
81+
exc_info=True,
82+
)
83+
versions = []
7984

8085
# Project downloads. What are they?
8186
downloads = []

0 commit comments

Comments
 (0)