Skip to content

Commit

Permalink
fix: Find rye pythons with and without install directory (#25)
Browse files Browse the repository at this point in the history
Starting with rye 0.31 (released today), it by default installs python
toolchains without the intermediate install directory (but both options
continue to exist).

As a side effect, this also picks up some other rye toolchains that were
already installed without the intermediate install - for example pypy
toolchains installed with rye.
  • Loading branch information
bluss committed Mar 25, 2024
1 parent a3f514c commit 8e1837d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/findpython/providers/rye.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def find_pythons(self) -> t.Iterable[PythonVersion]:
for child in safe_iter_dir(py_root):
if child.is_symlink(): # registered an existing python
continue
if WINDOWS:
python_bin = child / "install/python.exe"
else:
python_bin = child / "install/bin/python3"
if python_bin.exists():
yield self.version_maker(python_bin, _interpreter=python_bin)
for intermediate in ("", "install/"):
if WINDOWS:
python_bin = child / (intermediate + "python.exe")
else:
python_bin = child / (intermediate + "bin/python3")
if python_bin.exists():
yield self.version_maker(python_bin, _interpreter=python_bin)
break
10 changes: 8 additions & 2 deletions tests/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ def test_find_python_from_rye_provider(mocked_python, tmp_path, monkeypatch):
python310 = mocked_python.add_python(
tmp_path / ".rye/py/cpython@3.10.9/install/bin/python3", "3.10.9"
)
python311 = mocked_python.add_python(
tmp_path / ".rye/py/cpython@3.11.8/bin/python3", "3.11.8"
)
monkeypatch.setenv("HOME", str(tmp_path))

register_provider(RyeProvider)
pythons = Finder(selected_providers=["rye"]).find_all(3, 10)
assert python310 in pythons
find_310 = Finder(selected_providers=["rye"]).find_all(3, 10)
assert python310 in find_310

find_311 = Finder(selected_providers=["rye"]).find_all(3, 11)
assert python311 in find_311

0 comments on commit 8e1837d

Please sign in to comment.