Skip to content

Commit 2324303

Browse files
authored
Merge pull request #13064 from ichard26/block-upgrade-prompt
Skip self version check on EXTERNALLY-MANAGED environments
2 parents c432c33 + 69533e3 commit 2324303

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

news/11820.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The pip version self check is disabled on ``EXTERNALLY-MANAGED`` environments.

src/pip/_internal/self_outdated_check.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
get_best_invocation_for_this_python,
2727
)
2828
from pip._internal.utils.filesystem import adjacent_tmp_file, check_path_owner, replace
29-
from pip._internal.utils.misc import ensure_dir
29+
from pip._internal.utils.misc import (
30+
ExternallyManagedEnvironment,
31+
check_externally_managed,
32+
ensure_dir,
33+
)
3034

3135
_WEEK = datetime.timedelta(days=7)
3236

@@ -231,6 +235,10 @@ def pip_self_version_check(session: PipSession, options: optparse.Values) -> Non
231235
installed_dist = get_default_environment().get_distribution("pip")
232236
if not installed_dist:
233237
return
238+
try:
239+
check_externally_managed()
240+
except ExternallyManagedEnvironment:
241+
return
234242

235243
upgrade_prompt = _self_version_check_logic(
236244
state=SelfCheckState(cache_dir=options.cache_dir),

tests/unit/test_self_check_outdated.py

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from pip._vendor.packaging.version import Version
1515

1616
from pip._internal import self_outdated_check
17+
from pip._internal.self_outdated_check import UpgradePrompt, pip_self_version_check
18+
from pip._internal.utils.misc import ExternallyManagedEnvironment
1719

1820

1921
@pytest.mark.parametrize(
@@ -185,3 +187,15 @@ def test_writes_expected_statefile(self, tmpdir: Path) -> None:
185187
"last_check": "2000-01-01T00:00:00+00:00",
186188
"pypi_version": "1.0.0",
187189
}
190+
191+
192+
@patch("pip._internal.self_outdated_check._self_version_check_logic")
193+
def test_suppressed_by_externally_managed(mocked_function: Mock, tmpdir: Path) -> None:
194+
mocked_function.return_value = UpgradePrompt(old="1.0", new="2.0")
195+
fake_options = Values({"cache_dir": str(tmpdir)})
196+
with patch(
197+
"pip._internal.self_outdated_check.check_externally_managed",
198+
side_effect=ExternallyManagedEnvironment("nope"),
199+
):
200+
pip_self_version_check(session=Mock(), options=fake_options)
201+
mocked_function.assert_not_called()

0 commit comments

Comments
 (0)