Skip to content
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

colorama color doesn't reset properly when redirecting pip to stdout #6354

Closed
tusharlock10 opened this issue Mar 20, 2019 · 10 comments
Closed
Labels
C: logging Information Logging OS: windows Windows specific project: vendored dependency Related to a vendored dependency

Comments

@tusharlock10
Copy link

tusharlock10 commented Mar 20, 2019

Environment

  • pip version: Requirement already satisfied: pip in c:\python\lib\site-packages (19.0.3)
  • Python version: Python 3.7.2
  • OS: Windows 10 64 Bit

Using system interpreter

Description
The command line in windows stays red after entering a certain incorrect command, not all commands give this error. This happens in CMD and Powershell, I can't say about Linux or Mac.
It looks like this issue had occurred before - #2817 (Closed)
bug
bug2

Expected behavior
It is obvious, the expected behavior is that it should reset the colors back to white, after the error is over. Looks like someone forgot to reset in colorama.

How to Reproduce
Just type 'pip install > xyz' and this bug will appear. Also it only happens with the '>' symbol, and not with any other thing.

@cjerdonek
Copy link
Member

Can you see if this happened with version 18.1?

@tusharlock10
Copy link
Author

Yes the same issue appears on version 18.1
bug
This happened on version 17.1 and even version 10.0.0, so it is an old issue

Also, I tested it on macOS, and this issue isn't there. So I think it is Windows specific.

@cjerdonek
Copy link
Member

This might be stating the obvious, but two possibilities occur to me. Either--

  1. the redirect operator > is sending the color termination characters to the file you are redirecting to, or
  2. the use of the redirect operator is causing colorama to behave differently (e.g. causing it not to appear as a TTY).

I also wonder if this is a bug in colorama vs. pip's use of it.

@tusharlock10
Copy link
Author

tusharlock10 commented Mar 21, 2019

>>> import colorama as c
>>> c.init()
>>> x=c.Fore.RED+"pip install > xyz"+c.Style.RESET_ALL
>>> print(x)

This code is working fine and the lines below it aren't colored in RED. So it shouldn't be a colorama related issue.

@cjerdonek
Copy link
Member

cjerdonek commented Mar 21, 2019

This code is working fine and the lines below it aren't colored in RED. So it shouldn't be a colorama related issue.

The example you provided doesn't tell me it's not a colorama issue. All it says to me is that one particular combination of calls may work in one setting. Have you looked at what API's pip is using to invoke colorama?

Also, colorama's tracker seems to have a number of issues around Windows, various edge cases around TTY, redirection, etc. As one example, a very quick search yielded this issue, which seems similar to what you're reporting here (with title "Windows: Style.RESET_ALL does not work if stdout is redirected"): tartley/colorama#200

@tusharlock10
Copy link
Author

I tried to reproduce this issue tartley/colorama#200 , but it now no longer happening.
bug

Also, even if the issue occurs due to colorama, can't we apply a fix until the issue is fixed in colorama module.
Also, as you have said to look for the API's which pip uses to invoke colorama, I don't know how to look for that (not very experienced with open-source projects).

@cjerdonek cjerdonek added OS: windows Windows specific S: needs triage Issues/PRs that need to be triaged C: logging Information Logging labels Mar 21, 2019
@cjerdonek
Copy link
Member

I tried to reproduce this issue tartley/colorama#200 , but it now no longer happening.

FYI, you didn't follow their instructions. You need to put those lines in a separate file and then execute from the command-line (not Python prompt).

Also, even if the issue occurs due to colorama, can't we apply a fix until the issue is fixed in colorama module.

The policy here would be to fix the issue in colorama. It seems like it would be doable to me, if I were to guess.

@cjerdonek cjerdonek added project: vendored dependency Related to a vendored dependency and removed S: needs triage Issues/PRs that need to be triaged labels Mar 22, 2019
@cjerdonek cjerdonek changed the title Command gets colored in red and stays red after entering a wrong command colorama color doesn't reset properly when redirecting pip to stdout Mar 22, 2019
@cjerdonek
Copy link
Member

I filed an issue for this in colorama's tracker here: tartley/colorama#218

@tusharlock10
Copy link
Author

Great, hope they fix it soon.

@ichard26
Copy link
Member

We don't even use colorama anymore as our vendored copy of Rich uses Windows APIs to replace colorama on legacy environments. I can't reproduce the issue in the modern Windows 11 terminal (apparently Win+R and cmd.exe still uses the modern terminal...)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: logging Information Logging OS: windows Windows specific project: vendored dependency Related to a vendored dependency
Projects
None yet
Development

No branches or pull requests

3 participants