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

Pass real paths when running subprocesses #1168

Merged
merged 3 commits into from
Dec 28, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## dev

- Delete directories directly instead of spawning rmdir on Windows
- Fix "Failed to delete" error when using Microsoft Store Python
- Fix "No pyvenv.cfg file" error when using Microsoft Store Python (#1164)
- Add `--quiet` and `--verbose` options for the `pipx` subcommands
- [docs] Add Scoop installation instructions
- Add ability to install multiple packages at once
Expand Down
13 changes: 9 additions & 4 deletions src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ def rmdir(path: Path, safe_rm: bool = True) -> None:

logger.info(f"removing directory {path}")
try:
if WINDOWS:
os.system(f'rmdir /S /Q "{str(path)}"')
else:
shutil.rmtree(path)
shutil.rmtree(path)
except FileNotFoundError:
pass

Expand Down Expand Up @@ -171,6 +168,14 @@ def run_subprocess(
logger.info(f"running {log_cmd_str}")
# windows cannot take Path objects, only strings
cmd_str_list = [str(c) for c in cmd]
# Make sure to call the binary using its real path. This matters especially on Windows when using the packaged app
# (Microsoft Store) version of Python, which uses path redirection for sandboxing. If the path to the executable is
# redirected, the executable can get confused as to which directory it's being run from, leading to problems.
# See https://github.com/pypa/pipx/issues/1164
# Conversely, if the binary is a symlink, then we should NOT use the real path, as Python expects to receive the
# symlink in argv[0] so that it can locate the venv.
if not os.path.islink(cmd_str_list[0]):
cmd_str_list[0] = os.path.realpath(cmd_str_list[0])
completed_process = subprocess.run(
cmd_str_list,
env=env,
Expand Down