Repository navigation
Keep the translation folder valid for keys i18n loads later - #374
Merged
Merged
Conversation
main.py and the Whisper worker added the folder from
impres.as_file(impres.files("trans")) to i18n's load path. That is a
temporary copy, deleted when the with block ends, so the first lookup
of a key that is not memoized yet (a missing key, or the fallback to
"en") crashed with FileNotFoundError.
Add utils.translations_dir(), which returns the real folder of
noScribe.en.yml, and use it in both places.
Fixes kaixxx#368
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Owner
|
Thanks, @cristianchiriac and @happyarts. This looks good. I'll merge and test. |
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.
Fixes #368.
main.pyandwhisper_mp_worker.pyadded the folder fromimpres.as_file(impres.files("trans"))toi18n.load_path. Becausetrans/has no__init__.py,files("trans")returns aMultiplexedPath, andas_file()copies the folder into a temp directory that is deleted when thewithblock exits. python-i18n reads the load path again for any key it has not memoized yet, such as a missing key or the first fallback toen. That lookup then crashed withFileNotFoundErroron the deleted temptransfolder.The fix uses the approach @happyarts posted in the issue (thanks also to @omaer0 for the report and the first
_pathsworkaround). The newutils.translations_dir()returnsstr((impres.files("trans") / "noScribe.en.yml").parent). Joining a file name on theMultiplexedPathgives the real file, so there is no temporary copy, and if more than onetransfolder were on the path it picks the one that actually holds the.ymlfiles. Both call sites now use the helper. It doesn't use the private_pathsattribute.Testing:
tests/test_translations_dir.pyonly needs python-i18n and PyYAML, not torch or whisper. It checks that the returned folder still containsnoScribe.en.yml, that a missing key returns the key name for bothenanddewithout crashing, and that neither call site still usesas_fileontrans.as_filebehaviour, the folder test and both missing-key tests fail. The missing-key tests fail with theFileNotFoundErrorfrom the issue.tests/test_worker_import_lightweight.pystill passes for the worker modules.I haven't tried a frozen PyInstaller build.
trans/is bundled there as a real folder, so it should behave the same.