diff --git a/CHANGELOG.md b/CHANGELOG.md index bed7454dae..756ee9d4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/pipx/util.py b/src/pipx/util.py index 3e899aa69e..fad47c82cf 100644 --- a/src/pipx/util.py +++ b/src/pipx/util.py @@ -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, diff --git a/tests/test_util.py b/tests/test_util.py new file mode 100644 index 0000000000..f013782c5f --- /dev/null +++ b/tests/test_util.py @@ -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)