Summary
Add optional host-side compilation of .py files to .mpy via mpy-cross when transferring files to a MicroPython board (CLI put/cp and File Transfer UI).
Motivation
Uploading bytecode instead of source:
- Uses less flash
- Speeds up imports (no parse/compile on device)
- Matches how
mip often installs packages (.mpy by default)
mpftp already builds host mpy-cross as part of firmware builds (firmware_engine.py), but file transfer always sends .py as-is. Exposing compile-on-upload would close that gap for app/lib deployment workflows.
Proposed behavior
- Opt-in setting / CLI flag, e.g.
mpftp.compileOnUpload and --mpy / --compile on put / cp.
- When enabled and the destination is MicroPython:
- For each uploaded
.py, run mpy-cross on the host
- Upload the resulting
.mpy (same basename, .mpy extension)
- Skip files that should remain source (
boot.py, main.py, or a configurable allowlist/denylist)
- Compatibility: pass the correct
-march / mpy version for the connected firmware (probe board or reuse firmware-workspace mpy-cross built for that tree). Mismatch should fail clearly rather than silently upload incompatible bytecode.
- Tooling discovery (in order): firmware-workspace
mpy-cross binary → PATH → error with install/build hint.
- CircuitPython: out of scope or explicitly unsupported (different bytecode / tooling), unless a clear CP path exists later.
Acceptance criteria
Notes
Related existing pieces:
- Firmware build already invokes
make -C mpy-cross
mip has --mpy / source install choices; this request is about user file transfer, not package install
Summary
Add optional host-side compilation of
.pyfiles to.mpyviampy-crosswhen transferring files to a MicroPython board (CLIput/cpand File Transfer UI).Motivation
Uploading bytecode instead of source:
mipoften installs packages (.mpyby default)mpftp already builds host
mpy-crossas part of firmware builds (firmware_engine.py), but file transfer always sends.pyas-is. Exposing compile-on-upload would close that gap for app/lib deployment workflows.Proposed behavior
mpftp.compileOnUploadand--mpy/--compileonput/cp..py, runmpy-crosson the host.mpy(same basename,.mpyextension)boot.py,main.py, or a configurable allowlist/denylist)-march/ mpy version for the connected firmware (probe board or reuse firmware-workspacempy-crossbuilt for that tree). Mismatch should fail clearly rather than silently upload incompatible bytecode.mpy-crossbinary →PATH→ error with install/build hint.Acceptance criteria
.pyas.mpyvia mpy-cross with an explicit flagmpy-cross/ board combo produces a clear errorboot.py/main.py(and documented exceptions) are not rewritten to.mpyby defaultNotes
Related existing pieces:
make -C mpy-crossmiphas--mpy/ source install choices; this request is about user file transfer, not package install