local_registry.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """Local registry implementation."""
  2. import logging
  3. from typing_extensions import Self
  4. from wandb.docker import is_docker_installed
  5. from wandb.sdk.launch.errors import LaunchError
  6. from wandb.sdk.launch.utils import docker_image_exists
  7. from .abstract import AbstractRegistry
  8. _logger = logging.getLogger(__name__)
  9. class LocalRegistry(AbstractRegistry):
  10. """A local registry.
  11. This is a dummy registry that is used when no registry is configured.
  12. """
  13. def __init__(self) -> None:
  14. """Initialize a local registry."""
  15. @classmethod
  16. def from_config(
  17. cls,
  18. config: dict,
  19. ) -> Self:
  20. """Create a local registry from a config.
  21. Arguments:
  22. config (dict): The config. This is ignored.
  23. environment (AbstractEnvironment): The environment. This is ignored.
  24. Returns:
  25. LocalRegistry: The local registry.
  26. """
  27. return cls()
  28. async def verify(self) -> None:
  29. """Verify the local registry by doing nothing."""
  30. async def get_username_password(self) -> tuple[str, str]:
  31. """Get the username and password of the local registry."""
  32. raise LaunchError("Attempted to get username and password for LocalRegistry.")
  33. async def get_repo_uri(self) -> str:
  34. """Get the uri of the local registry.
  35. Returns: An empty string.
  36. """
  37. return ""
  38. async def check_image_exists(self, image_uri: str) -> bool:
  39. """Check if an image exists in the local registry.
  40. Arguments:
  41. image_uri (str): The uri of the image.
  42. Returns:
  43. bool: True.
  44. """
  45. if is_docker_installed():
  46. return docker_image_exists(image_uri)
  47. return False