On 15. 01. 20 23:59, Zbigniew Jędrzejewski-Szmek wrote:
### Solution 5: Stop shipping mandatory bytecode cache
This solution sounds simple: We do no longer ship the bytecode cache mandatorily. Technically, we move the `.pyc` files to a subpackage of `python3-libs` (or three different subpackages, that is not important here). And we only*Recommend* them from `python3-libs` -- by default, the users get them, but for space critical Fedora flavors (such as container images) the maintainers can opt-out and so can the powerusers.
This would **save 18.6 MiB / 50%** -- quite a lot.
However, as said earlier, if the bytecode cache files are not there, Python attempts to create them upon first import. That can result in several problems, here we will try to propose how to workaround them.
Below using a flag file in each __pycache__ directory is suggested. What about a different route: having a flag file for all descendants of a directory?
For example, /usr/lib/python3.8/.dont_write_bytecode would cover all modules under /usr/lib/python3.8/. If a .pyc file is present, python could still make use of it.
This would be a nicer solution because it wouldn't require modifying individual packages, but would still avoid the selinux issues and slowdowns from failed attempts to write the optimized files. The __pycache__ files wouldn't need to exist at all.
To follow up on this, I got an idea recently.
If we add a reason to this marker file, Python can warn properly, without distro-specific patches.
Something like:
echo "Install python3-libs-bytecode-opt-0 or python3-libs-bytecode-opt-1 to get the cache." > /usr/lib64/python3.8/.dont_write_bytecode
python -0 ... Warning: Bytecode cashe for the selected optimization level was not found and the /usr/lib64/python3.8/.dont_write_bytecode file prevents it to be created. Python startup and imports may be slower. Install python3-libs-bytecode-opt-0 or python3-libs-bytecode-opt-1 to get the cache.