Skip to content

pip uninstall -y <pkg> should warn when an extra file will not be removed #12445

@zanieb

Description

@zanieb

Description

pip uninstall -y <pkg> does not display warnings for files it does not remove, which means you can think an uninstall was successful while you are left in a bad state due to lingering files.

Expected behavior

pip uninstall -y <pkg> should display warnings for files that are not removed. This information is already shown for pip uninstall <pkg>.

e.g.

WARNING: Did not remove `.venv/lib/python3.11/site-packages/idna-3.6.dist-info/FOO

pip version

23.3.2

Python version

3.11.4

OS

macOS

How to Reproduce

Here's a script to reproduce in a clean environment:

python -m venv .venv
source .venv/bin/activate
python -m pip install pip==23.3.2 > /dev/null 2>&1

set -eux

SITE_PACKAGES=$(python -c 'import site; print(site.getsitepackages()[0])')
pip install --no-cache idna==3.6 > /dev/null 2>&1

# Create an extra file, this is "silly" but you can end up in this state without touching `site-packages` manually
touch $SITE_PACKAGES/idna-3.6.dist-info/FOO

# Shows "would not remove" warning
yes | pip uninstall idna

pip install --no-cache idna==3.6 > /dev/null 2>&1

# Does not show warning
pip uninstall -y idna

rm -rf .venv

Output

++ python -c 'import site; print(site.getsitepackages()[0])'
+ SITE_PACKAGES=.venv/lib/python3.11/site-packages
+ pip install --no-cache idna==3.6
+ touch .venv/lib/python3.11/site-packages/idna-3.6.dist-info/FOO
+ yes
+ pip uninstall idna
Found existing installation: idna 3.6
Uninstalling idna-3.6:
  Would remove:
    .venv/lib/python3.11/site-packages/idna-3.6.dist-info/*
    .venv/lib/python3.11/site-packages/idna/*
  Would not remove (might be manually added):
    .venv/lib/python3.11/site-packages/idna-3.6.dist-info/FOO
Proceed (Y/n)?   Successfully uninstalled idna-3.6
+ pip install --no-cache idna==3.6
+ pip uninstall -y idna
Found existing installation: idna 3.6
Uninstalling idna-3.6:
  Successfully uninstalled idna-3.6
+ rm -rf .venv

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    S: needs triageIssues/PRs that need to be triagedtype: bugA confirmed bug or unintended behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions