Skip to content

Commit

Permalink
Factor out mkdir() argument validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
asnare committed Jul 16, 2024
1 parent 59be839 commit a68776f
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/databricks/labs/blueprint/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a68776f

Please sign in to comment.