Skip to content

Add hook for pyphen#242

Merged
albertosottile merged 1 commit into
py2exe:masterfrom
LeonarddeR:master
Jun 1, 2026
Merged

Add hook for pyphen#242
albertosottile merged 1 commit into
py2exe:masterfrom
LeonarddeR:master

Conversation

@LeonarddeR

@LeonarddeR LeonarddeR commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds hook_pyphen to bundle hyph_*.dic dictionary files next to the frozen executable
  • Patches pyphen.dictionaries at runtime via bootcode so pyphen resolves dictionaries from the correct path instead of the non-functional importlib.resources / __file__ paths inside library.zip

Problem

pyphen locates its dictionary files at module init time via:

try:
    dictionaries = resources.files('pyphen.dictionaries')
except TypeError:
    dictionaries = Path(__file__).parent / 'dictionaries'

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 result pyphen.LANGUAGES is empty and hyphenation does not work.

Solution

The hook:

  1. Copies every hyph_*.dic file from pyphen's dictionaries/ folder into pyphenDictionaries/ next to the executable via finder.add_datafile
  2. Injects bootcode that sets pyphen.dictionaries to Path(os.path.dirname(sys.executable)) / "pyphenDictionaries" after pyphen is imported

See also nvaccess/nvda#20145

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>
@albertosottile

albertosottile commented May 31, 2026

Copy link
Copy Markdown
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?

@LeonarddeR

Copy link
Copy Markdown
Contributor Author

Thanks @albertosottile.
It would be acceptable for me, but if you can give some directions/examples on how to add proper CI tests, I'd be more than happy to do so.

@albertosottile

Copy link
Copy Markdown
Member

You can find test examples in the tests/functional folder. For now I would merge this PR as it is, since I intend to make a release rather soon.

@albertosottile albertosottile merged commit 19fa932 into py2exe:master Jun 1, 2026
22 checks passed
@LeonarddeR

Copy link
Copy Markdown
Contributor Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants