Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python slimit minimizer unwanted warning output

from slimit import minify


if __name__ == "__main__":
    print("start")

    # Normally, I pass real JavaScript. For this issue, an empty string reproduces problem.
    minify("", mangle=True)

    print("exit")

This triggers the following console output.

start
WARNING: Couldn't write lextab module <module 'slimit.lextab' from '/Users/kurtostfeld/samba/wrapad/venv/lib/python2.7/site-packages/slimit/lextab.pyc'>. Won't overwrite existing lextab module
WARNING: yacc table file version is out of date
WARNING: Token 'IMPORT' defined, but not used
WARNING: Token 'BLOCK_COMMENT' defined, but not used
WARNING: Token 'ENUM' defined, but not used
WARNING: Token 'EXTENDS' defined, but not used
WARNING: Token 'LINE_COMMENT' defined, but not used
WARNING: Token 'LINE_TERMINATOR' defined, but not used
WARNING: Token 'CONST' defined, but not used
WARNING: Token 'EXPORT' defined, but not used
WARNING: Token 'CLASS' defined, but not used
WARNING: Token 'SUPER' defined, but not used
WARNING: There are 10 unused tokens
WARNING: Couldn't create <module 'slimit.yacctab' from '/Users/kurtostfeld/samba/wrapad/venv/lib/python2.7/site-packages/slimit/yacctab.pyc'>. Won't overwrite existing tabmodule
exit

These warnings are flooding my application console output. How can I use minify without generating warnings?

I'm using Python 2.7.12, and what is currently the latest library versions: slimit 0.8.1, ply 3.10.

like image 574
clay Avatar asked Jun 12 '17 15:06

clay


4 Answers

According to this issue on Github, slimit depends of the ply package. After few tries, it seems that theses warnings appear since version 3.8 of ply. . You could update ply to 3.6 which is the last version that doesn't bring these messages :

pip uninstall ply -y && pip install ply==3.6

It solved my problem.

UPDATE Install a sooner version of ply was really a bad work around since some of my tests were failing. Original slimit version seems not maintained well so I suggest to update to a newer version, metatoaster did a good job to improve it and fixed that problem of warning message. The solution for me was to uninstall slimit and then install it's version:

pip install git+https://github.com/metatoaster/slimit.git#egg=slimit

FINAL UPDATE In fact, slimit seems not maintened anymore and its successor is called calmjs, there is few differences but it is really more stable and don't shows these annoying warning message. See: https://github.com/calmjs/calmjs.parse

like image 163
snoob dogg Avatar answered Nov 13 '22 10:11

snoob dogg


Switching versions did not change anything for me, I found another workaround: simply delete (or move, if you want to be cautious) the mentioned files (yourpython/site-packages/slimit/yacctab.py and yourpython/site-packages/slimit/lextab.py).

I believe the module will re-create these files and stop bothering you with warning messages.

like image 25
Be Chiller Too Avatar answered Nov 13 '22 10:11

Be Chiller Too


Slimit uses ply under the hood, which uses logging from stdlib. AFAICS slimit does not allow you to pass the logging parameters that ply's lex and yacc expect.

While you therefor can't (directly) access ply's logging, you should be able to suppress those messages my raising the global logging level:

import logging
...
logging.disable(logging.CRITICAL)
minify("", mangle=True)
logging.disable(logging.NOTSET)
like image 2
user2722968 Avatar answered Nov 13 '22 10:11

user2722968


You can use this parser, too: https://github.com/PiotrDabkowski/pyjsparser

It works and is easy to use. It does not handle comments though. (Neither does calmjs seems to handle comments fully: Its parse function has a parameter to indicate that you want the comments, but as of now, some comments seem to get lost.)

like image 1
jciloa Avatar answered Nov 13 '22 12:11

jciloa