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 python path resolution on linux #1196

Merged
merged 5 commits into from
Jan 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Update `pipx run` on scripts using `/// script` and no `run` table following the updated version of PEP 723 (#1180)
- Avoid repeated exception logging in a few rare cases (#1192)
- Include `tomli` into `pipx.pyz` (zipapp) so that it can be executed with Python 3.10 or earlier (#1142)
- Fix resolving the python executable path on linux
- `pipx run`: Verify whether the script name provided is a file before running it

## 1.4.1
Expand Down
2 changes: 1 addition & 1 deletion src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def run_subprocess(
# 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]):
if not os.path.islink(cmd_str_list[0]) and WINDOWS:
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
cmd_str_list[0] = os.path.realpath(cmd_str_list[0])
completed_process = subprocess.run(
cmd_str_list,
Expand Down
26 changes: 26 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys

import pytest # type: ignore

from pipx import util
from pipx.util import run_subprocess


@pytest.mark.skipif(sys.platform.startswith("win"), reason="Path resolution skip if not on windows")
def test_executable_path_resolution_unix():
cmd = ["python99.99", "-c", "import sys;"]
try:
run_subprocess(cmd)
except FileNotFoundError as e:
assert "No such file or directory: 'python99.99'" in str(e)


@pytest.mark.skipif(sys.platform.startswith("win"), reason="Path resolution skip if not on windows")
def test_executable_path_resolution_fails_on_unix_if_not_skipped(monkeypatch: pytest.MonkeyPatch):
cmd = ["python99.99", "-c", "import sys;"]
monkeypatch.setattr(util, "WINDOWS", True)
monkeypatch.chdir("./tests")
try:
run_subprocess(cmd)
except FileNotFoundError as e:
assert "tests/python99.99'" in str(e)