fix: add PyInstaller hook for rich library Unicode data on macOS#40
Open
Hazzzzzzzzze wants to merge 1 commit intomonad-developers:mainfrom
Open
fix: add PyInstaller hook for rich library Unicode data on macOS#40Hazzzzzzzzze wants to merge 1 commit intomonad-developers:mainfrom
Hazzzzzzzzze wants to merge 1 commit intomonad-developers:mainfrom
Conversation
Greptile SummaryThis PR adds a minimal PyInstaller hook (
Confidence Score: 5/5
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant PyInstaller
participant Hook as hooks/hook-rich.py
participant RichLib as rich library
participant Exe as Bundled Executable
Dev->>PyInstaller: pyinstaller --additional-hooks-dir=./hooks main.py
PyInstaller->>Hook: Load hook-rich.py
Hook->>RichLib: collect_submodules('rich')
RichLib-->>Hook: [rich.console, rich.table, rich._unicode_data.*, ...]
Hook-->>PyInstaller: hiddenimports list
PyInstaller->>Exe: Bundle all rich submodules
Note over Exe: rich._unicode_data.unicode* modules included
Exe-->>Dev: console.print(tx_table) succeeds ✅
Last reviewed commit: 18f14ee |
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.
Problem
When running the PyInstaller-built executable on macOS during validator registration, the CLI
crashes after successfully completing the transaction:
ModuleNotFoundError: No module named 'rich._unicode_data.unicode17-0-0'
[PYI-76623:ERROR] Failed to execute script 'main' due to unhandled exception!
Important: The validator registration completes successfully on-chain. The error only prevents displaying the transaction confirmation message.
Error Location
The crash occurs at
staking-cli/src/add_validator.py:158when callingconsole.print(tx_table)to display the transaction results.Root Cause
The
richlibrary dynamically imports Unicode data modules at runtime to calculate cell widths for emoji characters (✅ and ❌ in the transaction table). PyInstaller's static analysis doesn't detect these dynamic imports, so the requiredrich._unicode_datamodules are not included in the executable bundle.Solution
Added a PyInstaller hook (
staking-cli/hooks/hook-rich.py) that explicitly instructs PyInstaller to collect allrichsubmodules, including the dynamically-imported Unicode data modules.This follows the same pattern as the existing
hook-py_ecc.pyin the hooks directory.Testing
pyinstaller --additional-hooks-dir=./hooksrich._unicode_datamodule is included in build artifactsFiles Changed
staking-cli/hooks/hook-rich.py