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
2 changes: 2 additions & 0 deletions docs/changelog/147.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Treat specs with dot-only version components, such as ``python.``, as literal executable paths instead of raising
``IndexError`` - by :user:`harbinresearcher`.
3 changes: 3 additions & 0 deletions src/python_discovery/_py_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def _int_or_none(val: str | None) -> int | None:

def _parse_version_parts(version: str) -> tuple[int | None, int | None, int | None]:
versions = tuple(int(i) for i in version.split(".") if i)
if not versions:
msg = "version must contain a numeric component"
raise ValueError(msg)
if len(versions) > _MAX_VERSION_PARTS:
msg = "too many version parts"
raise ValueError(msg)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ def test_discovery_fallback_fail(session_cache: DiskCache, caplog: pytest.LogCap
assert "accepted" not in caplog.text


def test_discovery_fallback_ok(session_cache: DiskCache, caplog: pytest.LogCaptureFixture) -> None:
@pytest.mark.parametrize("missing", ["magic-one", "python."])
def test_discovery_fallback_ok(missing: str, session_cache: DiskCache, caplog: pytest.LogCaptureFixture) -> None:
caplog.set_level(logging.DEBUG)
result = get_interpreter(["magic-one", sys.executable], cache=session_cache)
result = get_interpreter([missing, sys.executable], cache=session_cache)
assert result is not None, caplog.text
assert result.executable == sys.executable, caplog.text
assert "accepted" in caplog.text
Expand Down
4 changes: 2 additions & 2 deletions tests/test_py_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from pathlib import Path


def test_bad_py_spec() -> None:
text = "python2.3.4.5"
@pytest.mark.parametrize("text", ["python2.3.4.5", ".", "..", "...", "python.", "cpython..", "pypy..."])
def test_bad_py_spec(text: str) -> None:
spec = PythonSpec.from_string_spec(text)
assert text in repr(spec)
assert spec.str_spec == text
Expand Down