shared/memzip/make-memzip.py: Make the script run with recent Python versions.#19343
Open
agatti wants to merge 2 commits into
Open
shared/memzip/make-memzip.py: Make the script run with recent Python versions.#19343agatti wants to merge 2 commits into
agatti wants to merge 2 commits into
Conversation
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>
|
Code size report: |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Octoprobe PR report
Failures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR applies a few fixes to the
shared/memzip/make-memzip.pyutility, 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
.zipextension would make the script fail (zipwould add the extension itself and the script wouldn't find the file). A similar change was applied to the generated file, with a.cextension 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 generatedcfile.cfile was used to recreate the zip archive present aszipfile.zipin the same directory.verminwas 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
zipbinary using Python'szipfilemodule, 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.