wheel.py 1.3 KB

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