From 15333696ae91229bfb4921337c1cfaeb64c216e7 Mon Sep 17 00:00:00 2001 From: VaultVulp Date: Wed, 6 May 2020 22:52:12 +0300 Subject: [PATCH] Convert colorama into an optional dependency * Update install_requires in setup.py * Add platform check before colorama import * Remove Windows specific context manager --- icecream/icecream.py | 19 +++++-------------- setup.py | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/icecream/icecream.py b/icecream/icecream.py index 180fcf7..80cb383 100644 --- a/icecream/icecream.py +++ b/icecream/icecream.py @@ -13,16 +13,13 @@ from __future__ import print_function -import ast import inspect import pprint import sys -from contextlib import contextmanager from datetime import datetime from os.path import basename from textwrap import dedent -import colorama import executing from pygments import highlight # See https://gist.github.com/XVilka/8346728 for color support in various @@ -33,6 +30,10 @@ from .coloring import SolarizedDark +if sys.platform.startswith('win'): + # We will import colorama only on a specific subset of OS's thus removing colorama from required dependencies + import colorama + colorama.init() PYTHON2 = (sys.version_info[0] == 2) @@ -55,23 +56,13 @@ def colorize(s): return highlight(s, self.lexer, self.formatter) -@contextmanager -def supportTerminalColorsInWindows(): - # Filter and replace ANSI escape sequences on Windows with equivalent Win32 - # API calls. This code does nothing on non-Windows systems. - colorama.init() - yield - colorama.deinit() - - def stderrPrint(*args): print(*args, file=sys.stderr) def colorizedStderrPrint(s): colored = colorize(s) - with supportTerminalColorsInWindows(): - stderrPrint(colored) + stderrPrint(colored) DEFAULT_PREFIX = 'ic| ' diff --git a/setup.py b/setup.py index d3b4542..e190863 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,7 @@ def run_tests(self): ], tests_require=[], install_requires=[ - 'colorama>=0.3.9', + 'colorama>=0.3.9; platform_system=="Windows"', 'pygments>=2.2.0', 'executing>=0.3.1', 'asttokens>=2.0.1',