Skip to content

Shrink win install - #2346

Merged
amilcarlucas merged 2 commits into
masterfrom
shrink_win_install
Nov 9, 2026
Merged

amilcarlucas merged 2 commits into
masterfrom
shrink_win_install

Conversation

@amilcarlucas

Copy link
Copy Markdown
Collaborator

Description

Do not ship unused files

Checklist

  • Run pre-commit checks locally
  • Verified by a human programmer
  • All commits are signed off (use git commit --signoff)
  • Code follows our coding standards
  • Documentation updated if needed
  • No breaking changes or properly documented

Testing

Describe how you tested these changes:

  • Unit tests pass
  • Integration tests pass
  • Manual testing performed
  • Tested on flight controller hardware

Copilot AI balanced review requested due to automatic review settings November 9, 2026 01:41
@amilcarlucas amilcarlucas added the AIReview Request an automated AI review; picked up by the reviewprs sweep label Nov 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Reduces PyInstaller bundle size by excluding unused pymavlink dialects and trimming platform-irrelevant / unused packaged files from the build artifacts.

Changes:

  • Filter pymavlink hidden imports to only include required MAVLink dialects and exclude the rest explicitly.
  • Exclude lxml and prune unnecessary binaries/data (e.g., non-target selenium-manager binaries, unused PIL/matplotlib assets).
  • Tighten collected package data on macOS/Linux by excluding translation sources and build artifacts.
File Description
windows/​ardupilot_methodic_configurator.spec Filters pymavlink dialect modules, excludes lxml, and prunes unused binaries/datas (platform-specific + unused assets).
macos/​ardupilot_methodic_configurator.spec Adds re, narrows collected data files, filters pymavlink dialects, excludes lxml, and prunes unused binaries/datas.
linux/​ardupilot_methodic_configurator.spec Adds re, narrows collected data files, filters pymavlink dialects, excludes lxml, and prunes unused binaries/datas.

Review effort: Lite

Comment on lines +98 to +101
_UNUSED_FILE_PATTERNS = (
re.compile(r"(^|[\\/])PIL[\\/]_avif\.[^\\/]*$"), # AVIF images are not used
re.compile(r"(^|[\\/])matplotlib[\\/]mpl-data[\\/]fonts[\\/](afm|pdfcorefonts)[\\/]"), # only used by PostScript/PDF output
)
Comment on lines +40 to +46
# Pymavlink ships one large module per MAVLink dialect; the application only uses these.
USED_MAVLINK_DIALECTS = {"all", "ardupilotmega"}


def _is_unused_mavlink_dialect(module_name: str) -> bool:
parts = module_name.split(".")
return len(parts) >= 4 and parts[:2] == ["pymavlink", "dialects"] and parts[3] not in USED_MAVLINK_DIALECTS
Comment on lines +72 to +84
# Remove files that the application cannot use on this platform or does not need.
_UNUSED_PATH_PREFIXES = tuple(
os.path.join("selenium", "webdriver", "common", folder) + os.sep for folder in ("macos", "windows")
) # selenium wheels bundle selenium-manager for every OS
_UNUSED_FILE_PATTERNS = (
re.compile(r"(^|[\\/])PIL[\\/]_avif\.[^\\/]*$"), # AVIF images are not used
re.compile(r"(^|[\\/])matplotlib[\\/]mpl-data[\\/]fonts[\\/](afm|pdfcorefonts)[\\/]"), # only used by PostScript/PDF output
)


def _is_unused_file(entry: tuple) -> bool:
destination = os.path.normpath(entry[0])
return destination.startswith(_UNUSED_PATH_PREFIXES) or any(pattern.search(destination) for pattern in _UNUSED_FILE_PATTERNS)
@AP-Review

AP-Review commented Nov 9, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-09)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 316de3dad1.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2346/1.html#prMethodicConfigurator-2346

The size reductions work and the kept dialects, plugins and log validation still run in the frozen Linux build, but one environment-dependent startup crash should be fixed.

Should fix

  • linux/ardupilot_methodic_configurator.spec:41: with only all/ardupilotmega bundled, a user who has exported MAVLINK_DIALECT=common (or any other dialect) gets a startup crash, even for --version. pymavlink selects the dialect at import time and falls back to mavgen, which needs XML that is not bundled. The base build starts fine with the same setting. The same filter is in macos spec:52 and windows spec:66. Fix: have a frozen runtime hook or the entry point reset an unsupported MAVLINK_DIALECT to ardupilotmega before pymavlink is imported.
