Repository navigation
Set coloured output with a context manager - #12134
chrisjsewell wants to merge 1 commit into
Conversation
| if on: | ||
| coloron() | ||
| else: | ||
| nocolor() | ||
| yield |
There was a problem hiding this comment.
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.
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.
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.
Oh I'm not a fan of any mutable global variables, I wish there wasn't so many in docutils/sphinx 😅
picnixz
left a comment
There was a problem hiding this comment.
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 |
|
I don't think this is needed now that we don't wrap stdout/stderr on Windows (#12493). A |
@AA-Turner I would perhaps disagree, the point is that colorization should not be just globally set to "on forever" whenever sphinx is run, More specifically, most unit tests, for sphinx core and for sphinx extensions, should not have colorisation enabled, #12493 is certainly an improvement, but I don't see that it achieves this? |
Rather than having singular
nocolorandcoloronfunctions (left for back-compatibility, introduce acolorize_outputcontext manager, for temporarily enabling / disabling colorized output streams, on entering, then return to the initial state on exit.Two outstandung questions:
make_appis now set to always have color deactivated (which helps for checking output strings), but maybe this should be configurable?