pip icon indicating copy to clipboard operation
pip copied to clipboard

`pip list --quiet` squelches normal output

Open aukalas opened this issue 5 years ago • 3 comments

Environment

  • pip version: 20.1.1
  • Python version: Python 2.7/3.8
  • OS: Arch Linux

Description When running pip list --quiet or pip list --quiet --quiet, normal output is suppressed, not just warnings. This differs from the behavior of pip freeze (which I am switching from as advised in https://github.com/pypa/pip/issues/8174#issuecomment-621649797).

Expected behavior Package listing is output, but no warnings.

Actual behavior With --quiet, only warnings are output. With --quiet --quiet, nothing is output.

How to Reproduce

  • Run in Python 2 so that you get the deprecation notice. (This is not necessary, but illustrates better what's happening.)
  • Have a few packages installed.

See below for commands to try.

Output

$ pip2 list --format=freeze
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
appdirs==1.4.4
[…]
$ pip2 list --format=freeze --quiet
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
$ pip2 list --format=freeze --quiet --quiet

For comparison:

$ pip2 freeze                       
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
appdirs==1.4.4
[…]
$ pip2 freeze --quiet
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
-f https://leifarne%40auka.io:8YxwbRIe4MAlV5XtXBGVVRY68DWb4S2Rc4x1qNeO6vA@auka-build-tools.appspot.com/find-links
appdirs==1.4.4
[…]
$ pip2 freeze --quiet --quiet
appdirs==1.4.4
[…]

aukalas avatar Jul 09 '20 11:07 aukalas

So we decide the verbosity of a command here:

https://github.com/pypa/pip/blob/2f9b50c097fa5e655cd2978b682fc79ed2e6295f/src/pip/_internal/cli/base_command.py#L137

and then the following function defined the log level based on verbosity value

https://github.com/pypa/pip/blob/2f9b50c097fa5e655cd2978b682fc79ed2e6295f/src/pip/_internal/utils/logging.py#L278-L294

When we pass -qq to pip list --format=freeze, we have self.verbosity == -2, making log level as ERROR, and none of the write_output functions below are called, which are at log level INFO

https://github.com/pypa/pip/blob/2f9b50c097fa5e655cd2978b682fc79ed2e6295f/src/pip/_internal/commands/list.py#L240-L246

deveshks avatar Jul 09 '20 16:07 deveshks

Thanks @deveshks! :raised_hands: Should list also be using sys.stdout.write, like freeze? Seems appropriate, since the package list is the desired output of the command (it's not exactly logging).

aukalas avatar Jul 27 '20 09:07 aukalas

I also 'vote' for sys.stdout.write. I think just removing the if around the write_output calls would still pass the outut as the wrong level? I can do the PR if accepted

bartoli avatar Dec 09 '25 12:12 bartoli