Skip to content

Commit 51107ab

Browse files
committed
logging with tqdm
1 parent baad735 commit 51107ab

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/melon/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ def cli(argv=sys.argv):
123123

124124
if len(argv) == 1:
125125
print(f"\
126-
__ \n\
127-
__ _ ___ / /__ ___ \n\
128-
/ ' \/ -_) / _ \/ _ \ \n\
129-
/_/_/_/\__/_/\___/_//_/ ver. {__version__}\n")
126+
__ \n\
127+
__ _ ___ / /__ ___ \n\
128+
/ ' \\/ -_) / _ \\/ _ \\ \n\
129+
/_/_/_/\\__/_/\\___/_//_/ ver. {__version__}\n")
130130

131131
opt = parser.parse_args(argv[1:])
132132
run(opt)

src/melon/melon.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import json
33
import numpy as np
44

5-
from tqdm import tqdm
6-
from tqdm.contrib.logging import logging_redirect_tqdm
75
from collections import defaultdict
86
from scipy.sparse import csr_matrix
97
from .utils import *

src/melon/utils.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import os
22
import re
3+
import sys
34
import subprocess
4-
import logging
5+
import logging
56

7+
if sys.stderr.isatty():
8+
os.environ['TQDM_DISABLE'] = '1'
9+
10+
from tqdm import tqdm
11+
from tqdm.contrib.logging import logging_redirect_tqdm
612

713
## setup logger format
814
logging.basicConfig(
9-
level="INFO",
10-
format="[%(asctime)s] %(levelname)s: %(message)s",
11-
datefmt="%Y-%m-%d %H:%M:%S")
12-
13-
logging.addLevelName(logging.INFO,
14-
f'\033[1m{logging.getLevelName(logging.INFO)}\033[1;0m')
15-
logging.addLevelName(logging.WARNING,
16-
f'\033[1m\x1b[33;20m{logging.getLevelName(logging.WARNING)}\033[1;0m')
17-
logging.addLevelName(logging.CRITICAL,
18-
f'\033[1m\x1b[31;20m{logging.getLevelName(logging.CRITICAL)}\033[1;0m')
15+
level='INFO',
16+
format='[%(asctime)s] %(levelname)s: %(message)s',
17+
datefmt='%Y-%m-%d %H:%M:%S')
18+
19+
if sys.stderr.isatty():
20+
logging.addLevelName(logging.INFO,
21+
f'\033[1m{logging.getLevelName(logging.INFO)}\033[1;0m')
22+
logging.addLevelName(logging.WARNING,
23+
f'\033[1m\x1b[33;20m{logging.getLevelName(logging.WARNING)}\033[1;0m')
24+
logging.addLevelName(logging.CRITICAL,
25+
f'\033[1m\x1b[31;20m{logging.getLevelName(logging.CRITICAL)}\033[1;0m')
1926

2027
logger = logging.getLogger(__name__)
2128

0 commit comments

Comments
 (0)