Skip to content

Commit

Permalink
Merge branch 'main' into run-python-3.13-ci-tests-
Browse files Browse the repository at this point in the history
  • Loading branch information
notatallshaw authored Apr 29, 2024
2 parents 90295fb + f18bebd commit 8c7dfb7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:

tests-unix:
name: tests / ${{ matrix.python.key || matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}

needs: [packaging, determine-changes]
if: >-
Expand All @@ -107,7 +107,7 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [Ubuntu, MacOS]
os: [ubuntu-latest, macos-12]
python:
- "3.8"
- "3.9"
Expand All @@ -124,13 +124,13 @@ jobs:
allow-prereleases: true

- name: Install Ubuntu dependencies
if: matrix.os == 'Ubuntu'
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install bzr
- name: Install MacOS dependencies
if: matrix.os == 'MacOS'
if: matrix.os == 'macos-12'
run: brew install breezy

- run: pip install nox
Expand Down
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()

0 comments on commit 8c7dfb7

Please sign in to comment.