macos.py 759 B

1234567891011121314151617181920212223242526
  1. from __future__ import annotations
  2. import typing as t
  3. from pathlib import Path
  4. from findpython.providers.base import BaseProvider
  5. from findpython.python import PythonVersion
  6. class MacOSProvider(BaseProvider):
  7. """A provider that finds python from macos typical install base
  8. with python.org installer.
  9. """
  10. INSTALL_BASE = Path("/Library/Frameworks/Python.framework/Versions/")
  11. @classmethod
  12. def create(cls) -> t.Self | None:
  13. if not cls.INSTALL_BASE.exists():
  14. return None
  15. return cls()
  16. def find_pythons(self) -> t.Iterable[PythonVersion]:
  17. for version in self.INSTALL_BASE.iterdir():
  18. if version.is_dir():
  19. yield from self.find_pythons_from_path(version / "bin", True)