dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
583 stars 43 forks source link

Minify recursively #21

Closed ntaraujo closed 2 years ago

ntaraujo commented 3 years ago

It's probably a hard feature request, but would be great run "pyminify -r hello.py" to minify the file & the libraries its using

e.g. for projects with a lot of dependencies which want to have a .exe or even a .apk, as kivy projects (they tend to be much bigger than normal apks)

is it viable?

phorward commented 3 years ago

@ntaraujo I would appreciate this function, too.

Anyway, as a quick an dirty solution, you can also run

for py in `find . -name "*.py"`; do echo "Minifying $py..."; pyminify --remove-literal-statements $py > $py.min; mv $py.min $py; done

from a shell to minify any Python files in the current directory in-place.

amaank404 commented 3 years ago

It's probably a hard feature request, but would be great run "pyminify -r hello.py" to minify the file & the libraries its using

e.g. for projects with a lot of dependencies which want to have a .exe or even a .apk, as kivy projects (they tend to be much bigger than normal apks)

is it viable?

It just becomes less possible to do that if the libraries are installed on the actual python interpreter. you will need a installation of all those libraries locally within your project, after that you can simply minfy all the files within the project, reason being: You do not want to modify libraries installed in site-packages, there is chance that you will break the code.

Here is a simple example for the above:

My project uses: xyz-library which needs xyz-other-libraries

so you can use pip to make a local install.

my project structure before:

main_package
+- __init__.py
wrapper_main.py
requirements.txt
setup.py

now do: pip install xyz-library --target .

it will add the packages and requirements of xyz-library into the target directory.

now you can run a simple script to minfy all the contained libraries. (Minfy only, no obfuscation)

johnthagen commented 3 years ago

Being able to recursively minify an entire Python package (a directory of directories) seems like it would be a great addition.

clbarnes commented 2 years ago

My PR implementing this was closed without comment so I guess it's not a desired feature.

dflook commented 2 years ago

2.6.0 has been released which allows specifying a directory as the path to process. All files ending in .py below that directory will be minified in place.