base.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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):
  18. # type: (InstallRequirement) -> None
  19. super().__init__()
  20. self.req = req
  21. @abc.abstractmethod
  22. def get_pkg_resources_distribution(self):
  23. # type: () -> Optional[Distribution]
  24. raise NotImplementedError()
  25. @abc.abstractmethod
  26. def prepare_distribution_metadata(self, finder, build_isolation):
  27. # type: (PackageFinder, bool) -> None
  28. raise NotImplementedError()