Skip to content
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
1 change: 1 addition & 0 deletions docs/changelog/188.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Match literal interpreter names against the executable found on ``PATH``, including symlink names.
2 changes: 1 addition & 1 deletion src/python_discovery/_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def _satisfies_path(self, spec: PythonSpec) -> bool:
return True
if spec.is_abs:
return True
basename = os.path.basename(self.original_executable)
basename = os.path.basename(self.executable)
spec_path = spec.path
if sys.platform == "win32":
basename, suffix = os.path.splitext(basename)
Expand Down
4 changes: 2 additions & 2 deletions tests/py_info/test_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ def test_py_info_ignores_distutils_config(monkeypatch: pytest.MonkeyPatch, tmp_p
def test_discover_exe_on_path_non_spec_name_match(mocker: MockerFixture) -> None:
suffixed_name = f"python{CURRENT.version_info.major}.{CURRENT.version_info.minor}m"
if sys.platform == "win32": # pragma: win32 cover
suffixed_name += Path(CURRENT.original_executable).suffix
suffixed_name += Path(CURRENT.executable).suffix
spec = PythonSpec.from_string_spec(suffixed_name)
mocker.patch.object(CURRENT, "original_executable", str(Path(CURRENT.executable).parent / suffixed_name))
mocker.patch.object(CURRENT, "executable", str(Path(CURRENT.executable).parent / suffixed_name))
assert CURRENT.satisfies(spec, impl_must_match=True) is True


Expand Down
11 changes: 11 additions & 0 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ def test_discovery_via_path_not_found(tmp_path: Path, monkeypatch: pytest.Monkey
assert interpreter is None


@pytest.mark.skipif(sys.platform == "win32", reason="POSIX symlink names")
def test_discovery_via_path_literal_symlink(tmp_path: Path) -> None:
link = tmp_path / "python_custom"
link.symlink_to(sys.executable)

interpreter = get_interpreter("python_custom", [], env={"PATH": str(tmp_path)})

assert interpreter is not None
assert interpreter.executable == str(link)


def test_discovery_via_path_in_nonbrowseable_directory(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
bad_perm = tmp_path / "bad_perm"
bad_perm.mkdir(mode=0o000)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_py_info_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_satisfies_path_not_abs_basename_no_match() -> None:
def test_satisfies_path_win32(mocker: MockerFixture) -> None:
info = copy.deepcopy(CURRENT)
mocker.patch.object(sys, "platform", "win32")
info.original_executable = "/some/path/python.exe"
info.executable = "/some/path/python.exe"
spec = PythonSpec.from_string_spec("python")
spec.path = "python"
assert info.satisfies(spec, impl_must_match=False) is True
Expand Down
14 changes: 13 additions & 1 deletion tests/windows/test_windows.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
from __future__ import annotations

import sys
from pathlib import Path

import pytest

from python_discovery import PythonSpec
from python_discovery import PythonSpec, get_interpreter


@pytest.mark.skipif(sys.platform != "win32", reason="Windows executable alias")
def test_discovery_via_path_literal_symlink(tmp_path: Path) -> None:
link = tmp_path / "python_custom.exe"
link.symlink_to(Path(sys.base_prefix) / "python.exe")

interpreter = get_interpreter("python_custom", [], env={"PATH": f"{tmp_path};{sys.base_prefix}"})

assert interpreter is not None
assert interpreter.executable == str(link)


@pytest.mark.skipif(sys.platform != "win32", reason="propose_interpreters calls from_exe with Windows paths")
Expand Down