-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RTD: Add compatibility fixes for upstream changes at Read The Docs #535
Conversation
When invoking Sphinx standalone, we need to preconfigure a few variables to make the RTD compatibility package work.
cc9f865
to
f02303c
Compare
sphinx-build-compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a stack!
... to permit publishing `crate-docs-theme` to PyPI.
... after switching to new GitHub Issues.
... to respect `linkcheck_anchors_ignore_for_url` configuration setting, needed for handling new GitHub Issues.
# We are using APIv2 to pull active versions, downloads and subprojects | ||
# because APIv3 requires a token. | ||
try: | ||
response_versions = requests.get( | ||
f"{scheme}://{production_domain}/api/v2/version/?project__slug={project_slug}&active=true", | ||
timeout=2, | ||
).json() | ||
versions = [ | ||
(version["slug"], f"/{version['project']['language']}/{version['slug']}/") | ||
for version in response_versions["results"] | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the preview for crate-reference, intending to restore the version chooser, it looks like this now:
Now, the question is if it will be all good on the live site, or if it will also start displaying all the PR builds, for whatever reason, which we certainly want to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yeah. It would probably also happen on the live site. Why does this always happen to me?
$ http 'https://readthedocs.org/api/v2/version/?project__slug=crate&active=true' | jq '.results[].slug'
"master"
"latest"
"5.8"
"5.7"
"4.8"
"3.3"
"16732"
"16731"
"16729"
"16728"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe APIv2 has a bug, but I couldn't figure out the right parameters.
APIv3 however works well, like before, so we will just update the URL pattern accordingly.
$ http 'https://readthedocs.org/api/v3/projects/crate/versions/?active=true' | jq '.results[].slug'
"master"
"latest"
"5.8"
"5.7"
"4.8"
"3.3"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c0c0929 adds a fix by adjusting the RTD compat layer. Now, this spot looks like before.
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.
# 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/v3/projects/{project_slug}/versions/?active=true", | ||
timeout=2, | ||
).json() | ||
versions = [ | ||
(version["slug"], f"/{language}/{version['slug']}/") | ||
for version in response_versions["results"] | ||
] | ||
except Exception: | ||
logger.warning( | ||
"An error ocurred when hitting API to fetch active versions. Defaulting to an empty list.", | ||
exc_info=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fragment has been adjusted to yield better results for this theme, see #535 (review).
About
https://about.readthedocs.com/blog/2024/07/addons-by-default/
References