Can I remove python source files (*.py) after byte-compiling? I know this does not provide a security and that .pyc/o files can be reverse-engineered very easily; I just want to release less files on a release.
# Clean the python cache
find ./mypythonstuffs -type f -name "*.py[co]" -delete
find ./mypythonstuffs -type d -name "__pycache__" -delete
# Remove test directories
find ./mypythonstuffs -name "test" -type d -exec rm -r "{}" \;
# Byte-compile, ignoring .git subdirectories
python3 -O -m compileall -f -x r'[/\\][.]git' ./mypythonstuffs
# Remove now-unnecessary??? python source files
find ./mypythonstuffs -type f -name "*.py" -delete
Please do not do this.
First off, python bytecode is an undocumented implementation detail. There is no guarantee that distributing bytecode to other people will actually work.
Second, it makes it hard to debug. You know how tracebacks show the lines of source code? That's taken from the original source files. Even if you don't care about FOSS at all, you should still care about getting helpful bug reports from users.
Third, it is really unnecessary. If you want to distribute less files, just distribute the python source files. Bytecode is an implementation detail. You shouldn't be checking it in or distributing it in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With