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 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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## dev

- Check whether pip module exists in shared lib before performing any actions, such as `reinstall-all`.
- Drop `setuptools` and `wheel` from the shared libraries. This results in less time consumption when the libraries are
automatically upgraded.
- Allow running `pip` with `pipx run`
Expand Down
8 changes: 0 additions & 8 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 @@ -13,7 +12,6 @@
EXIT_CODE_OK,
EXIT_CODE_REINSTALL_INVALID_PYTHON,
EXIT_CODE_REINSTALL_VENV_NONEXISTENT,
PIPX_SHARED_LIBS,
ExitCode,
)
from pipx.emojis import error, sleep
Expand Down Expand Up @@ -52,12 +50,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, local_man_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
Loading