From a68776fa85369a23e776d50a99f7f59d1d52205b Mon Sep 17 00:00:00 2001 From: Andrew Snare Date: Tue, 16 Jul 2024 12:12:45 +0200 Subject: [PATCH] Factor out mkdir() argument validation. --- src/databricks/labs/blueprint/paths.py | 30 +++++++++++--------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/databricks/labs/blueprint/paths.py b/src/databricks/labs/blueprint/paths.py index bc2a886..3fc9219 100644 --- a/src/databricks/labs/blueprint/paths.py +++ b/src/databricks/labs/blueprint/paths.py @@ -212,7 +212,7 @@ def as_fuse(self) -> Path: ... def exists(self, *, follow_symlinks: bool = True) -> bool: ... @abstractmethod - def mkdir(self, mode: int = 0o600, parents: bool = True, exist_ok: bool = True) -> None: ... + def _mkdir(self) -> None: ... @abstractmethod def rmdir(self, recursive: bool = False) -> None: ... @@ -525,6 +525,16 @@ def absolute(self: P) -> P: return self return self.with_segments(self.cwd(), self) + def mkdir(self, mode: int = 0o600, parents: bool = True, exist_ok: bool = True) -> None: + """Create a directory;Only mode 0o600 is supported.""" + if not exist_ok: + raise ValueError("exist_ok must be True for Databricks Workspace") + if not parents: + raise ValueError("parents must be True for Databricks Workspace") + if mode != 0o600: + raise ValueError("other modes than 0o600 are not yet supported") + self._mkdir() + def _prepare_pattern(self, pattern: str | bytes | os.PathLike) -> Sequence[str]: if not pattern: raise ValueError("Glob pattern must not be empty.") @@ -600,14 +610,7 @@ def exists(self, *, follow_symlinks: bool = True) -> bool: except NotFound: return False - def mkdir(self, mode: int = 0o600, parents: bool = True, exist_ok: bool = True) -> None: - """Create a directory in DBFS. Only mode 0o600 is supported.""" - if not exist_ok: - raise ValueError("exist_ok must be True for Databricks Workspace") - if not parents: - raise ValueError("parents must be True for Databricks Workspace") - if mode != 0o600: - raise ValueError("other modes than 0o600 are not yet supported") + def _mkdir(self) -> None: self._ws.dbfs.mkdirs(self.as_posix()) def rmdir(self, recursive: bool = False) -> None: @@ -740,14 +743,7 @@ def exists(self, *, follow_symlinks: bool = True) -> bool: except NotFound: return False - def mkdir(self, mode: int = 0o600, parents: bool = True, exist_ok: bool = True) -> None: - """Create a directory in Databricks Workspace. Only mode 0o600 is supported.""" - if not exist_ok: - raise ValueError("exist_ok must be True for Databricks Workspace") - if not parents: - raise ValueError("parents must be True for Databricks Workspace") - if mode != 0o600: - raise ValueError("other modes than 0o600 are not yet supported") + def _mkdir(self) -> None: self._ws.workspace.mkdirs(self.as_posix()) def rmdir(self, recursive: bool = False) -> None: