Skip to content

Commit

Permalink
RTD: Fix inquiring active project versions
Browse files Browse the repository at this point in the history
The `sphinx-build-compatibility` code needed to be improved where
inquiring project metadata.

The v2 API returns or started returning inactive builds (PR numbers) in
inquiries to active project versions. The v3 API works much better.

The project language will be inquired separately.
  • Loading branch information
amotl committed Oct 8, 2024
1 parent 4c01af2 commit f6956a4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/crate/theme/vendor/rtd_compat/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,26 @@ def manipulate_config(app, config):

# We are using APIv2 to pull active versions, downloads and subprojects
# because APIv3 requires a token.
try:
response_project = requests.get(
f"{scheme}://{production_domain}/api/v3/projects/{project_slug}/",
timeout=2,
).json()
language = response_project["language"]["code"]
except Exception:
logger.warning(
"An error ocurred when hitting API to fetch project language. Defaulting to 'en'.",
exc_info=True,
)
language = "en"

try:
response_versions = requests.get(
f"{scheme}://{production_domain}/api/v2/version/?project__slug={project_slug}&active=true",
f"{scheme}://{production_domain}/api/v3/projects/{project_slug}/versions/?active=true",
timeout=2,
).json()
versions = [
(version["slug"], f"/{version['project']['language']}/{version['slug']}/")
(version["slug"], f"/{language}/{version['slug']}/")
for version in response_versions["results"]
]
except Exception:
Expand Down

0 comments on commit f6956a4

Please sign in to comment.