__init__.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from typing import List, Optional
  2. from .base import BaseDistribution, BaseEnvironment, FilesystemWheel, MemoryWheel, Wheel
  3. __all__ = [
  4. "BaseDistribution",
  5. "BaseEnvironment",
  6. "FilesystemWheel",
  7. "MemoryWheel",
  8. "Wheel",
  9. "get_default_environment",
  10. "get_environment",
  11. "get_wheel_distribution",
  12. ]
  13. def get_default_environment() -> BaseEnvironment:
  14. """Get the default representation for the current environment.
  15. This returns an Environment instance from the chosen backend. The default
  16. Environment instance should be built from ``sys.path`` and may use caching
  17. to share instance state accorss calls.
  18. """
  19. from .pkg_resources import Environment
  20. return Environment.default()
  21. def get_environment(paths: Optional[List[str]]) -> BaseEnvironment:
  22. """Get a representation of the environment specified by ``paths``.
  23. This returns an Environment instance from the chosen backend based on the
  24. given import paths. The backend must build a fresh instance representing
  25. the state of installed distributions when this function is called.
  26. """
  27. from .pkg_resources import Environment
  28. return Environment.from_paths(paths)
  29. def get_wheel_distribution(wheel: Wheel, canonical_name: str) -> BaseDistribution:
  30. """Get the representation of the specified wheel's distribution metadata.
  31. This returns a Distribution instance from the chosen backend based on
  32. the given wheel's ``.dist-info`` directory.
  33. :param canonical_name: Normalized project name of the given wheel.
  34. """
  35. from .pkg_resources import Distribution
  36. return Distribution.from_wheel(wheel, canonical_name)