Don't enable warnings if log was never inited

Otherwise, anything importing qtutils (which uses ignore_py_warnings
on module level) would enable warnings. This means pylint showed its own
warnings because of qute_pylint.config.
This commit is contained in:
Florian Bruhin 2016-07-25 13:03:58 +02:00
parent c3f53312af
commit 1564563662

View File

@ -38,6 +38,8 @@ try:
except ImportError:
colorama = None
_log_inited = False
COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white']
COLOR_ESCAPES = {color: '\033[{}m'.format(i)
for i, color in enumerate(COLORS, start=30)}
@ -169,6 +171,8 @@ def init_log(args):
logging.captureWarnings(True)
_init_py_warnings()
QtCore.qInstallMessageHandler(qt_message_handler)
global _log_inited
_log_inited = True
def _init_py_warnings():
@ -189,10 +193,11 @@ def disable_qt_msghandler():
@contextlib.contextmanager
def ignore_py_warnings(**kwargs):
"""Contextmanager to temporarily hke certain Python warnings."""
"""Contextmanager to temporarily disable certain Python warnings."""
warnings.filterwarnings('ignore', **kwargs)
yield
_init_py_warnings()
if _log_inited:
_init_py_warnings()
def _init_handlers(level, color, force_color, json_logging, ram_capacity):