Minor (2)
  • linux/ardupilot_methodic_configurator.spec:77: dropping PIL/_avif leaves its 4.9 MB pillow.libs/libavif-*.so in the Linux bundle with no remaining user; adding a pattern for it would finish the saving.
  • linux/ardupilot_methodic_configurator.spec:38: release builds install the package non-editably and already ship only .mo files, so the .po/.pot exclusion only helps source-tree builds. build/**/dist/** match only top-level folders, which is narrower than the commit message says.

Copilot's missing import re concern on the Windows spec does not apply: it is already imported at line 9.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

☂️ Code Coverage

current status: ✅

Overall Coverage

Statements Covered Coverage Threshold Status
30665 29142 95% 89% 🟢

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: 8b78224 by action🐍

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

     3 files  ± 0       3 suites  ±0   40m 49s ⏱️ - 1m 13s
 9 526 tests +24   9 521 ✅ +24   5 💤 ±0  0 ❌ ±0 
28 446 runs  +72  28 411 ✅ +72  35 💤 ±0  0 ❌ ±0 

Results for commit 8b78224. ± Comparison against base commit 7fa9579.

♻️ This comment has been updated with latest results.

@AP-Review

AP-Review commented Nov 9, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-09)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 0950a70c95.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2346/2.html#prMethodicConfigurator-2346

The bundle shrink holds up and the frozen Linux build works; one CodeQL-flagged regex should still be simplified. This review is of head 0950a70c9, which moved from 316de3dad1. Since then the MAVLINK_DIALECT startup crash, the leftover libavif library and the narrow build/dist excludes have all been fixed.

Should fix

  • scripts/pyinstaller_spec_helpers.py:25: the libavif pattern nests (\.[^\\/]*)*. Since [^\\/] also matches ., a failing match backtracks exponentially (0.19 s at 22 dots, about 4x per two more), which is the py/redos alert keeping CodeQL red. so(\.[0-9]+)* in place of so(\.[^\\/]*)* gives the same results on the real Pillow names and runs in microseconds.
Minor (2)
  • .github/workflows/build_windows_macos.yml:203: only the Windows smoke step tests an unbundled dialect. Adding the same MAVLINK_DIALECT=common / --version check to the Linux and macOS smoke steps would cover the hook there.
  • Commit messages: 9211a9a does not mention that frozen builds now rewrite an unsupported MAVLINK_DIALECT to ardupilotmega. 0950a70 says the Linux selenium-manager binaries are kept, but only the build architecture's one is.

Not fully reviewed: native Windows and macOS frozen runs, Linux arm64, frozen GUI flows (FC connection, tuning plots, Selenium web tools) and the full GUI pytest suite were not exercised.

amilcarlucas and others added 2 commits November 9, 2026 13:22
…ries

The 5.1.0 installer grew by about 3.8 MB over 5.0.2 (62.3 -> 66.1 MB).
Inspecting the bundle showed that much of it is never used on Windows or
by the application at all:

- Pillow's _avif extension (7.5 MB): AVIF images are not used. Pillow
  treats the plug-in as optional and falls back cleanly.
- selenium-manager for Linux and macOS (about 17 MB): selenium wheels bundle
  one binary per OS, and only the Windows one can run. It is still used by
  the web log tools to locate the Chrome driver, so it is kept.
- lxml (6.7 MB): only imported lazily by pymavlink's dialect generator
  (mavgen) and its optional log-metadata parser, neither of which the
  application uses.
- 11 unused MAVLink dialect modules, in both the v10 and v20 variants
  (about 34 MB of source, a large part of the 26.9 MB exe):
  collect_submodules("pymavlink") bundled every dialect. Only "all"
  (mavutil's default dialect) and "ardupilotmega" (imported directly by the
  app) are kept.
- matplotlib afm/pdfcorefonts data (1.3 MB): only used by the PostScript
  and PDF backends.

Dialect modules are removed both from the hidden imports and through
Analysis(excludes=...) so that static imports cannot pull them back in.
Binaries and data are filtered in the TOC by destination path, so
the Windows selenium-manager.exe and the Tk/Pillow libraries that are
needed stay untouched.

Verified with a test PyInstaller build (Python 3.14 venv, so not a strict
before/after with the 3.15 installer): the removed files are absent, the
exe shrank from 26.9 MB to 19.7 MB, and the frozen exe runs --version,
--help and --validate-bin-log on tests/fixtures/backend_log_80k.bin.
The installer applies solid LZMA, which already deduplicates the similar
dialect files, so the final installer saving is expected to be a fraction
of the uncompressed numbers.

Signed-off-by: Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
The Linux and macOS specs bundled the same unused content that was removed
from the Windows spec:

- Every pymavlink MAVLink dialect (about 42 MB of source) through
  collect_submodules("pymavlink"). Only "all" (mavutil's default dialect)
  and "ardupilotmega" (imported directly by the app) are kept, in both the
  v10 and v20 variants. Unused dialects are removed from the hidden imports
  and through Analysis(excludes=...) so static imports cannot pull them back.
- lxml, which pymavlink imports only in its dialect generator and in an
  optional log-metadata parser that the application never uses.
- Pillow's _avif extension, because AVIF images are not used.
- matplotlib's afm and pdfcorefonts data, only used by PostScript/PDF output.
- selenium-manager binaries for the other operating systems. Linux keeps
  the linux* binaries and macOS keeps the macos one.
- The .po and .pot translation sources (about 5 MB), because collect_data_files
  shipped every non-Python file. Only the compiled .mo files are needed.

collect_data_files now also skips any build/ and dist/ directory inside the
package, so a previous local PyInstaller output is not bundled recursively.

Verified by building the Linux spec with Python 3.15.2 on a development
machine: the removed files are absent, the Linux selenium-manager binaries
are kept, and the frozen executable validates a sample .bin log. The macOS
spec received the identical change but could not be built there.

Signed-off-by: Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 8b78224093.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2346/3.html#prMethodicConfigurator-2346

Nothing blocking at head 8b7822409; only a commit-message nit is left. The head moved from 0950a70c9. Since then, the CodeQL-flagged libavif regex has been replaced with so(\.[0-9]+)* and a stall regression test, and the Linux and macOS smoke steps now also start the app with MAVLINK_DIALECT=common.

Minor (1)
  • Commit messages, wording (still open): 539d815 should mention that frozen builds now rewrite an unsupported MAVLINK_DIALECT to ardupilotmega. In 8b78224, "Linux keeps the linux* binaries" should say that only the build architecture's selenium-manager is kept.

@amilcarlucas
amilcarlucas merged commit 0640472 into master Nov 9, 2026
29 of 31 checks passed
@amilcarlucas
amilcarlucas deleted the shrink_win_install branch November 9, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIReview Request an automated AI review; picked up by the reviewprs sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants