Skip to content
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

Merged
merged 9 commits into from
Oct 8, 2024

Conversation

msbt
Copy link
Collaborator

@msbt msbt commented Oct 8, 2024

About

References

@cla-bot cla-bot bot added the cla-signed label Oct 8, 2024
@msbt msbt requested a review from amotl October 8, 2024 14:11
msbt and others added 2 commits October 8, 2024 17:17
@amotl amotl force-pushed the msbt/rtd-addons-fix branch from cc9f865 to f02303c Compare October 8, 2024 15:20
@amotl amotl changed the title add sphinx-build-compatibility RTD: Add compatibility fixes for upstream changes at Read The Docs Oct 8, 2024
Copy link
Member

@amotl amotl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a stack!

setup.py Outdated Show resolved Hide resolved
... to permit publishing `crate-docs-theme` to PyPI.
amotl added 2 commits October 8, 2024 18:44
... after switching to new GitHub Issues.
... to respect `linkcheck_anchors_ignore_for_url` configuration setting,
needed for handling new GitHub Issues.
Comment on lines 56 to 66
# 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"]
]
Copy link
Member

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:

Image

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.

Copy link
Member

@amotl amotl Oct 8, 2024

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"

Copy link
Member

@amotl amotl Oct 8, 2024

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"

Copy link
Member

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.

image

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.
Comment on lines +56 to +84
# 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,
)
Copy link
Member

@amotl amotl Oct 8, 2024

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).

@amotl amotl merged commit 1199810 into main Oct 8, 2024
9 checks passed
@amotl amotl deleted the msbt/rtd-addons-fix branch October 8, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants