Really fix Python 3.6 deprecation warnings

Before, the module regexes didn't actually work properly, but we thought the
warnings were gone as they only were shown once because of __pycache__.

Now we instead don't filter by module, but simply hide those messages globally
during the earlyinit dependency import (which is the first import).
This commit is contained in:
Florian Bruhin 2017-01-18 08:40:57 +01:00
parent d9389ff0a7
commit b47f90d24f
2 changed files with 12 additions and 17 deletions

View File

@ -299,9 +299,20 @@ def check_libraries(args):
else:
modules['PyQt5.QtWebKit'] = _missing_str("PyQt5.QtWebKit")
from qutebrowser.utils import log
for name, text in modules.items():
try:
importlib.import_module(name)
# https://github.com/pallets/jinja/pull/628
# https://bitbucket.org/birkenfeld/pygments-main/issues/1314/
# https://github.com/pallets/jinja/issues/646
# https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
messages = ['invalid escape sequence',
'Flags not at the start of the expression']
with log.ignore_py_warnings(
category=DeprecationWarning,
message=r'({})'.format('|'.join(messages))):
importlib.import_module(name)
except ImportError as e:
_die(text, e)

View File

@ -200,22 +200,6 @@ def _init_py_warnings():
"""Initialize Python warning handling."""
warnings.simplefilter('default')
warnings.filterwarnings('ignore', module='pdb', category=ResourceWarning)
# https://github.com/pallets/jinja/pull/628
warnings.filterwarnings('ignore', module=r'jinja2\.filters',
category=DeprecationWarning,
message='Flags not at the start of the expression')
# https://bitbucket.org/birkenfeld/pygments-main/issues/1314/
warnings.filterwarnings('ignore', module=r'pygments\.util',
category=DeprecationWarning,
message='Flags not at the start of the expression')
# https://github.com/pallets/jinja/issues/646
warnings.filterwarnings('ignore', module=r'jinja2\..*',
category=DeprecationWarning,
message='invalid escape sequence')
# https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
warnings.filterwarnings('ignore', module='pypeg2',
category=DeprecationWarning,
message='invalid escape sequence')
@contextlib.contextmanager