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 3 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
7 changes: 0 additions & 7 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 Down Expand Up @@ -47,12 +46,6 @@ def reinstall(
else:
package_or_url = venv.main_package_name

if importlib.util.find_spec("pip") is 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."
)

uninstall(venv_dir, local_bin_dir, verbose)

# in case legacy original dir name
Expand Down
12 changes: 11 additions & 1 deletion src/pipx/shared_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ def create(self, verbose: bool = False) -> None:

@property
def is_valid(self) -> bool:
return self.python_path.is_file() and self.pip_path.is_file()
if self.python_path.is_file():
check_pip = "import importlib.util; print(importlib.util.find_spec('pip'))"
out = run_subprocess(
[self.python_path, "-c", check_pip],
capture_stderr=False,
log_cmd_str="<checking pip's availability>",
).stdout.strip()

return self.pip_path.is_file() and out != "None"
else:
return False

@property
def needs_upgrade(self) -> bool:
Expand Down