pyminifier
pyminifier copied to clipboard
`pyminifier` returns an error when run on multiple files and at least one of those files is empty
When pyminifier is run on multiple files and at least one of those files is empty, for example a simple __init__.py, pyminifier returns an error.
Setup To Reproduce
File Structure
.
+-- helloworld
+-- helloworld.py
+-- __init__.py
helloworld/helloworld.py
def main():
print('Hello world!')
if __name__ == '__main__':
def main()
helloworld/__init__.py
In this example, __init__.py is empty.
pyminifier Command Example
$ pyminifier --lzma hello-world/*
hello-world/hello-world.py (81) reduced to 300 bytes (370.37% of original size)
Traceback (most recent call last):
File "/home/eric/miniconda3/envs/r-net-obs/bin/pyminifier", line 11, in <module>
sys.exit(main())
File "/home/eric/miniconda3/envs/r-net-obs/lib/python3.6/site-packages/pyminifier/pyminifier.py", line 383, in main
(float(new_filesize) / float(filesize)) * 100, 2)
ZeroDivisionError: float division by zero
Command Output
File Structure
.
+-- helloworld
+-- helloworld.py
+-- __init__.py
+-- minified
+-- helloworld.py
+-- __init__.py
minified/helloworld.py
import lzma, base64
exec(lzma.decompress(base64.b64decode('/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4ABHAEFdADIZSP9PQ8pBqvy8GuB3/\
H0Qt1jd2RFpjIH9/RzFxpUPhuyY1j8kvGaXMaA/+973nHhS7q96s0/enRActGVVWm9CAAAAACfiBV7GVo8JAAFdSJBflFcftvN9A\
QAAAAAEWVo=')))
# Created by pyminifier (https://github.com/liftoff/pyminifier)
minified/__init__.py
File Edit Options Buffers Tools Python Help
import lzma, base64
exec(lzma.decompress(base64.b64decode('/Td6WFoAAATm1rRGAAAAABzfRCEftvN9AQAAAAAEWVo=')))
# Created by pyminifier (https://github.com/liftoff/pyminifier)
Explanation
You can see from the example that pyminifier successfully does it job, but when it tries to report the % reduction in size (after the fact), it gets a ZeroDivisionError