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
Set coloured output with a context manager #12134
base: master
Are you sure you want to change the base?
Set coloured output with a context manager #12134
Conversation
if on: | ||
coloron() | ||
else: | ||
nocolor() | ||
yield |
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.
Based on the docstring: should there be toggle actions both before and after the yield
statement?
if on: | |
coloron() | |
else: | |
nocolor() | |
yield | |
(coloron if on else nocolor)() | |
yield | |
(nocolor if on else coloron)() |
...or something neater (example for illustration purposes, not necessarily good code).
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.
maybe toggle is the wrong word then; it should just turn on/off colorization, on entering the context, then return it to the initial state on exiting the context
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 a little wary of thread-safety / potential timing issues related to the codes
object, but thanks for resolving my concern about the content of this function. The code as you have it is OK with me 👍
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.
Oh I'm not a fan of any mutable global variables, I wish there wasn't so many in docutils/sphinx 😅
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.
Hadn't looked at it yet but you might need to fix the ColorizeFormatter of the logging module as well. That was what I wanted to fix yesterday so that the environment variable is handled properly in loggers.
Didn't see your questions, sorry.
This can be configured I think by changing the environment variable by using |
this looks ok to me, basically it ends up calling: Line 88 in 3f3d3d8
and |
I don't believe this to be the case for testing; these variables are only evaluated in |
Rather than having singular
nocolor
andcoloron
functions (left for back-compatibility, introduce acolorize_output
context manager, for temporarily enabling / disabling colorized output streams, on entering, then return to the initial state on exit.Two outstandung questions:
make_app
is now set to always have color deactivated (which helps for checking output strings), but maybe this should be configurable?