base.py 1.8 KB

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