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

Check whether pip module exists in shared lib before performing any actions #1111

Merged
merged 7 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## dev

- Use virtual environment's Python to check for pip's availability during reinstalling process
- Drop support for Python 3.7
- Make usage message in `pipx run` show `package_or_url`, so extra will be printed out as well
- Add `--force-reinstall` to pip arguments when `--force` was passed
Expand Down
11 changes: 8 additions & 3 deletions src/pipx/commands/reinstall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import importlib.util
import sys
from pathlib import Path
from typing import List, Sequence
Expand All @@ -17,7 +16,7 @@
ExitCode,
)
from pipx.emojis import error, sleep
from pipx.util import PipxError
from pipx.util import PipxError, run_subprocess
from pipx.venv import Venv, VenvContainer


Expand Down Expand Up @@ -47,7 +46,13 @@ def reinstall(
else:
package_or_url = venv.main_package_name

if importlib.util.find_spec("pip") is None:
check_pip = "import importlib.util; print(importlib.util.find_spec('pip'))"
out = run_subprocess(
[venv.python_path, "-c", check_pip],
capture_stderr=False,
log_cmd_str="<checking pip's availability>",
).stdout.strip()
if out == "None":
raise PipxError(
f"Can not find pip. You may encounter issues uninstalling packages. "
f"Remove {PIPX_SHARED_LIBS} and run 'pipx reinstall-all' to fix them."
Expand Down