wheel.py 1.3 KB

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