rye.py 913 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. import shutil
  3. import typing as t
  4. from pathlib import Path
  5. from findpython.providers.base import BaseProvider
  6. from findpython.python import PythonVersion
  7. from findpython.utils import safe_iter_dir
  8. class RyeProvider(BaseProvider):
  9. def __init__(self) -> None:
  10. self.root = Path.home() / ".rye"
  11. self.rye_bin = shutil.which("rye")
  12. @classmethod
  13. def create(cls) -> t.Self | None:
  14. return cls()
  15. def find_pythons(self) -> t.Iterable[PythonVersion]:
  16. py_root = self.root / "py"
  17. if not py_root.exists():
  18. return
  19. for child in safe_iter_dir(py_root):
  20. if child.is_symlink(): # registered an existing python
  21. continue
  22. python_bin = child / "install/bin/python3"
  23. if python_bin.exists():
  24. yield self.version_maker(python_bin, _interpreter=python_bin)