fix(cli): preserve display output with --quiet #14155
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
I'm not sure why we need this helper function. If the goal is to reduce show_on_quiet=True noise, let's just make True the default and explicitly set exceptions to False. That would clean things up and let us remove this helper.
Any reason this uses %-style formatting? Could just use .format(): return str(msg).format(*args)
I think we can be a bit more defensive here by moving logger.info(msg, *args) after the if branch. What do you think?
AssertionError exceptions usually indicate programming errors and generally shouldn't be swallowed. If there's a good reason for this, could you add a brief comment explaining why? Otherwise, I think this should be removed.
Since pip already has RichPipStreamHandler in pip._internal.utils.logging, I think we can change this to if not isinstance(handler, RichPipStreamHandler). To keep things clean, it might make sense to move this to src/pip/_internal/utils/logging.py.
Can you add a docstring here?
Hi @ychampion, thanks for your contribution!
I'm +1 on this overall. This is something I've wanted to tackle for a long time but never got around to.
The PR looks good overall, though I've left a few comments that I think would improve it further. Let me know if you have any questions!
Done in 55548c41d. write_output now defaults to showing primary display output under quiet mode, so show.py no longer needs the local helper.
I kept % formatting because the same msg, *args are still passed to logger.info, which uses logging-style interpolation. I added a short comment in the helper to make that explicit.
Done in 55548c41d. The direct quiet fallback now returns before the normal logger.info path; otherwise it falls through to logging.
Done in 55548c41d. Removed the AssertionError handling; the fallback now calls get_console() directly instead of hiding a missing console.
Done in 55548c41d. I moved the fallback helpers into utils/logging.py and now check for RichPipStreamHandler directly.
Done in 55548c41d.
Why did you add show_on_quiet=True here? Nothing else is changing this parameter, so why not just pass it to write_output explicitly?
?
Thanks for addressing the review comments. I've left a couple more; let me know if you need any help with them.
Agreed. Removed the helper parameter and passed show_on_quiet=True directly at the write_output calls.
Cleaned up; that blank-line-only diff is gone now.
Hey @notatallshaw, would you mind taking a look at this when you have a chance? You mentioned earlier that you'd be happy to review a PR for this issue if someone submitted one. Thanks!
sepehr-rs
ychampion
What does this PR do?
Fixes #13018.
--quietcurrently raises pip's logging threshold, which also hides primary output from display commands. This keeps primary display output visible when quiet mode suppressesINFOlogs, while leaving install/download progress output quiet-suppressible.Covered display paths include
show,help,index versions,list,check,hash,cache dir/info/list,config get/list/debug,debug, andsearchoutput.Validation:
uv run --with pre-commit pre-commit run black --files <touched Python files>uv run --with pre-commit pre-commit run ruff-check --files <touched Python files>uv run --with nox nox -s test-3.12 -- tests/functional/test_show.py tests/functional/test_help.py tests/functional/test_index.py tests/functional/test_check.py tests/functional/test_list.py tests/functional/test_hash.py tests/functional/test_cache.py tests/functional/test_configuration.py tests/functional/test_debug.py tests/unit/test_command_show.py -quv run --with nox nox -s test-3.12 -- tests/functional/test_install.py::test_install_quiet -qlist --quiet,show --quiet,cache dir --quiet, andinstall --dry-run --quietPR Checklist:
AI tools used: Codex.