Skip to content

Commit

Permalink
Revert "added an extra variable for system specific path to use pathl…
Browse files Browse the repository at this point in the history
…ib.Path functions"

This reverts commit 16dc404.
  • Loading branch information
parthban-db committed Jun 12, 2024
1 parent 9a67da8 commit 3833e11
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions databricks/sdk/mixins/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ class _Path(ABC):

def __init__(self, path: str):
self._path = pathlib.PurePosixPath(str(path).replace('dbfs:', '').replace('file:', ''))
self._system_path = pathlib.Path(self._path)

@property
def is_local(self) -> bool:
Expand Down Expand Up @@ -338,18 +337,18 @@ def child(self, path: str) -> Self:
return _LocalPath(str(self._path / path))

def _is_dir(self) -> bool:
return self._system_path.is_dir()
return self._path.is_dir()

def mkdir(self):
self._system_path.mkdir(mode=0o755, parents=True, exist_ok=True)
self._path.mkdir(mode=0o755, parents=True, exist_ok=True)

def exists(self) -> bool:
return self._system_path.exists()
return self._path.exists()

def open(self, *, read=False, write=False, overwrite=False):
# make local fs follow the similar semantics as DBFS
self._system_path.parent.mkdir(mode=0o755, parents=True, exist_ok=True)
return self._system_path.open(mode='wb' if overwrite else 'rb' if read else 'xb')
self._path.parent.mkdir(mode=0o755, parents=True, exist_ok=True)
return self._path.open(mode='wb' if overwrite else 'rb' if read else 'xb')

def list(self, recursive=False) -> Generator[files.FileInfo, None, None]:
if not self.is_dir:
Expand All @@ -360,7 +359,7 @@ def list(self, recursive=False) -> Generator[files.FileInfo, None, None]:
modification_time=int(st.st_mtime_ns / 1e6),
)
return
queue = deque([self._system_path])
queue = deque([self._path])
while queue:
path = queue.popleft()
for leaf in path.iterdir():
Expand All @@ -380,20 +379,20 @@ def delete(self, *, recursive=False):
if recursive:
for leaf in self.list(recursive=True):
_LocalPath(leaf.path).delete()
self._system_path.rmdir()
self._path.rmdir()
else:
kw = {}
if sys.version_info[:2] > (3, 7):
kw['missing_ok'] = True
self._system_path.unlink(**kw)
self._path.unlink(**kw)

def __repr__(self) -> str:
return f'<_LocalPath {self._path}>'


class _VolumesPath(_Path):

def __init__(self, api: files.FilesAPI, src: Union[str, pathlib.Path]):
def __init__(self, api: files.FilesAPI, src: Union[str, pathlib.PurePosixPath]):
super().__init__(src)
self._api = api

Expand Down

0 comments on commit 3833e11

Please sign in to comment.