Skip to content

Mixed-case spec prefixes such as Python3.12 or GraalVM3.12 find no interpreter #270

Closed

Description

@HarshJamgaonkar05

_spec_from_match in src/python_discovery/_py_spec.py drops the generic py/python prefix and maps graalvm to
graalpy, but only when the prefix is lowercase:

impl = match["impl"]
if impl in {"py", "python"}:
    impl = None
if impl == "graalvm":
    impl = "graalpy"

Everything downstream compares implementation names case-insensitively (PythonSpec.satisfies,
PythonInfo._satisfies_implementation, the uv install filter, the IGNORECASE filename regex), so CPython3.12
works. Python3.12 instead keeps "Python" as the implementation. When a python3.12 executable is found on PATH,
the finder requires the interpreter to report that implementation. "python" != "cpython" rejects it, as it does the
current interpreter and uv installs. The spec only works if an executable with exactly that spelling, Python3.12, is
on PATH.

Reproducer (Windows, CPython 3.12 from uv, main at b7f7a6e):

import os, sys
from python_discovery import PythonSpec, get_interpreter

path = os.path.dirname(sys._base_executable)  # holds python.exe
for s in ("python3.12", "CPython3.12", "Python3.12", "Py3.12", "Python>=3.12", "GraalVM3.12"):
    info = get_interpreter(s, [], env={"PATH": path, "UV_PYTHON_INSTALL_DIR": path + "/missing"})
    print(f"{s:14} {PythonSpec.from_string_spec(s).implementation!s:8} -> {info and info.executable}")
python3.12     None     -> ...\.venv\Scripts\python.exe
CPython3.12    CPython  -> ...\.venv\Scripts\python.exe
Python3.12     Python   -> None
Py3.12         Py       -> None
Python>=3.12   Python   -> None
GraalVM3.12    GraalVM  -> None

It shows up in virtualenv (python-discovery 1.9.5): virtualenv -p python3.13 venv works, while
virtualenv -p Python3.13 venv fails with RuntimeError: failed to find interpreter for Builtin discover of python_spec='Python3.13'.

Proposed fix: lowercase the prefix before checking the aliases. Happy to send a PR with tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions