Fix pyphen hook: use original NVDA approach#244
Merged
Conversation
The original bootcode patched pyphen.dictionaries after importing pyphen,
but pyphen.__init__ populates LANGUAGES at module level during import,
so the patch was always too late.
Fix: inject a fake pyphen.dictionaries module into sys.modules before
pyphen is imported. Uses a _DicLoader whose .path tricks FileReader into
resolving importlib.resources.files('pyphen.dictionaries') to the
pyphenDictionaries/ directory next to the frozen executable.
Add tests/functional/pyphen_test/ to verify the hook works end-to-end
in a frozen binary.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
5 tasks
Member
|
I appreciate the test. However, the hook now seems fairly convoluted. I wonder if patching the |
Contributor
Author
|
Replaced bootcode + fake module injection with AST transformation, matching the |
Member
|
Thanks for this, I will try to prepare a patch release over the weekend. |
Member
|
@LeonarddeR I just released this fix in version 0.14.1.1 |
Contributor
Author
|
Thank you very much! |
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.
The original hook added in #242 patched
pyphen.dictionariesafter importingpyphenvia bootcode, butpyphen.__init__populatesLANGUAGESat module level on import — so the patch always ran too late.Root cause
importlib.resources.files('pyphen.dictionaries')requires a module insys.moduleswith a loader implementingget_resource_reader().files(). Inside a frozen binary,pyphen.dictionariesis never imported so no such module exists.Fix
Bootcode injects a minimal fake
pyphen.dictionariesmodule intosys.modulesbeforepyphenis imported. Its loader'sget_resource_reader()returns an object whosefiles()yieldsPath(pyphenDictionaries/)next to the executable — exactly whatresources.files()expects.pyphen.LANGUAGESthen populates correctly at import time.Adds
tests/functional/pyphen_test/to verify end-to-end in a frozen binary.