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")
这将触发以下控制台输出。
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
这些警告充斥着我的应用程序控制台输出。如何使用minify而不生成警告?
我使用的是Python2.7.12,以及目前最新的库版本:Slimit0.8.1,Ply3.10。
最佳答案
根据to this issue on Github,slimit取决于ply
包。经过几次尝试,这些警告似乎出现在ply
的3.8版之后。。您可以将ply
更新到3.6,这是不带这些消息的最新版本:
pip uninstall ply -y && pip install ply==3.6
它解决了我的问题。
更新
安装一个更早版本的
ply
确实是个糟糕的工作,因为我的一些测试失败了。原来的slimit
版本似乎没有得到很好的维护,所以我建议更新到一个新版本,metatoaster did a good job to improve it并修复了警告消息的问题。我的解决方案是卸载slimit
,然后安装它的版本:pip install git+https://github.com/metatoaster/slimit.git#egg=slimit
最终更新实际上,
slimit
似乎不再被维护,它的后续版本称为calmjs
,虽然没有什么区别,但它确实更稳定,并且不会显示这些烦人的警告消息。见:https://github.com/calmjs/calmjs.parse关于python - Python slimit最小化器不必要的警告输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44503833/