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:
Pradyun S. Gedam 2017-08-03 04:55:21 +05:30 committed by Pradyun Gedam
parent e8bdaa76e5
commit 8222d788f6
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
2 changed files with 24 additions and 3 deletions

View File

@ -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)

View File

@ -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"