__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. FindPython
  3. ~~~~~~~~~~
  4. A utility to find python versions on your system
  5. """
  6. from __future__ import annotations
  7. from typing import TYPE_CHECKING, TypeVar
  8. from findpython.finder import Finder
  9. from findpython.providers import ALL_PROVIDERS
  10. from findpython.providers.base import BaseProvider
  11. from findpython.python import PythonVersion
  12. def find(*args, **kwargs) -> PythonVersion | None:
  13. """
  14. Return the Python version that is closest to the given version criteria.
  15. :param major: The major version or the version string or the name to match.
  16. :param minor: The minor version to match.
  17. :param patch: The micro version to match.
  18. :param pre: Whether the python is a prerelease.
  19. :param dev: Whether the python is a devrelease.
  20. :param name: The name of the python.
  21. :param architecture: The architecture of the python.
  22. :return: a Python object or None
  23. """
  24. return Finder().find(*args, **kwargs)
  25. def find_all(*args, **kwargs) -> list[PythonVersion]:
  26. """
  27. Return all Python versions matching the given version criteria.
  28. :param major: The major version or the version string or the name to match.
  29. :param minor: The minor version to match.
  30. :param patch: The micro version to match.
  31. :param pre: Whether the python is a prerelease.
  32. :param dev: Whether the python is a devrelease.
  33. :param name: The name of the python.
  34. :param architecture: The architecture of the python.
  35. :return: a list of PythonVersion objects
  36. """
  37. return Finder().find_all(*args, **kwargs)
  38. if TYPE_CHECKING:
  39. P = TypeVar("P", bound=type[BaseProvider])
  40. def register_provider(provider: P) -> P:
  41. """
  42. Register a provider to use when finding python versions.
  43. :param provider: A provider class
  44. """
  45. ALL_PROVIDERS[provider.name()] = provider
  46. return provider
  47. __all__ = ["Finder", "find", "find_all", "PythonVersion", "register_provider"]