Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove python source files after byte-compiling?

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
like image 821
tarabyte Avatar asked Oct 31 '22 16:10

tarabyte


1 Answers

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.

like image 124
Antimony Avatar answered Nov 15 '22 05:11

Antimony