base.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import abc
  2. from typing import TYPE_CHECKING, Optional
  3. from pip._internal.metadata.base import BaseDistribution
  4. from pip._internal.req import InstallRequirement
  5. if TYPE_CHECKING:
  6. from pip._internal.index.package_finder import PackageFinder
  7. class AbstractDistribution(metaclass=abc.ABCMeta):
  8. """A base class for handling installable artifacts.
  9. The requirements for anything installable are as follows:
  10. - we must be able to determine the requirement name
  11. (or we can't correctly handle the non-upgrade case).
  12. - for packages with setup requirements, we must also be able
  13. to determine their requirements without installing additional
  14. packages (for the same reason as run-time dependencies)
  15. - we must be able to create a Distribution object exposing the
  16. above metadata.
  17. - if we need to do work in the build tracker, we must be able to generate a unique
  18. string to identify the requirement in the build tracker.
  19. """
  20. def __init__(self, req: InstallRequirement) -> None:
  21. super().__init__()
  22. self.req = req
  23. @abc.abstractproperty
  24. def build_tracker_id(self) -> Optional[str]:
  25. """A string that uniquely identifies this requirement to the build tracker.
  26. If None, then this dist has no work to do in the build tracker, and
  27. ``.prepare_distribution_metadata()`` will not be called."""
  28. raise NotImplementedError()
  29. @abc.abstractmethod
  30. def get_metadata_distribution(self) -> BaseDistribution:
  31. raise NotImplementedError()
  32. @abc.abstractmethod
  33. def prepare_distribution_metadata(
  34. self,
  35. finder: "PackageFinder",
  36. build_isolation: bool,
  37. check_build_deps: bool,
  38. ) -> None:
  39. raise NotImplementedError()