Skip to content

Commit 1d58235

Browse files
committed
Improve sphinx-build-compatibility to make less requests to RTD's API
1 parent a791490 commit 1d58235

File tree

2 files changed

+10
-56
lines changed

2 files changed

+10
-56
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGES
55

66
Unreleased
77
----------
8+
- Improved vendorised ``sphinx-build-compatibility`` to make less requests to RTD's API
89

910
2025/03/20 0.38.3
1011
-----------------

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

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,12 @@ def manipulate_config(app, config):
5555

5656
# We are using APIv2 to pull active versions, downloads and subprojects
5757
# because APIv3 requires a token.
58-
try:
59-
response_project = requests.get(
60-
f"{scheme}://{production_domain}/api/v3/projects/{project_slug}/",
61-
timeout=2,
62-
).json()
63-
language = response_project["language"]["code"]
64-
except Exception:
65-
logger.warning(
66-
"An error ocurred when hitting API to fetch project language. Defaulting to 'en'.",
67-
exc_info=True,
68-
)
69-
language = "en"
7058

59+
# Project language.
60+
# Do not inquire the RTD API for the project language. We can safely just use English.
61+
language = "en"
62+
63+
# Project versions. Acquire them from RTD's API.
7164
try:
7265
response_versions = requests.get(
7366
f"{scheme}://{production_domain}/api/v3/projects/{project_slug}/versions/?active=true",
@@ -84,51 +77,11 @@ def manipulate_config(app, config):
8477
)
8578
versions = []
8679

87-
try:
88-
downloads = []
89-
for version in response_versions["results"]:
90-
if version["slug"] != version_slug:
91-
continue
92-
93-
for key, value in version["downloads"]:
94-
downloads.append(
95-
(
96-
key,
97-
value,
98-
),
99-
)
100-
except Exception:
101-
logger.warning(
102-
"An error ocurred when generating the list of downloads. Defaulting to an empty list.",
103-
exc_info=True,
104-
)
105-
downloads = []
106-
107-
try:
108-
subprojects = []
109-
response_project = requests.get(
110-
f"{scheme}://{production_domain}/api/v2/project/?slug={project_slug}",
111-
timeout=2,
112-
).json()
113-
project_id = response_project["results"][0]["id"]
80+
# Project downloads. What are they?
81+
downloads = []
11482

115-
response_subprojects = requests.get(
116-
f"{scheme}://readthedocs.org/api/v2/project/{project_id}/subprojects/",
117-
timeout=2,
118-
).json()
119-
for subproject in response_subprojects["subprojects"]:
120-
subprojects.append(
121-
(
122-
subproject["slug"],
123-
subproject["canonical_url"],
124-
),
125-
)
126-
except Exception:
127-
logger.warning(
128-
"An error ocurred when hitting API to fetch project/subprojects. Defaulting to an empty list.",
129-
exc_info=True,
130-
)
131-
subprojects = []
83+
# Subprojects. We don't use them.
84+
subprojects = []
13285

13386
# Add project information to the template context.
13487
context = {

0 commit comments

Comments
 (0)