-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Cease all use of Colorama on non-Windows systems. #345
Conversation
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'm glad all the typing paid off in the end! :)
You've almost got it, it's just the semantic new lines that got lost in the litany.
I have left instructions that should fix the coverage problems too.
Getting rid of a dependency on most platforms sounds GREAT!
OK, I've made the changes you suggested, and pushed them to this PR. |
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.
ah sorry forgot about this one. once it's applied, we should be ready to merge!
Co-authored-by: Hynek Schlawack <[email protected]>
Thanks! |
As the author of Colorama, I'm sorry we caused you trouble, and I approve of this change. I originally created colorama for my own very modest uses, and it since became wildly popular, without a commensurate amount of thought on the design, or effort on the maintenance. Thanks for your patience. |
Jonathan, please don't be sorry as I know how hard it is to write cross-platform code (Especially for messy topics like I/O.) and it has served us well over the years. As I wrote above, I'm glad to get rid of dependencies in general. If I'd have known that we need only the color codes on non-Windows, this would've been the approach from day 1. |
docs/api.rst
by hand.versionadded
,versionchanged
, ordeprecated
directives. Find the appropriate next version in our__init__.py
file..rst
files is written using semantic newlines.This PR was inspired by the frustration and confusion I suffered over the last week, dealing with figuring out why colored logging wan't working on my apps, despite everything seemingly having been configured properly. I eventually tracked it down to the
self.stream.isatty()
check oncolorama
'sansitowin32.py
file, line 92. Because my apps run in Docker containers, they don't log directly to a TTY, so it was returning False and forcing the ANSI-to-Win32 color code conversion, even though my apps run on Linux. This broke all the colors.Yes, fixing this is what
ConsoleRenderer
'sforce_colors
kwarg appears to be for, but I was using an old version ofConsoleRenderer
from before that was added, and didn't realize it.Ultimately, though, my experience showed me that
colorama
isn't intended to be used on non-Windows systems at all (See tartley/colorama#306). The only thingcolorama.init()
does is wrapsys.stdout
andsys.stderr
in theAnsiToWin32
wrapper, which either does nothing on non-Win32 systems (if logging to a TTY) or is actively harmful (if logging to a file).So I believe that
structlog
should change to avoid the use ofcolorama
at all unless it's running on Windows. That's what this PR does. I made the following changes:structlog
defines ifcolorama
isn't installed with the actual raw ANSI color codes thatcolorama
generates when one uses those constants.colorama
, since it isn't done lazily on Windows, and shouldn't be done on other OSes at all.force_colors
kwarg on Windows. The Windows init code was usingself._force_colors
, which was alwaysFalse
where that code was being called, even if theforce_colors
kwarg wasTrue
.ConsoleRenderer
'scolors
kwarg from "true ifcolorama
is installed" to "True on Windows ifcolorama
is installed, but always True on other OSes".I hope I did this right... I don't contribute to GitHub all that often, but your "How to Contribute" guide was freaking great for helping give me the confidence that I was at least mostly doing this right. I ran
tox
andpre-commit
for the first time ever, and it showed me some bugs in my original code, which I fixed before committing.The one thing I'm a bit iffy on is the tests. I really just updated the "Make sure this crashes if
colors=True
is sent when colorama isn't installed" test doesn't get run unless it's running on Windows. I'm not really certain that's all that needs to change, or if that's even the right change.