Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence ply errors #97

Open
warrenspe opened this issue Jan 16, 2018 · 4 comments
Open

Silence ply errors #97

warrenspe opened this issue Jan 16, 2018 · 4 comments

Comments

@warrenspe
Copy link

Running slimit on cygwin produces several warnings each time it is run

>>> import slimit
s>>> slimit.minify("")
WARNING: Couldn't write lextab module <module 'slimit.lextab' from '/usr/lib/python3.6/site-packages/slimit/lextab.py'>. Won't overwrite existing lextab module
WARNING: yacc table file version is out of date
WARNING: Token 'LINE_COMMENT' defined, but not used
WARNING: Token 'BLOCK_COMMENT' defined, but not used
WARNING: Token 'LINE_TERMINATOR' defined, but not used
WARNING: Token 'CLASS' defined, but not used
WARNING: Token 'CONST' defined, but not used
WARNING: Token 'ENUM' defined, but not used
WARNING: Token 'EXPORT' defined, but not used
WARNING: Token 'EXTENDS' defined, but not used
WARNING: Token 'IMPORT' 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 '/usr/lib/python3.6/site-packages/slimit/yacctab.py'>. Won't overwrite existing tabmodule
''

Using ply v 3.10. Only fix for me appears to be to revert to ply 3.4

@metatoaster
Copy link

metatoaster commented Jan 30, 2018

This can be worked around by removing those *tab.py files under the slimit directory (along with the related .pyc there or inside the __pycache__ directory); you will likely need to be the root user (or sudo) to remove them and regenerate them (again as root) using the current version of ply that was also installed (by running python -c 'import slimit;slimit.minify("")', and as root for a system level installation).

Really though, this package doesn't look maintained anymore so I ended up forking this, took the good bits as a base for my own.

@rod-app
Copy link

rod-app commented Feb 16, 2019

I get the same verbose dreck spewed out to stderr. This exceedingly ugly one-liner anywhere after import slimit, but before calling minify() silences the logging:

slimit.lexer.ply.lex.PlyLogger =  \
slimit.parser.ply.yacc.PlyLogger = \
  type('_NullLogger', (slimit.lexer.ply.lex.NullLogger,),
       dict(__init__=lambda s, *_, **__: (None, s.super().__init__())[0]))

This works for me in Python 3.6 with slimit 0.8.1 and ply 3.11 -- maybe others, but YMMV.

All this does is monkey-patches the PlyLogger class with the NullLogger class the ply package defines itself, adapting for the differences in initializer signatures between the two classes (shame, shame). If ply has a configuration setting or optional initializer parameter somewhere that effectively does this -- and it should -- I couldn't find it. (Hint, hint, ply maintainers.) Maybe in lieu of that, slimit should do this internally instead of putting the onus on the user?

@metatoaster
Copy link

@rod-app The problem actually goes deeper than that - if those messages are generated every time minify is called, it means that the ply tab modules are being regenerated (which takes as long as a second), and if there are a number of JavaScript files being processed that extra delay and thus performance hit to the program will accumulate rather quickly. Removing the message simply hides the problem but not actually fixing it - the only way to fix it is to manually remove the problematic tab files and regenerate them correct as I had suggested.

The fork that I made (calmjs.parse) does not track the tab files for the source repository, but they are package/generated for every supported (and released) ply versions, such that they are not needlessly being regenerated for the end-users, and in the case a newer version of ply is out there is a specific command (python -m calmjs.parse.parsers.optimize) with the reasoning behind it explained in the README for the package.

Also please note that slimit has not received a new release for nearly 6 years now, so I made that fork as an attempt to rectify the situation (the slimit minify equivalent is available via from calmjs.parse import es5 and then call es5.minify_print).

@rod-app
Copy link

rod-app commented Feb 17, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants