Skip to content
Closed
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/5073.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes open issue where uninstalling a package that exists outside the environment returns an incorrect exit status.
4 changes: 3 additions & 1 deletion src/pip/_internal/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from importlib.util import cache_from_source
from typing import Any, Callable

from pip._internal.cli.status_codes import ERROR
from pip._internal.exceptions import LegacyDistutilsInstall, UninstallMissingRecord
from pip._internal.locations import get_bin_prefix, get_bin_user
from pip._internal.metadata import BaseDistribution
Expand Down Expand Up @@ -355,8 +356,9 @@ def remove(self, auto_confirm: bool = False, verbose: bool = False) -> None:

if not self._paths:
logger.info(
"Can't uninstall '%s'. No files were found to uninstall.",
"Can't uninstall '%s'. Exists outside environment, exit status %s.",
self._dist.raw_name,
ERROR,
)
return

Expand Down
4 changes: 3 additions & 1 deletion tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,9 @@ def test_uninstallpathset_no_paths(caplog: pytest.LogCaptureFixture) -> None:
uninstall_set = UninstallPathSet(test_dist)
uninstall_set.remove() # with no files added to set

assert "Can't uninstall 'pip'. No files were found to uninstall." in caplog.text
assert (
"Can't uninstall 'pip'. Exists outside environment, exit status" in caplog.text
)


def test_uninstall_non_local_distutils(
Expand Down