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

list: disable pip version self check unless given --outdated/--uptodate #12646

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/11677.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``pip list`` no longer performs the pip version check unless ``--outdated`` or ``--uptodate`` is given.
4 changes: 4 additions & 0 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def add_options(self) -> None:
self.parser.insert_option_group(0, index_opts)
self.parser.insert_option_group(0, self.cmd_opts)

def handle_pip_version_check(self, options: Values) -> None:
if options.outdated or options.uptodate:
super().handle_pip_version_check(options)

def _build_package_finder(
self, options: Values, session: PipSession
) -> PackageFinder:
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Callable, List
from unittest import mock

Expand Down Expand Up @@ -104,6 +105,10 @@ def test_index_group_handle_pip_version_check(
options.disable_pip_version_check = disable_pip_version_check
options.no_index = no_index

# See test test_list_pip_version_check() below.
if command_name == "list":
expected_called = False

command.handle_pip_version_check(options)
if expected_called:
mock_version_check.assert_called_once()
Expand All @@ -120,3 +125,20 @@ def is_requirement_command(command: Command) -> bool:
return isinstance(command, RequirementCommand)

check_commands(is_requirement_command, ["download", "install", "wheel"])


@pytest.mark.parametrize("flag", ["", "--outdated", "--uptodate"])
@mock.patch("pip._internal.cli.req_command.pip_self_version_check")
@mock.patch.dict(os.environ, {"PIP_DISABLE_PIP_VERSION_CHECK": "no"})
def test_list_pip_version_check(version_check_mock: mock.Mock, flag: str) -> None:
"""
Ensure that pip list doesn't perform a version self-check unless given
--outdated or --uptodate (as they require hitting the network anyway).
"""
command = create_command("list")
command.run = lambda *args, **kwargs: 0 # type: ignore[method-assign]
command.main([flag])
if flag != "":
version_check_mock.assert_called_once()
else:
version_check_mock.assert_not_called()
Loading