Skip to content

fix: add PyInstaller hook for rich library Unicode data on macOS#40

Open
Hazzzzzzzzze wants to merge 1 commit intomonad-developers:mainfrom
Hazzzzzzzzze:fix/pyinstaller-rich-unicode-macos
Open

fix: add PyInstaller hook for rich library Unicode data on macOS#40
Hazzzzzzzzze wants to merge 1 commit intomonad-developers:mainfrom
Hazzzzzzzzze:fix/pyinstaller-rich-unicode-macos

Conversation

@Hazzzzzzzzze
Copy link

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:158 when calling console.print(tx_table) to display the transaction results.

Root Cause

The rich library 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 required rich._unicode_data modules are not included in the executable bundle.

Solution

Added a PyInstaller hook (staking-cli/hooks/hook-rich.py) that explicitly instructs PyInstaller to collect all rich submodules, including the dynamically-imported Unicode data modules.

This follows the same pattern as the existing hook-py_ecc.py in the hooks directory.

Testing

  • ✅ Built executable successfully with pyinstaller --additional-hooks-dir=./hooks
  • ✅ Verified executable runs and displays output correctly
  • ✅ Confirmed rich._unicode_data module is included in build artifacts
  • ✅ No changes to dependencies or existing functionality

Files Changed

  • Added: staking-cli/hooks/hook-rich.py

@greptile-apps
Copy link

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR adds a minimal PyInstaller hook (staking-cli/hooks/hook-rich.py) that resolves a ModuleNotFoundError crash on macOS when the bundled executable attempts to display transaction results using rich's console.print(). The fix correctly uses collect_submodules('rich') to force PyInstaller to include all rich submodules—particularly rich._unicode_data.*—which are dynamically imported at runtime for emoji cell-width calculations and are otherwise invisible to PyInstaller's static analysis.

  • The hook uses the appropriate PyInstaller utility (collect_submodules) since the missing items are Python modules, not data files.
  • No functional logic, dependencies, or existing behavior is changed; this is purely a build-tooling fix.
  • The fix directly and correctly addresses the described root cause without introducing any runtime risk.

Confidence Score: 5/5

  • This PR is safe to merge — it adds a single, well-scoped PyInstaller hook with no risk to runtime logic.
  • The change is a 6-line build-tooling file that uses a standard, well-documented PyInstaller utility (collect_submodules). It introduces no new runtime code, modifies no existing logic, and directly addresses the described root cause of the ModuleNotFoundError.
  • No files require special attention.

Sequence Diagram

sequenceDiagram
    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 ✅
Loading

Last reviewed commit: 18f14ee

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.

1 participant