@@ -1413,24 +1413,26 @@ def filter_params(params, **kwargs):
1413
1413
1414
1414
1415
1415
def 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
+ )
1418
1420
1419
1421
1420
1422
def 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 ()
1422
1424
1423
1425
# 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" :
1425
1427
return is_a_tty
1426
1428
1427
- if sys .platform != ' win32' :
1429
+ if sys .platform != " win32" :
1428
1430
# Docker does not consistently have a tty attached to it
1429
1431
return is_a_tty or is_docker ()
1430
1432
1431
1433
# ANSICON checks for things like ConEmu
1432
1434
# 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 )
1434
1436
1435
1437
1436
1438
class _ColourFormatter (logging .Formatter ):
@@ -1444,17 +1446,17 @@ class _ColourFormatter(logging.Formatter):
1444
1446
# 1 means bold, 2 means dim, 0 means reset, and 4 means underline.
1445
1447
1446
1448
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" ),
1452
1454
]
1453
1455
1454
1456
FORMATS = {
1455
1457
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" ,
1458
1460
)
1459
1461
for level , colour in LEVEL_COLOURS
1460
1462
}
@@ -1467,7 +1469,7 @@ def format(self, record):
1467
1469
# Override the traceback to always print in red
1468
1470
if record .exc_info :
1469
1471
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"
1471
1473
1472
1474
output = formatter .format (record )
1473
1475
@@ -1483,8 +1485,7 @@ def setup_logging(
1483
1485
level : int = MISSING ,
1484
1486
root : bool = True ,
1485
1487
) -> 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."""
1488
1489
1489
1490
if level is MISSING :
1490
1491
level = logging .INFO
@@ -1493,16 +1494,20 @@ def setup_logging(
1493
1494
handler = logging .StreamHandler ()
1494
1495
1495
1496
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
+ ):
1497
1500
formatter = _ColourFormatter ()
1498
1501
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
+ )
1501
1506
1502
1507
if root :
1503
1508
logger = logging .getLogger ()
1504
1509
else :
1505
- lib , _ , _ = __name__ .partition ('.' )
1510
+ lib , _ , _ = __name__ .partition ("." )
1506
1511
logger = logging .getLogger (lib )
1507
1512
1508
1513
handler .setFormatter (formatter )
0 commit comments