fix(translation_graph): prevent CI failure when writing translation stats#651
Open
dimasd-angga wants to merge 1 commit into
Open
Conversation
…tats The translation stats writer assumed `_static` existed and that a stats file should always be produced, causing `FileNotFoundError` in CI when the build errored or no `.po` files were present. Skip the write on build failure or empty stats, and ensure the output directory exists before writing so translated-language Sphinx builds finish cleanly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Translated-language Sphinx builds in CI were failing with
FileNotFoundErrorwhenwrite_translation_statstried to open_static/translation_stats.json. The hook assumed the_staticdirectory already existed and that stats should always be written, which isn't true when the build errored before Sphinx materialised the output tree or when no.pofiles were collected. This PR makes the writer defensive in those two cases and ensures the parent directory is created before opening the file.Changes
_ext/translation_graph.py, early-return fromwrite_translation_statswhen Sphinx passes a non-Noneexception, so a failed build doesn't trigger a second failure inside thebuild-finishedhook.get_translation_stats()returns no entries, instead of writing an empty stats file for builds that have no translation sources.app.outdirinPath(...)and callout_path.parent.mkdir(parents=True, exist_ok=True)before writing, so the_staticdirectory is guaranteed to exist regardless of build configuration.Testing
Ran
nox -s docs-testlocally; the suite completes without theFileNotFoundErrorpreviously seen in CI. No new tests were added — the change is a guard inside a Sphinxbuild-finishedcallback, and the existing docs build exercises the path.Notes
The two new early-returns log at
infolevel so it's still visible in CI output when stats are skipped, which should make future debugging easier without changing the build outcome.Closes #649