wheel.py 1.2 KB

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