Skip to content

shared/memzip/make-memzip.py: Make the script run with recent Python versions.#19343

Open
agatti wants to merge 2 commits into
micropython:masterfrom
agatti:memzip-fix
Open

shared/memzip/make-memzip.py: Make the script run with recent Python versions.#19343
agatti wants to merge 2 commits into
micropython:masterfrom
agatti:memzip-fix

Conversation

@agatti

@agatti agatti commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR applies a few fixes to the shared/memzip/make-memzip.py utility, namely finishing the Python 3.x migration and improve its resiliency.

The code still wasn't fully aware of how Python unified bytes and strings when it comes to I/O API. These first commit helps with that, following what has been shown in #7522.

Then turns out that the script had a couple more shortcomings, as passing a zip archive name without the .zip extension would make the script fail (zip would add the extension itself and the script wouldn't find the file). A similar change was applied to the generated file, with a .c extension added to the output if it was missing from the chosen filename.

This should close #7522.

Testing

This was tested manually on a Linux/x64 system with both CPython 3.12 and CPython 3.14. make-memzip.py -z zipfile -c cfile . was executed in a directory containing a few small files, and then the generated cfile.c file was used to recreate the zip archive present as zipfile.zip in the same directory.

vermin was also used to confirm the minimum Python version needed to run the script to not be past 3.8.

Trade-offs and Alternatives

An even more resilient script could be had by reimplementing the bundling done by the zip binary using Python's zipfile module, but that's probably a bit too much for such a simple utility right now.

Generative AI

I did not use generative AI tools when creating this PR.

agatti added 2 commits June 15, 2026 06:32
This commit updates the `make-memzip.py` utility to finish the migration
to Python 3.x.

The code still wasn't fully aware of how Python unified bytes and
strings when it comes to I/O API.  These changes help with that.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit makes the `make-memzip.py` utility more resilient in certain
usage cases, which weren't accounted for in the original source.

In some Linux distributions the `zip` command may not be available,
although `unzip` could be.  Unless the `zip` package is installed this
script will fail with a generic "file not found" error, which has been
addressed in these changes set.

Also, the `zip` command by default adds a `.zip` suffix to archives,
which wasn't accounted for.  So, running `./make-memzip -z z1 -c z2 .`
would fail, as the script would build `z1.zip` whilst the header
generator attempted to open `z1` instead.  This has now been fixed.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
@github-actions

Copy link
Copy Markdown

Code size report:

Reference:  unix/README: Update the supported targets list. [d901e98]
Comparison: shared/memzip/make-memzip.py: Improve script resilience. [merge of f146996]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.51%. Comparing base (d901e98) to head (f146996).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19343   +/-   ##
=======================================
  Coverage   98.51%   98.51%           
=======================================
  Files         176      176           
  Lines       22903    22903           
=======================================
  Hits        22562    22562           
  Misses        341      341           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@octoprobe-bot

Copy link
Copy Markdown

Octoprobe PR report

Test Tests
passed
Tests
skipped
Tests
xfailed
Tests
failed
Total
Failures

@agatti agatti added tools Relates to tools/ directory in source, or other tooling shared Relates to shared/ directory in source labels Jun 15, 2026

@dpgeorge dpgeorge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shared Relates to shared/ directory in source tools Relates to tools/ directory in source, or other tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with 'lib/memzip/make-memzip.py'

3 participants