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

Add a global option to disable colors #4739

Merged
merged 9 commits into from
Nov 5, 2017
Merged

Conversation

oz123
Copy link
Contributor

@oz123 oz123 commented Sep 27, 2017

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.

pip-fix

 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.
@oz123
Copy link
Contributor Author

oz123 commented Sep 27, 2017

should have an auto mode which disables coloring when not a tty but also allow for manual override.

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:

Same thing when building docker images with PyCharm. The ANSI sequences and deflated output make it hard to spot issues quickly.

Which is almost exactly what the title of the issue says:

pip needs a way to force all colours off

The only difference is the my PR is switching off colors 😄

@ghost
Copy link

ghost commented Sep 28, 2017

BTW you need to fix the lint errors before the PR will be reviewed.

 * not sure it makes the code more readable though ...
@oz123
Copy link
Contributor Author

oz123 commented Sep 28, 2017

@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:

warning: connecting to bitbucket.org using legacy security technology (TLS 1.0); see https://mercurial-scm.org/wiki/SecureConnections for more info

abort: HTTP Error 404: Not Found

@pfmoore
Copy link
Member

pfmoore commented Sep 28, 2017

I've restarted the failed ones.

@oz123
Copy link
Contributor Author

oz123 commented Sep 29, 2017

@pfmoore Thanks! now all tests pass! I hope that this PR can be soon reviewed and merged.

Copy link
Member

@pradyunsg pradyunsg left a 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. :)

@pradyunsg pradyunsg added type: enhancement Improvements to functionality C: logging Information Logging labels Sep 29, 2017
@pradyunsg
Copy link
Member

Ping @oz123! :)

@@ -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)
Copy link
Member

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
@oz123
Copy link
Contributor Author

oz123 commented Oct 7, 2017

@pradyunsg, the requested changes have been implemented. Thanks for reminding me ...

src/pip/_internal/cmdoptions.py Outdated Show resolved Hide resolved
src/pip/_internal/cmdoptions.py Outdated Show resolved Hide resolved
@oz123
Copy link
Contributor Author

oz123 commented Oct 20, 2017

@pradyunsg @xavfernandez , can you please review my changes? I would be happy if this is merged.

@pradyunsg
Copy link
Member

Thanks for the reminder. I'll try to do it in the evening today.

Copy link
Member

@pradyunsg pradyunsg left a 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.

@oz123
Copy link
Contributor Author

oz123 commented Oct 21, 2017

@pradyunsg ,

I could add a test that is based on the cache feature. Like I showed in the screenshot.
What do you think about that?

@pradyunsg
Copy link
Member

I think just uninstall based one would be fine too.

pip uninstall not_installed_package would print it with \033 and pip uninstall --no-color not_installed_package would not. That should be a good test.

@pradyunsg pradyunsg added type: feature request Request for a new feature and removed type: enhancement Improvements to functionality labels Oct 24, 2017
@oz123
Copy link
Contributor Author

oz123 commented Oct 26, 2017

@pradyunsg, I finally had some time to add a functional test. I hope you would approve it.
Unfortunately, I could not use the existing testing facilities (e.g. test.lib.TestPipResult), but I was able to add a test case using sp.Popen directly.

oz123 added 2 commits October 27, 2017 06:59
 * 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.
@oz123
Copy link
Contributor Author

oz123 commented Nov 4, 2017

@pradyunsg, ping. Any more questions or suggestions for this PR? Can it be merged?

Copy link
Member

@pradyunsg pradyunsg left a 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. :)

tests/functional/test_no_color.py Show resolved Hide resolved
import pytest


@pytest.mark.skipif(sys.platform == 'win32',
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues then. :)

tests/functional/test_no_color.py Outdated Show resolved Hide resolved
tests/functional/test_no_color.py Outdated Show resolved Hide resolved
@pradyunsg pradyunsg closed this Nov 4, 2017
@pradyunsg pradyunsg reopened this Nov 4, 2017
@pradyunsg
Copy link
Member

That should retrigger CI.


I'll wait for another @pypa/pip-committers to review this. :)

Copy link
Member

@xavfernandez xavfernandez left a 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.

@xavfernandez xavfernandez added this to the 10.0 milestone Nov 4, 2017
@pradyunsg pradyunsg merged commit 4370a5a into pypa:master Nov 5, 2017
@pradyunsg
Copy link
Member

Thanks for this @oz123! :)

kianasun pushed a commit to kianasun/pip that referenced this pull request Mar 28, 2018
* 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
@lock
Copy link

lock bot commented Jun 2, 2019

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.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation C: logging Information Logging type: feature request Request for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants