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

Error handling upon uninstall invalid parameter #10171

Merged
merged 2 commits into from
Jul 24, 2021
Merged
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/4958.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a warning when passing an invalid requirement to ``pip uninstall``.
10 changes: 10 additions & 0 deletions src/pip/_internal/commands/uninstall.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from optparse import Values
from typing import List

Expand All @@ -14,6 +15,8 @@
)
from pip._internal.utils.misc import protect_pip_from_modification_on_windows

logger = logging.getLogger(__name__)
uranusjr marked this conversation as resolved.
Show resolved Hide resolved


class UninstallCommand(Command, SessionCommandMixin):
"""
Expand Down Expand Up @@ -60,6 +63,13 @@ def run(self, options, args):
)
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
else:
logger.warning(
"Invalid requirement: %r ignored -"
" the uninstall command expects named"
" requirements.",
name,
)
for filename in options.requirements:
for parsed_req in parse_requirements(
filename,
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ def test_basic_uninstall_with_scripts(script):
)


@pytest.mark.parametrize("name",
["GTrolls.tar.gz",
"https://guyto.com/archives/"])
def test_uninstall_invalid_parameter(script, caplog, name):
result = script.pip("uninstall", name, "-y", expect_error=True)
expected_message = (
f"Invalid requirement: '{name}' ignored -"
f" the uninstall command expects named requirements."
)
assert expected_message in result.stderr


@pytest.mark.network
def test_uninstall_easy_install_after_import(script):
"""
Expand Down