base.py 1.1 KB

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