Skip to content

Commit 8c7dfb7

Browse files
authored
Merge branch 'main' into run-python-3.13-ci-tests-
2 parents 90295fb + f18bebd commit 8c7dfb7

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797

9898
tests-unix:
9999
name: tests / ${{ matrix.python.key || matrix.python }} / ${{ matrix.os }}
100-
runs-on: ${{ matrix.os }}-latest
100+
runs-on: ${{ matrix.os }}
101101

102102
needs: [packaging, determine-changes]
103103
if: >-
@@ -107,7 +107,7 @@ jobs:
107107
strategy:
108108
fail-fast: true
109109
matrix:
110-
os: [Ubuntu, MacOS]
110+
os: [ubuntu-latest, macos-12]
111111
python:
112112
- "3.8"
113113
- "3.9"
@@ -124,13 +124,13 @@ jobs:
124124
allow-prereleases: true
125125

126126
- name: Install Ubuntu dependencies
127-
if: matrix.os == 'Ubuntu'
127+
if: matrix.os == 'ubuntu-latest'
128128
run: |
129129
sudo apt-get update
130130
sudo apt-get install bzr
131131
132132
- name: Install MacOS dependencies
133-
if: matrix.os == 'MacOS'
133+
if: matrix.os == 'macos-12'
134134
run: brew install breezy
135135

136136
- run: pip install nox

news/11677.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``pip list`` no longer performs the pip version check unless ``--outdated`` or ``--uptodate`` is given.

src/pip/_internal/commands/list.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def add_options(self) -> None:
135135
self.parser.insert_option_group(0, index_opts)
136136
self.parser.insert_option_group(0, self.cmd_opts)
137137

138+
def handle_pip_version_check(self, options: Values) -> None:
139+
if options.outdated or options.uptodate:
140+
super().handle_pip_version_check(options)
141+
138142
def _build_package_finder(
139143
self, options: Values, session: PipSession
140144
) -> PackageFinder:

tests/unit/test_commands.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Callable, List
23
from unittest import mock
34

@@ -104,6 +105,10 @@ def test_index_group_handle_pip_version_check(
104105
options.disable_pip_version_check = disable_pip_version_check
105106
options.no_index = no_index
106107

108+
# See test test_list_pip_version_check() below.
109+
if command_name == "list":
110+
expected_called = False
111+
107112
command.handle_pip_version_check(options)
108113
if expected_called:
109114
mock_version_check.assert_called_once()
@@ -120,3 +125,20 @@ def is_requirement_command(command: Command) -> bool:
120125
return isinstance(command, RequirementCommand)
121126

122127
check_commands(is_requirement_command, ["download", "install", "wheel"])
128+
129+
130+
@pytest.mark.parametrize("flag", ["", "--outdated", "--uptodate"])
131+
@mock.patch("pip._internal.cli.req_command.pip_self_version_check")
132+
@mock.patch.dict(os.environ, {"PIP_DISABLE_PIP_VERSION_CHECK": "no"})
133+
def test_list_pip_version_check(version_check_mock: mock.Mock, flag: str) -> None:
134+
"""
135+
Ensure that pip list doesn't perform a version self-check unless given
136+
--outdated or --uptodate (as they require hitting the network anyway).
137+
"""
138+
command = create_command("list")
139+
command.run = lambda *args, **kwargs: 0 # type: ignore[method-assign]
140+
command.main([flag])
141+
if flag != "":
142+
version_check_mock.assert_called_once()
143+
else:
144+
version_check_mock.assert_not_called()

0 commit comments

Comments
 (0)