__init__.py 858 B

123456789101112131415161718192021
  1. from pip._internal.distributions.base import AbstractDistribution
  2. from pip._internal.distributions.sdist import SourceDistribution
  3. from pip._internal.distributions.wheel import WheelDistribution
  4. from pip._internal.req.req_install import InstallRequirement
  5. def make_distribution_for_install_requirement(
  6. install_req: InstallRequirement,
  7. ) -> AbstractDistribution:
  8. """Returns a Distribution for the given InstallRequirement"""
  9. # Editable requirements will always be source distributions. They use the
  10. # legacy logic until we create a modern standard for them.
  11. if install_req.editable:
  12. return SourceDistribution(install_req)
  13. # If it's a wheel, it's a WheelDistribution
  14. if install_req.is_wheel:
  15. return WheelDistribution(install_req)
  16. # Otherwise, a SourceDistribution
  17. return SourceDistribution(install_req)