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/238.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reject generic Python executables when a requested implementation is unavailable.
4 changes: 2 additions & 2 deletions src/python_discovery/_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ def path_exes(path: Path) -> Generator[tuple[Path, bool], None, None]:
yield direct_path, impl_must_match

for exe in path.iterdir():
if pat.fullmatch(exe.name):
yield exe.absolute(), impl_must_match
if match := pat.fullmatch(exe.name):
yield exe.absolute(), impl_must_match or match["impl"].lower() == "python"

return path_exes

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


def test_unknown_implementation_rejects_python_on_path(tmp_path: Path, session_cache: DiskCache) -> None:
env = {"PATH": str(Path(sys.executable).parent), "UV_PYTHON_INSTALL_DIR": str(tmp_path / "missing")}

assert get_interpreter("missing", [], cache=session_cache, env=env) is None
assert list(iter_interpreters("missing", cache=session_cache, env=env)) == []


@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"
Expand Down