Skip to content

Fix packaged builds: bundle leapp_functions & assets, resolve report assets when frozen#1646

Open
abrignoni wants to merge 1 commit into
mainfrom
fix-pyinstaller-frozen-assets
Open

Fix packaged builds: bundle leapp_functions & assets, resolve report assets when frozen#1646
abrignoni wants to merge 1 commit into
mainfrom
fix-pyinstaller-frozen-assets

Conversation

@abrignoni

Copy link
Copy Markdown
Owner

Problem

Building the CLI from scripts/pyinstaller/ileapp_macOS.spec on current main produces a broken binary. Two independent bugs, plus a size issue:

1. leapp_functions is not bundled → plugin loader crashes on startup

scripts/artifacts/apple_atx_images.py does:

from leapp_functions.parsers.apple_atx import decode_atx_file

Artifacts are loaded dynamically (plugin_loader.py), so PyInstaller's static analysis never sees leapp_functions and doesn't bundle it. Running the packaged binary:

ModuleNotFoundError: No module named 'leapp_functions.parsers'
[ileapp] Failed to execute script 'ileapp' due to unhandled exception!

This aborts the whole run (the loader imports every artifact at startup).

2. Report assets are resolved from Path.cwd() → no icons in a packaged binary

scripts/report.py loads its Tabler icons and correction JSON with paths relative to the current working directory:

Path.cwd().joinpath("assets/tabler_icons")
get_json_file_content('scripts/data/tabler_icon_correction.json')

That only works when iLEAPP is launched from the repo root. A packaged binary run from anywhere else logs:

Error: JSON file 'scripts/data/tabler_icon_correction.json' not found.
Error: File '.../assets/tabler_icons/home.svg' not found.

and generates a report with missing icons. The three CLI specs also never bundled assets/ at all (the GUI specs already do).

3. Size — unused heavy libs bundled

scipy, matplotlib, and pyarrow are imported by zero iLEAPP files (they come in transitively via pandas). They add a lot to the binary for nothing.

Fix

  • scripts/report.py — resolve assets/ and scripts/data/ from sys._MEIPASS when frozen, falling back to cwd from source (no behavior change when run from source). New _base_dir() helper.
  • All six specs (ileapp[_macOS/_Linux].spec, ileappGUI[_macOS/_Linux].spec) — add leapp_functions to datas + a hidden import for leapp_functions.parsers.apple_atx, and put the repo root on pathex so analysis can find it.
  • CLI specs — also bundle assets/ (the GUI specs already did).
  • All six specs — add scipy, matplotlib, pyarrow to excludes.

Testing

Built the macOS CLI (ileapp_macOS.spec) and verified end-to-end:

  • Loads all 295 artifacts, including apple_atx_images, with no import error.
  • Full parse of a test extraction from an unrelated working directory: report generates with Tabler icons rendered and no missing-asset errors.

The other five specs received the analogous change but were not built in this environment (no Windows/Linux here). They share the identical gaps, so the same fix applies.

…assets from _MEIPASS

PyInstaller CLI/GUI builds from main were broken:

1. leapp_functions not bundled. The apple_atx_images artifact imports
   leapp_functions.parsers.apple_atx; since artifacts load dynamically,
   PyInstaller never sees it, so the plugin loader crashed at startup with
   ModuleNotFoundError. Added leapp_functions to datas + a hidden import and
   put the repo root on pathex, on all six specs.

2. Report assets unreachable. report.py resolved assets/tabler_icons and
   scripts/data/*.json via Path.cwd(), which only works when run from the repo.
   A packaged binary launched elsewhere logged 'file not found' and produced a
   report with no icons. It now resolves from sys._MEIPASS when frozen. The CLI
   specs also did not bundle assets/ at all; added it (GUI specs already did).

3. Size. Excluded scipy, matplotlib and pyarrow (pulled in transitively via
   pandas but imported by zero iLEAPP files) to shrink the binaries.

Verified: built the macOS CLI from ileapp_macOS.spec, loaded all 295 artifacts
with no import error, and ran a full parse from an unrelated working directory
with icons rendered and no missing-asset errors. The other five specs received
the analogous change (not built here).
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