base.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import abc
  2. from typing import Optional
  3. from pip._vendor.pkg_resources import Distribution
  4. from pip._internal.index.package_finder import PackageFinder
  5. from pip._internal.req import InstallRequirement
  6. class AbstractDistribution(metaclass=abc.ABCMeta):
  7. """A base class for handling installable artifacts.
  8. The requirements for anything installable are as follows:
  9. - we must be able to determine the requirement name
  10. (or we can't correctly handle the non-upgrade case).
  11. - for packages with setup requirements, we must also be able
  12. to determine their requirements without installing additional
  13. packages (for the same reason as run-time dependencies)
  14. - we must be able to create a Distribution object exposing the
  15. above metadata.
  16. """
  17. def __init__(self, req: InstallRequirement) -> None:
  18. super().__init__()
  19. self.req = req
  20. @abc.abstractmethod
  21. def get_pkg_resources_distribution(self) -> Optional[Distribution]:
  22. raise NotImplementedError()
  23. @abc.abstractmethod
  24. def prepare_distribution_metadata(
  25. self, finder: PackageFinder, build_isolation: bool
  26. ) -> None:
  27. raise NotImplementedError()