Skip to content

Commit 8b5a87e

Browse files
committed
colorama only on win
1 parent ade57d5 commit 8b5a87e

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

tqdm/_utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import os
22
import subprocess
3+
from platform import system as _curos
4+
CUR_OS = _curos()
5+
IS_WIN = CUR_OS in ['Windows', 'cli']
6+
IS_NIX = (not IS_WIN) and any(
7+
CUR_OS.startswith(i) for i in
8+
['CYGWIN', 'MSYS', 'Linux', 'Darwin', 'SunOS', 'FreeBSD'])
9+
310

411
try: # pragma: no cover
512
_range = xrange
@@ -17,9 +24,13 @@
1724
except NameError: # pragma: no cover
1825
_unicode = str # in Py3, all strings are unicode
1926

27+
2028
try: # pragma: no cover
21-
import colorama
22-
colorama.init()
29+
if IS_WIN:
30+
import colorama
31+
colorama.init()
32+
else:
33+
colorama = None
2334
except ImportError: # pragma: no cover
2435
colorama = None
2536
except: # pragma: no cover
@@ -49,15 +60,12 @@ def _environ_cols_wrapper(): # pragma: no cover
4960
Return a function which gets width and height of console
5061
(linux,osx,windows,cygwin).
5162
"""
52-
import platform
53-
current_os = platform.system()
5463
_environ_cols = None
55-
if current_os in ['Windows', 'cli']:
64+
if IS_WIN:
5665
_environ_cols = _environ_cols_windows
5766
if _environ_cols is None:
5867
_environ_cols = _environ_cols_tput
59-
if any(current_os.startswith(i) for i in
60-
['CYGWIN', 'MSYS', 'Linux', 'Darwin', 'SunOS', 'FreeBSD']):
68+
if IS_NIX:
6169
_environ_cols = _environ_cols_linux
6270
return _environ_cols
6371

0 commit comments

Comments
 (0)