-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert colorama into an optional dependency #40
base: master
Are you sure you want to change the base?
Convert colorama into an optional dependency #40
Conversation
* Update install_requires in setup.py * Add platform check before colorama import * Remove Windows specific context manager
# API calls. This code does nothing on non-Windows systems. | ||
colorama.init() | ||
yield | ||
colorama.deinit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could easily write this to still use a context manager and deinit
after each print. Any reason not to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you interest to my PR, @alexmojaki .
I spent a little time tweaking with the code base, trying to minimize code change, but I wasn't able to find a readable solution.
If we leave this contex manager in place, we should move conditional import into this context manager, thus we will try to import colorama on each call of ic
. And import
statement is a costly opertaion.
I've tried to move context manager into another module (windows_support
), to be able to import colorama
on a module level. But in that case we have to use conditional function definition such as:
if sys.platform == 'win32':
from .windows_support import supportTerminalColorsInWindows
def colorizedStderrPrint(s):
colored = colorize(s)
with supportTerminalColorsInWindows():
stderrPrint(colored)
else:
def colorizedStderrPrint(s):
colored = colorize(s)
stderrPrint(colored)
In my opinion it comlicates both icecream.py
and entrire package. So I had to throw away this idea.
After that I've read a little bit of colorama's documentation to find out the reason to deinit
colorama
, but wasn't succesfful. So I wasn't sure why do we need to call init
and deinit
in such manner.
After a while, I've rewriten my proposition from ground up, and created this PR.
If you can help me understand the reason behind this context manager, I will try to rewrite this PR again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See if you can do without init() and deinit() entirely using colorama.AnsiToWin32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can write:
if sys.platform.startswith('win'):
# We will import colorama only on a specific subset of OS's, and wrap sys.stderr into colorama's stream wrapper
import colorama
colorama.init(wrap=False)
output_stream = colorama.AnsiToWin32(sys.stderr).stream
else:
output_stream = sys.stderr
...
def stderrPrint(*args):
print(*args, file=output_stream)
Sadly, in this case we have to rewrite captureStandardStreams
context manager in test_icecream.py
, for it tries to replace stderr with a fake stream. I tride to monkey-patch newly added module level attribute, but without any luck.
I have no problem with an optional Why would you like to move
And/or other reason(s) entirely. |
Thanks for your attention, @gruns! I'm using It allows me to set platform specific dependencies. uvloop = {version = "==0.14.0", markers = "sys_platform != 'win32' and implementation_name == 'cpython'"}
colorama = {version = "==0.4.3", markers = "sys_platform == 'win32' and implementation_name == 'cpython'"} As you know less dependecies means less version conflicts, less security issues etc. So usually I prefer to not install colorama on windows.
Maybe this concrete issue (pipenv + icecream + colorama) should be solved through pipenv's repo, but their release cycle is unbelievably long. So I've started with icream at first. |
Thank you for expounding; I understand your predicament much better now.
From Googling, we're not the first to be bitten by this: pypa/pipenv#3902.
If none of the above are satisfactory, perhaps it's time indeed to turn colorama into an optional icecream dependency. |
Sorry, @gruns, was a little bit busy with my work. Answering your questions:
|
|
Marking
One problem: I don't have ready access to a Window machine to test. @VaultVulp Would you be able to graciously continue to assist and test on Windows? |
For sure, @gruns, I'll help you. But if we do not move colorama's import under an |
Hi, folks! You asked for my help @gruns , can I help you with anything? |
I think that a fix like the one that you propose @VaultVulp (#40 (comment)) is needed to display colors in Pytest using Pycharm. |
I propose an update to the list of dependecies required to use
icecream
.Right now, we have to install
colorama
on all platforms, despite the fact thatic
will run properly on some operating systems even withoutcolorama
presented.As stated, I suggest: