-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add a global option to disable colors #4739
Conversation
This is a fix for issue pypa#2449 All it does is simply add a global option --no-color Internally it switches ColorizedStreamHandler to StreamHandler if this flag is detected.
As a note for my PR, the above desired behaviour for detecting whether we can output color or not, is an issue of colorama. This is a simpler fix for cases like:
Which is almost exactly what the title of the issue says:
The only difference is the my PR is switching off colors 😄 |
BTW you need to fix the lint errors before the PR will be reviewed. |
* not sure it makes the code more readable though ...
@xoviat some tests failed now, but I don't understand why, the exact same tests worked before I linted my code. Can you or some other contributor restart the build with out me pushing code again? This seems like a temporary name resolution error:
|
I've restarted the failed ones. |
@pfmoore Thanks! now all tests pass! I hope that this PR can be soon reviewed and merged. |
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.
Looks good barring one minor issue. :)
Ping @oz123! :) |
docs/reference/pip.rst
Outdated
@@ -24,7 +24,9 @@ Console logging | |||
~~~~~~~~~~~~~~~ | |||
|
|||
pip offers :ref:`-v, --verbose <--verbose>` and :ref:`-q, --quiet <--quiet>` | |||
to control the console log level. | |||
to control the console log level. By default, some messages (error and warnnings) |
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.
typo: warnings
* As requested per review * Make the code shorter and easier to follow
@pradyunsg, the requested changes have been implemented. Thanks for reminding me ... |
@pradyunsg @xavfernandez , can you please review my changes? I would be happy if this is merged. |
Thanks for the reminder. I'll try to do it in the evening today. |
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.
A test would be nice though I'm not sure how that'd work. I'm fine with the implementation and documentation.
I'm also fine if you just add a comment above no-color saying it's not tested by the test suite.
I could add a test that is based on the cache feature. Like I showed in the screenshot. |
I think just uninstall based one would be fine too.
|
@pradyunsg, I finally had some time to add a functional test. I hope you would approve it. |
* The version found in Travis-CI does not respect this flag It added a prefix line and suffix line found if one does not add the flag --quiet (script from util-linux 2.26.2). As such the out put is: Script started on Fri 27 Oct 2017 07:17:30 AM CEST \x1b[31mCannot uninstall requirement noSuchPackage, not installed\x1b[0m\n Script done on Fri 27 Oct 2017 07:17:31 AM CEST With this change, the test should pass, and is hopefully more stable.
@pradyunsg, ping. Any more questions or suggestions for this PR? Can it be merged? |
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.
A quick skim looks good.
I'll look at this again in a little bit. :)
import pytest | ||
|
||
|
||
@pytest.mark.skipif(sys.platform == 'win32', |
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.
A cross-platform test would be nice to have.
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.
@pradyunsg , I would love that too, but it is unfair to ask me to implement this. I have no access to
a windows machine.
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.
No issues then. :)
That should retrigger CI. I'll wait for another @pypa/pip-committers to review this. :) |
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.
Even if I'm not a fan of the test with subprocess but I don't see another solution.
Thanks for this @oz123! :) |
* Add a global option to disable colors This is a fix for issue pypa#2449 All it does is simply add a global option --no-color Internally it switches ColorizedStreamHandler to StreamHandler if this flag is detected. * Fix lint errors * not sure it makes the code more readable though ... * Fix typo * Choose logging class before assigning * As requested per review * Make the code shorter and easier to follow * Be polite to followers, add commas * Add functional test for the --no-color output * Better detection of windows * Fix fragile tests - can't trust script --quiet * The version found in Travis-CI does not respect this flag It added a prefix line and suffix line found if one does not add the flag --quiet (script from util-linux 2.26.2). As such the out put is: Script started on Fri 27 Oct 2017 07:17:30 AM CEST \x1b[31mCannot uninstall requirement noSuchPackage, not installed\x1b[0m\n Script done on Fri 27 Oct 2017 07:17:31 AM CEST With this change, the test should pass, and is hopefully more stable. * Simplify testing for color or no-color
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This is a fix for issue #2449
All it does is simply add a global option --no-color
Internally it switches ColorizedStreamHandler to StreamHandler if
this flag is detected.