Repository navigation
Install wheel files from PyPi via upip (requires micropython-zipfile) #7067
Description
Activity
Alright, on review, there are a few things needed for this:
- Expose
crc32()fromuzlib(may as well exposeadler32()as well) - Implement
zlib.decompressobj()compatibleuzlib.decompressobj() - Implement
zlib.Decompressorcompatibleuzlib.Decompressor, supporting a subsetdecompress()unconsumed_tail()eof()flush()
- Implement
zipfile.infolist()andzipfile.zopen()
That's just barely enough to extract files from a Zip file using Deflate compression using the CPython
zipfilemodule. I expect the potential size cost is minimal:crc32()andadler32()are already implementeduzlib.Decompressorwraps existinguzlibfunctionality with a thin interfacezipfileis a small Python module
- Expose
One thing to consider when proposing changes to
upipis that the script was optimised to ensure it can install libraries on an ESP8266. This has restricted RAM: my recollection is that the developer had some difficulty in achieving this.Fair enough.
crc32()andadler32()already exist in the C code foruzlib; I'm not sure the weight ofdecompressobj(), although it's supposed to be for not having a whole object in RAM; andzipfilefrom CPython is 86k of Python code, half of which is comments and white space.zipfileis also thread-safe, so implementing auzipfilethat's much more minimal is probably an easier target and is much less a heavy lift.What about trying to import
uzipfileorzipfileand throwing an exception if attempting to install awhlwhen neither exists, but otherwise running fine? In the very least, this is a small handful of additional bytes, although I worry a suitableuzipfilemight be half a kilo or so and that board is really, really tight on RAM.@jrmoserbaltimore was this able to be solved to create a functional ZipFile module for micropython?
In case anyone is curious I did implement zipfile and wheel here:
- https://github.com/maruno/mpy-blox/blob/master/mpy_blox/zipfile.py
- https://github.com/maruno/mpy-blox/tree/master/mpy_blox/wheel
But I mostly target my own ESP32 hobby boards, I don't trust anything I make to run on the constrained ESP8266 modules.
upip has been replaced by
mip/mpremote mip. Is this issue still relevant?Reacted by Matt TrentiniPS: there is now an initial port of the CPython
zipfileto MicroPython here: https://github.com/jonnor/micropython-zipfile
Looking into #6461, I came up with this:
The problem is the PyPi tar.gz is a source tarball and may not act as expected.
zipfileis necessary to extract the wheel file, but requiresmicropython-zipfilebe fleshed out. That in turn depends mainly onzlib, which is fine. CPython's implementation is basicallyzlibplus a bunch of Python code to read the actual format.Assuming a
zipfilethat implementsZipFile.infolist()andZipFile.open()to read a zip file, the below would conceptually work:I'm not sure anything is gained by using the CPython
zipfile(and it seems to have issues e.g. it imports but doesn't really use binascii(), has its own crc32 implementation internally), but it might work nearly as-is, since it doesn't rely on additional C code.