From 29913b01e31c30411872af98a1678bee9bc1eb80 Mon Sep 17 00:00:00 2001 From: Andrew Snare Date: Tue, 16 Jul 2024 11:26:16 +0200 Subject: [PATCH] Move the abstract methods to a single location. --- src/databricks/labs/blueprint/paths.py | 92 +++++++++++++------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/databricks/labs/blueprint/paths.py b/src/databricks/labs/blueprint/paths.py index 041e339..6b921ff 100644 --- a/src/databricks/labs/blueprint/paths.py +++ b/src/databricks/labs/blueprint/paths.py @@ -204,6 +204,52 @@ def _splitroot(cls, part: str, sep: str) -> tuple[str, str]: return sep, part.lstrip(sep) return "", part + @abstractmethod + def as_uri(self) -> str: ... + + @abstractmethod + def as_fuse(self) -> Path: ... + + @abstractmethod + def exists(self, *, follow_symlinks: bool = True) -> bool: ... + + @abstractmethod + def mkdir(self, mode: int = 0o600, parents: bool = True, exist_ok: bool = True) -> None: ... + + @abstractmethod + def rmdir(self, recursive: bool = False) -> None: ... + + @abstractmethod + def unlink(self, missing_ok: bool = False) -> None: ... + + @abstractmethod + def open( + self, + mode: str = "r", + buffering: int = -1, + encoding: str | None = None, + errors: str | None = None, + newline: str | None = None, + ): ... + + @abstractmethod + def is_dir(self) -> bool: ... + + @abstractmethod + def is_file(self) -> bool: ... + + @abstractmethod + def rename(self: P, target: str | bytes | os.PathLike) -> P: ... + + @abstractmethod + def replace(self: P, target: str | bytes | os.PathLike) -> P: ... + + @abstractmethod + def expanduser(self: P) -> P: ... + + @abstractmethod + def iterdir(self: P) -> Generator[P, None, None]: ... + def __reduce__(self) -> NoReturn: # Cannot support pickling because we can't pickle the workspace client. msg = f"Pickling {self.__class__.__qualname__} paths is not supported." @@ -445,12 +491,6 @@ def home(self): # pylint: disable=arguments-differ """Return the user's home directory. Adapted from pathlib.Path""" return type(self)(self._ws, "~").expanduser() - @abstractmethod - def rename(self: P, target: str | bytes | os.PathLike) -> P: ... - - @abstractmethod - def replace(self: P, target: str | bytes | os.PathLike) -> P: ... - def _return_false(self) -> bool: return False @@ -514,46 +554,6 @@ def rglob( selector = _Selector.parse(pattern_parts, case_sensitive=case_sensitive) yield from selector(self) - @abstractmethod - def as_uri(self) -> str: ... - - @abstractmethod - def as_fuse(self) -> Path: ... - - @abstractmethod - def exists(self, *, follow_symlinks: bool = True) -> bool: ... - - @abstractmethod - def mkdir(self, mode: int = 0o600, parents: bool = True, exist_ok: bool = True) -> None: ... - - @abstractmethod - def rmdir(self, recursive: bool = False) -> None: ... - - @abstractmethod - def unlink(self, missing_ok: bool = False) -> None: ... - - @abstractmethod - def open( - self, - mode: str = "r", - buffering: int = -1, - encoding: str | None = None, - errors: str | None = None, - newline: str | None = None, - ): ... - - @abstractmethod - def is_dir(self) -> bool: ... - - @abstractmethod - def is_file(self) -> bool: ... - - @abstractmethod - def expanduser(self: P) -> P: ... - - @abstractmethod - def iterdir(self: P) -> Generator[P, None, None]: ... - class DBFSPath(_DatabricksPath): """Experimental implementation of pathlib.Path for DBFS paths."""