from zenml.enums import StackComponentType
from zenml.stack import StackComponent, StackComponentConfig
PathType = Union[bytes, str]
class BaseArtifactStoreConfig(StackComponentConfig):
"""Config class for `BaseArtifactStore`."""
path: str
SUPPORTED_SCHEMES: ClassVar[Set[str]]
class BaseArtifactStore(StackComponent):
"""Base class for all ZenML artifact stores."""
@abstractmethod
def open(self, name: PathType, mode: str = "r") -> Any:
"""Open a file at the given path."""
@abstractmethod
def copyfile(
self, src: PathType, dst: PathType, overwrite: bool = False
) -> None:
"""Copy a file from the source to the destination."""
@abstractmethod
def exists(self, path: PathType) -> bool:
"""Returns `True` if the given path exists."""
@abstractmethod
def glob(self, pattern: PathType) -> List[PathType]:
"""Return the paths that match a glob pattern."""
@abstractmethod
def isdir(self, path: PathType) -> bool:
"""Returns whether the given path points to a directory."""
@abstractmethod
def listdir(self, path: PathType) -> List[PathType]:
"""Returns a list of files under a given directory in the filesystem."""
@abstractmethod
def makedirs(self, path: PathType) -> None:
"""Make a directory at the given path, recursively creating parents."""
@abstractmethod
def mkdir(self, path: PathType) -> None:
"""Make a directory at the given path; parent directory must exist."""
@abstractmethod
def remove(self, path: PathType) -> None:
"""Remove the file at the given path. Dangerous operation."""
@abstractmethod
def rename(
self, src: PathType, dst: PathType, overwrite: bool = False
) -> None:
"""Rename source file to destination file."""
@abstractmethod
def rmtree(self, path: PathType) -> None:
"""Deletes dir recursively. Dangerous operation."""
@abstractmethod
def stat(self, path: PathType) -> Any:
"""Return the stat descriptor for a given file path."""
@abstractmethod
def walk(
self,
top: PathType,
topdown: bool = True,
onerror: Optional[Callable[..., None]] = None,
) -> Iterable[Tuple[PathType, List[PathType], List[PathType]]]:
"""Return an iterator that walks the contents of the given directory."""
class BaseArtifactStoreFlavor(Flavor):
"""Base class for artifact store flavors."""
@property
@abstractmethod
def name(self) -> Type["BaseArtifactStore"]:
"""Returns the name of the flavor."""
@property
def type(self) -> StackComponentType:
"""Returns the flavor type."""
return StackComponentType.ARTIFACT_STORE
@property
def config_class(self) -> Type[StackComponentConfig]:
"""Config class."""
return BaseArtifactStoreConfig
@property
@abstractmethod
def implementation_class(self) -> Type["BaseArtifactStore"]:
"""Implementation class."""