mirror of https://github.com/pypa/pip
Switch pip uninstall behaviour to be idempotent
pip uninstall no longer aborts if a package is not installed; instead it prints a warning that the package is not installed and it is skipping the uninstallation of it for this reason.
This commit is contained in:
parent
e8bdaa76e5
commit
8222d788f6
|
@ -648,9 +648,8 @@ class InstallRequirement(object):
|
|||
|
||||
"""
|
||||
if not self.check_if_exists():
|
||||
raise UninstallationError(
|
||||
"Cannot uninstall requirement %s, not installed" % (self.name,)
|
||||
)
|
||||
logger.warning("Skipping %s as it is not installed.", self.name)
|
||||
return
|
||||
dist = self.satisfied_by or self.conflicts_with
|
||||
|
||||
uninstalled_pathset = UninstallPathSet.from_dist(dist)
|
||||
|
|
|
@ -468,3 +468,25 @@ def test_uninstall_editable_and_pip_install(script, data):
|
|||
) in uninstall2.files_deleted, list(uninstall2.files_deleted.keys())
|
||||
list_result2 = script.pip('list', '--format=json')
|
||||
assert "FSPkg" not in {p["name"] for p in json.loads(list_result2.stdout)}
|
||||
|
||||
|
||||
def test_uninstall_ignores_missing_packages(script, data):
|
||||
"""Uninstall of a non existent package prints a warning and exits cleanly
|
||||
"""
|
||||
result = script.pip(
|
||||
'uninstall', '-y', 'non-existent-pkg', expect_stderr=True,
|
||||
)
|
||||
|
||||
assert "Skipping non-existent-pkg as it is not installed." in result.stderr
|
||||
assert result.returncode == 0, "Expected clean exit"
|
||||
|
||||
|
||||
def test_uninstall_ignores_missing_packages_and_uninstalls_rest(script, data):
|
||||
script.pip_install_local('simple')
|
||||
result = script.pip(
|
||||
'uninstall', '-y', 'non-existent-pkg', 'simple', expect_stderr=True,
|
||||
)
|
||||
|
||||
assert "Skipping non-existent-pkg as it is not installed." in result.stderr
|
||||
assert "Successfully uninstalled simple" in result.stdout
|
||||
assert result.returncode == 0, "Expected clean exit"
|
||||
|
|
Loading…
Reference in New Issue