wheel.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from pip._vendor.packaging.utils import canonicalize_name
  2. from pip._internal.distributions.base import AbstractDistribution
  3. from pip._internal.index.package_finder import PackageFinder
  4. from pip._internal.metadata import (
  5. BaseDistribution,
  6. FilesystemWheel,
  7. get_wheel_distribution,
  8. )
  9. class WheelDistribution(AbstractDistribution):
  10. """Represents a wheel distribution.
  11. This does not need any preparation as wheels can be directly unpacked.
  12. """
  13. def get_metadata_distribution(self) -> BaseDistribution:
  14. """Loads the metadata from the wheel file into memory and returns a
  15. Distribution that uses it, not relying on the wheel file or
  16. requirement.
  17. """
  18. assert self.req.local_file_path, "Set as part of preparation during download"
  19. assert self.req.name, "Wheels are never unnamed"
  20. wheel = FilesystemWheel(self.req.local_file_path)
  21. return get_wheel_distribution(wheel, canonicalize_name(self.req.name))
  22. def prepare_distribution_metadata(
  23. self, finder: PackageFinder, build_isolation: bool
  24. ) -> None:
  25. pass