Open dessant opened 10 years ago
It already includes a feature like this but only for the .pyz output format. So if you had some .py files like this:
run.py
some_module.py
other_module.py
...and you ran:
pyminifier --pyz=minified_run.pyz run.py
...it would automatically include some_module.py
and other_module.py
(assuming run.py imported them) inside minified_run.pyz
.
I assume what you want is to just be able to point pyminifier at a package directory like, mymodule
and have it automatically minify all the code inside it? To do that pyminifier will need to keep global track of all exported names so that it can properly modify things like 'from foo import bar' to 'from foo import zX' (assuming it changed 'bar' to 'zX' inside foo.py).
I'll see what I can do.
Any followup on this issue? @liftoff
I can't use the -O option with --pyz
As a workaround, if comment/docstring stripping and/or variable obfuscation is sufficient, you can use pyminifier with something like pex (https://github.com/pantsbuild/pex) or another zip-application builder.
When you invoke pex with something like: pex -e mypackage:myfunc mypackage -o mypackage.pex
then pex uses setuptools to build the package. Pex will bundle your package into an executable zip-application, but doesn't do obfuscation on its own. You can add pyminifier for obfuscation by subclassing distutils.command.build from setup.py in your package and overriding the run method to execute pyminifier on each file in your package after calling the existing build-method.
Note, if you attempt to obfuscate classes and methods, your imports will start breaking... but if minification or variable-obfuscation is enough this work well.
I would like to thank you for the time and effort put into this project, it may very well be the best python code minifier/obfuscator out there.
I think you could make it even more clever by adding full package (with nested dirs) minification support to it. Please consider adding this, if you too find it worthwhile.