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

Fix cleanup of app binaries for venvs without pipx_metadata.json #651

Merged
merged 11 commits into from
Mar 24, 2021

Conversation

itsayellow
Copy link
Contributor

  • I have added an entry to docs/changelog.md

Summary of changes

Found this code bug with mypy --warn-unreachable.

This PR fixes a bug with pipx uninstall that would leave app binaries leftover in ~/.local/bin if the venv has no metadata file.

We were testing the wrong object to determine if metadata was present in uninstall.py. venv.pipx_metadata.main_package is in fact always not None, (it's always PackageInfo) so the else (for missing metadata case) was impossible to execute. Thus the special cleanup code for the non-metadata case to remove app binaries never executed.

I fixed it by changing the test for None to the object venv.pipx_metadata.main_package.package.

In addition, I updated venv.get_venv_metadata_for_package to add its currently-necessary second argument. (This code must have been unreachable for a while to not get flagged that it is missing an argument.)

Test plan

Tested by running

pipx install pycowsay
rm ~/.local/pipx/venvs/pycowsay/pipx_metadata.json
pipx uninstall pycowsay

This PR:

> ls -l ~/.local/bin/pycowsay
ls: /Users/mclapp/.local/bin/pycowsay: No such file or directory

pipx 0.16.1.0

> ls -l ~/.local/bin/pycowsay                     
lrwxr-xr-x  1 mclapp  staff  53 Mar 19 22:54 /Users/mclapp/.local/bin/pycowsay@ -> /Users/mclapp/.local/pipx/venvs/pycowsay/bin/pycowsay

@itsayellow itsayellow linked an issue Mar 21, 2021 that may be closed by this pull request
@itsayellow
Copy link
Contributor Author

I suppose I should be a "grown up" and add a test for this large block of code that isn't being tested...

@itsayellow itsayellow merged commit 9c48b61 into pypa:master Mar 24, 2021
@itsayellow itsayellow deleted the uninstall-unreachable branch March 24, 2021 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect code in uninstall() makes branch unreachable
1 participant