[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

Skip self version check on EXTERNALLY-MANAGED environments #13064

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/11820.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The pip version self check is disabled on ``EXTERNALLY-MANAGED`` environments.
10 changes: 9 additions & 1 deletion src/pip/_internal/self_outdated_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
get_best_invocation_for_this_python,
)
from pip._internal.utils.filesystem import adjacent_tmp_file, check_path_owner, replace
from pip._internal.utils.misc import ensure_dir
from pip._internal.utils.misc import (
ExternallyManagedEnvironment,
check_externally_managed,
ensure_dir,
)

_WEEK = datetime.timedelta(days=7)

Expand Down Expand Up @@ -231,6 +235,10 @@ def pip_self_version_check(session: PipSession, options: optparse.Values) -> Non
installed_dist = get_default_environment().get_distribution("pip")
if not installed_dist:
return
try:
check_externally_managed()
except ExternallyManagedEnvironment:
return

upgrade_prompt = _self_version_check_logic(
state=SelfCheckState(cache_dir=options.cache_dir),
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_self_check_outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from pip._vendor.packaging.version import Version

from pip._internal import self_outdated_check
from pip._internal.self_outdated_check import UpgradePrompt, pip_self_version_check
from pip._internal.utils.misc import ExternallyManagedEnvironment


@pytest.mark.parametrize(
Expand Down Expand Up @@ -185,3 +187,15 @@ def test_writes_expected_statefile(self, tmpdir: Path) -> None:
"last_check": "2000-01-01T00:00:00+00:00",
"pypi_version": "1.0.0",
}


@patch("pip._internal.self_outdated_check._self_version_check_logic")
def test_suppressed_by_externally_managed(mocked_function: Mock, tmpdir: Path) -> None:
mocked_function.return_value = UpgradePrompt(old="1.0", new="2.0")
fake_options = Values({"cache_dir": str(tmpdir)})
with patch(
"pip._internal.self_outdated_check.check_externally_managed",
side_effect=ExternallyManagedEnvironment("nope"),
):
pip_self_version_check(session=Mock(), options=fake_options)
mocked_function.assert_not_called()
Loading