Add hook for pyphen#242
Merged
Merged
Conversation
5 tasks
pyphen locates its dictionary files via importlib.resources or __file__, neither of which resolves inside a frozen library.zip. This hook copies hyph_*.dic files next to the executable and patches pyphen.dictionaries at runtime to point there. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Member
|
Hi, thanks for this contribution. Since CI is passing, I can merge this PR now and include the hook in the upcoming release (0.14.1.0). However, bear in mind that this hook will not be tested in CI. Is this acceptable for you? |
Contributor
Author
|
Thanks @albertosottile. |
Member
|
You can find test examples in the |
Contributor
Author
|
Thanks. |
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
hook_pyphento bundlehyph_*.dicdictionary files next to the frozen executablepyphen.dictionariesat runtime via bootcode so pyphen resolves dictionaries from the correct path instead of the non-functionalimportlib.resources/__file__paths insidelibrary.zipProblem
pyphen locates its dictionary files at module init time via:
After freezing, pyphen lives inside
library.zip.resources.files()fails silently or returns a broken path, and__file__no longer points to the filesystem. As a resultpyphen.LANGUAGESis empty and hyphenation does not work.Solution
The hook:
hyph_*.dicfile from pyphen'sdictionaries/folder intopyphenDictionaries/next to the executable viafinder.add_datafilepyphen.dictionariestoPath(os.path.dirname(sys.executable)) / "pyphenDictionaries"after pyphen is importedSee also nvaccess/nvda#20145