Skip to content

Commit 2441503

Browse files
authored
Fix python path resolution on linux (#1196)
1 parent 5563ae6 commit 2441503

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Update `pipx run` on scripts using `/// script` and no `run` table following the updated version of PEP 723 (#1180)
66
- Avoid repeated exception logging in a few rare cases (#1192)
77
- Include `tomli` into `pipx.pyz` (zipapp) so that it can be executed with Python 3.10 or earlier (#1142)
8+
- Fix resolving the python executable path on linux
89
- `pipx run`: Verify whether the script name provided is a file before running it
910

1011
## 1.4.1

src/pipx/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def run_subprocess(
174174
# See https://github.com/pypa/pipx/issues/1164
175175
# Conversely, if the binary is a symlink, then we should NOT use the real path, as Python expects to receive the
176176
# symlink in argv[0] so that it can locate the venv.
177-
if not os.path.islink(cmd_str_list[0]):
177+
if not os.path.islink(cmd_str_list[0]) and WINDOWS:
178178
cmd_str_list[0] = os.path.realpath(cmd_str_list[0])
179179
completed_process = subprocess.run(
180180
cmd_str_list,

tests/test_util.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
import pytest # type: ignore
4+
5+
from pipx import util
6+
from pipx.util import run_subprocess
7+
8+
9+
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Path resolution skip if not on windows")
10+
def test_executable_path_resolution_unix():
11+
cmd = ["python99.99", "-c", "import sys;"]
12+
try:
13+
run_subprocess(cmd)
14+
except FileNotFoundError as e:
15+
assert "No such file or directory: 'python99.99'" in str(e)
16+
17+
18+
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Path resolution skip if not on windows")
19+
def test_executable_path_resolution_fails_on_unix_if_not_skipped(monkeypatch: pytest.MonkeyPatch):
20+
cmd = ["python99.99", "-c", "import sys;"]
21+
monkeypatch.setattr(util, "WINDOWS", True)
22+
monkeypatch.chdir("./tests")
23+
try:
24+
run_subprocess(cmd)
25+
except FileNotFoundError as e:
26+
assert "tests/python99.99'" in str(e)

0 commit comments

Comments
 (0)