Skip to content

Commit

Permalink
Fix python path resolution on linux (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitznik authored Jan 12, 2024
1 parent 5563ae6 commit 2441503
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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:
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)

0 comments on commit 2441503

Please sign in to comment.