Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable ExtDeprecationWarning for external libs in flask

Tags:

python

flask

When I run my script, I get this output:

/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.marshmallow is deprecated, use flask_marshmallow instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful is deprecated, use flask_restful instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.fields is deprecated, use flask_restful.fields instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.reqparse is deprecated, use flask_restful.reqparse instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restplus is deprecated, use flask_restplus instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.representations is deprecated, use flask_restful.representations instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.migrate is deprecated, use flask_migrate instead.
  .format(x=modname), ExtDeprecationWarning

I don't really care about this, because external libs are causing this. I can't update these libs as I don't own them and I see for several there are pull requests pending.

How can I get some peace and quiet?

like image 994
Dennis Decoene Avatar asked Jun 28 '16 14:06

Dennis Decoene


1 Answers

As of Flask 1.0, flask.ext does not exist. Packages that haven't fixed these imports will not work.


First, you should care about this because the packages you're using aren't up to date. Report a bug that they should switch to using direct import names, such as flask_sqlalchemy, rather than the flask.ext import hook.

Add a warnings.simplefilter line to filter out these warnings. You can place it wherever you're configuring your application, before performing any imports that would raise the warning.

import warnings
from flask.exthook import ExtDeprecationWarning

warnings.simplefilter('ignore', ExtDeprecationWarning)
like image 129
davidism Avatar answered Oct 24 '22 11:10

davidism