I'm planning to create a huge executable directory and install it on some devices.
Imagine, that lateron I discover a bug in one of my python modules. Is there any way to transfer/copy only the modified byte code and replace the original byte code with the new one.
The reason I want to do this is, that in my context bandwidth is very expensive and I'd like to patch the code remotely.
Example: I have a project with two files:
prog.py
: (with following three lines)
import mod1
if __name__ == "__main__":
mod1.hello()
mod1.py
: (with following two line)
def hello():
print("hello old world")
Now I use PYTHONHASHSEED=2 pyinstaller prog.py
to create my directory which I copy to my device
Now I modify mod1.py
:
def hello():
print("hello new world")
and I recompile with PYTHONHASHSEED=2 pyinstaller prog.py
The full directory has (tared and gzipped) a size of about 10M
The file dist/prog/prog
has a size of about 1M
with pyi-archive_viewer
I can extract PYZ-00.pyz
out of my executable dist/prog/prog
In PYZ-00.pyz
I can find and extract mod1
which uses only 133 bytes.
Now if I copy that file to my device, how could I update the old
dist/prog/prog
such, that it has the new PYZ-00.pyz:mod1
byte code.
What code could I use to decompose, what code could I use to reassemble after having replaced one specific file (module)?
Alternative: Move pyc files to a zip file Startup performance is not that crucial. I could also live with an alternative solution, where no PYZ file is created and added to the executable, but where the dist directory contains a zip file with all the .pyc files
Another alternative: copy .pyc files into application directory
This would result in __file__
having exactly the same value as in the PYZ mode. Performance wise probably not that nice and creating a lot of files, but if incremental updates are crucial perhaps one option to handle it.