@@ -1413,24 +1413,26 @@ def filter_params(params, **kwargs):
14131413
14141414
14151415def is_docker () -> bool :
1416- path = '/proc/self/cgroup'
1417- return os .path .exists ('/.dockerenv' ) or (os .path .isfile (path ) and any ('docker' in line for line in open (path )))
1416+ path = "/proc/self/cgroup"
1417+ return os .path .exists ("/.dockerenv" ) or (
1418+ os .path .isfile (path ) and any ("docker" in line for line in open (path ))
1419+ )
14181420
14191421
14201422def stream_supports_colour (stream : Any ) -> bool :
1421- is_a_tty = hasattr (stream , ' isatty' ) and stream .isatty ()
1423+ is_a_tty = hasattr (stream , " isatty" ) and stream .isatty ()
14221424
14231425 # Pycharm and Vscode support colour in their inbuilt editors
1424- if ' PYCHARM_HOSTED' in os .environ or os .environ .get (' TERM_PROGRAM' ) == ' vscode' :
1426+ if " PYCHARM_HOSTED" in os .environ or os .environ .get (" TERM_PROGRAM" ) == " vscode" :
14251427 return is_a_tty
14261428
1427- if sys .platform != ' win32' :
1429+ if sys .platform != " win32" :
14281430 # Docker does not consistently have a tty attached to it
14291431 return is_a_tty or is_docker ()
14301432
14311433 # ANSICON checks for things like ConEmu
14321434 # WT_SESSION checks if this is Windows Terminal
1433- return is_a_tty and (' ANSICON' in os .environ or ' WT_SESSION' in os .environ )
1435+ return is_a_tty and (" ANSICON" in os .environ or " WT_SESSION" in os .environ )
14341436
14351437
14361438class _ColourFormatter (logging .Formatter ):
@@ -1444,17 +1446,17 @@ class _ColourFormatter(logging.Formatter):
14441446 # 1 means bold, 2 means dim, 0 means reset, and 4 means underline.
14451447
14461448 LEVEL_COLOURS = [
1447- (logging .DEBUG , ' \x1b [40;1m' ),
1448- (logging .INFO , ' \x1b [34;1m' ),
1449- (logging .WARNING , ' \x1b [33;1m' ),
1450- (logging .ERROR , ' \x1b [31m' ),
1451- (logging .CRITICAL , ' \x1b [41m' ),
1449+ (logging .DEBUG , " \x1b [40;1m" ),
1450+ (logging .INFO , " \x1b [34;1m" ),
1451+ (logging .WARNING , " \x1b [33;1m" ),
1452+ (logging .ERROR , " \x1b [31m" ),
1453+ (logging .CRITICAL , " \x1b [41m" ),
14521454 ]
14531455
14541456 FORMATS = {
14551457 level : logging .Formatter (
1456- f' \x1b [30;1m%(asctime)s\x1b [0m { colour } %(levelname)-8s\x1b [0m \x1b [35m%(name)s\x1b [0m %(message)s' ,
1457- ' %Y-%m-%d %H:%M:%S' ,
1458+ f" \x1b [30;1m%(asctime)s\x1b [0m { colour } %(levelname)-8s\x1b [0m \x1b [35m%(name)s\x1b [0m %(message)s" ,
1459+ " %Y-%m-%d %H:%M:%S" ,
14581460 )
14591461 for level , colour in LEVEL_COLOURS
14601462 }
@@ -1467,7 +1469,7 @@ def format(self, record):
14671469 # Override the traceback to always print in red
14681470 if record .exc_info :
14691471 text = formatter .formatException (record .exc_info )
1470- record .exc_text = f' \x1b [31m{ text } \x1b [0m'
1472+ record .exc_text = f" \x1b [31m{ text } \x1b [0m"
14711473
14721474 output = formatter .format (record )
14731475
@@ -1483,8 +1485,7 @@ def setup_logging(
14831485 level : int = MISSING ,
14841486 root : bool = True ,
14851487) -> None :
1486- """A helper method to automatically setup the library's default logging.
1487- """
1488+ """A helper method to automatically setup the library's default logging."""
14881489
14891490 if level is MISSING :
14901491 level = logging .INFO
@@ -1493,16 +1494,20 @@ def setup_logging(
14931494 handler = logging .StreamHandler ()
14941495
14951496 if formatter is MISSING :
1496- if isinstance (handler , logging .StreamHandler ) and stream_supports_colour (handler .stream ):
1497+ if isinstance (handler , logging .StreamHandler ) and stream_supports_colour (
1498+ handler .stream
1499+ ):
14971500 formatter = _ColourFormatter ()
14981501 else :
1499- dt_fmt = '%Y-%m-%d %H:%M:%S'
1500- formatter = logging .Formatter ('[{asctime}] [{levelname:<8}] {name}: {message}' , dt_fmt , style = '{' )
1502+ dt_fmt = "%Y-%m-%d %H:%M:%S"
1503+ formatter = logging .Formatter (
1504+ "[{asctime}] [{levelname:<8}] {name}: {message}" , dt_fmt , style = "{"
1505+ )
15011506
15021507 if root :
15031508 logger = logging .getLogger ()
15041509 else :
1505- lib , _ , _ = __name__ .partition ('.' )
1510+ lib , _ , _ = __name__ .partition ("." )
15061511 logger = logging .getLogger (lib )
15071512
15081513 handler .setFormatter (formatter )
0 commit comments