Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/numpy/distutils/log.py
7757 views
# Colored log1import sys2from distutils.log import * # noqa: F4033from distutils.log import Log as old_Log4from distutils.log import _global_log56from numpy.distutils.misc_util import (red_text, default_text, cyan_text,7green_text, is_sequence, is_string)8910def _fix_args(args,flag=1):11if is_string(args):12return args.replace('%', '%%')13if flag and is_sequence(args):14return tuple([_fix_args(a, flag=0) for a in args])15return args161718class Log(old_Log):19def _log(self, level, msg, args):20if level >= self.threshold:21if args:22msg = msg % _fix_args(args)23if 0:24if msg.startswith('copying ') and msg.find(' -> ') != -1:25return26if msg.startswith('byte-compiling '):27return28print(_global_color_map[level](msg))29sys.stdout.flush()3031def good(self, msg, *args):32"""33If we log WARN messages, log this message as a 'nice' anti-warn34message.3536"""37if WARN >= self.threshold:38if args:39print(green_text(msg % _fix_args(args)))40else:41print(green_text(msg))42sys.stdout.flush()434445_global_log.__class__ = Log4647good = _global_log.good4849def set_threshold(level, force=False):50prev_level = _global_log.threshold51if prev_level > DEBUG or force:52# If we're running at DEBUG, don't change the threshold, as there's53# likely a good reason why we're running at this level.54_global_log.threshold = level55if level <= DEBUG:56info('set_threshold: setting threshold to DEBUG level,'57' it can be changed only with force argument')58else:59info('set_threshold: not changing threshold from DEBUG level'60' %s to %s' % (prev_level, level))61return prev_level6263def get_threshold():64return _global_log.threshold6566def set_verbosity(v, force=False):67prev_level = _global_log.threshold68if v < 0:69set_threshold(ERROR, force)70elif v == 0:71set_threshold(WARN, force)72elif v == 1:73set_threshold(INFO, force)74elif v >= 2:75set_threshold(DEBUG, force)76return {FATAL:-2,ERROR:-1,WARN:0,INFO:1,DEBUG:2}.get(prev_level, 1)777879_global_color_map = {80DEBUG:cyan_text,81INFO:default_text,82WARN:red_text,83ERROR:red_text,84FATAL:red_text85}8687# don't use INFO,.. flags in set_verbosity, these flags are for set_threshold.88set_verbosity(0, force=True)899091_error = error92_warn = warn93_info = info94_debug = debug959697def error(msg, *a, **kw):98_error(f"ERROR: {msg}", *a, **kw)99100101def warn(msg, *a, **kw):102_warn(f"WARN: {msg}", *a, **kw)103104105def info(msg, *a, **kw):106_info(f"INFO: {msg}", *a, **kw)107108109def debug(msg, *a, **kw):110_debug(f"DEBUG: {msg}", *a, **kw)111112113