Skip to content

Commit 33a1616

Browse files
committed
Merge pull request kivy#494 from denys-duchier/colorama-fix
suppress colorization if stdout is not a tty
2 parents 1497c59 + fbeb675 commit 33a1616

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pythonforandroid/toolchain.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@
4141
import argparse
4242
from appdirs import user_data_dir
4343
import sh
44-
from colorama import Style, Fore
44+
if sys.stdout.isatty():
45+
from colorama import Style, Fore
46+
else:
47+
from collections import defaultdict
48+
class colorama_shim(object):
49+
def __init__(self):
50+
self._dict = defaultdict(str)
51+
def __getattr__(self, key):
52+
return self._dict[key]
53+
Style = Fore = colorama_shim()
4554

4655
user_dir = dirname(realpath(os.path.curdir))
4756
toolchain_dir = dirname(__file__)
@@ -69,7 +78,7 @@ def format(self, record):
6978
# handler and reset the level
7079
logger.setLevel(logging.INFO)
7180
logger.touched = True
72-
ch = logging.StreamHandler(stdout)
81+
ch = logging.StreamHandler(stdout) if sys.stdout.isatty() else logging.NullHandler()
7382
formatter = LevelDifferentiatingFormatter('%(message)s')
7483
ch.setFormatter(formatter)
7584
logger.addHandler(ch)

0 commit comments

Comments
 (0)