-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement SMBPath and tests * upath._flavour_sources: revert formatting changes * tests: add smb protocol to registry tests * tests: update smb glob test (mark '*' as xfail for now) * upath.implementations.smb: configure flavour to correctly handle path parsing * tests: skip smb test on windows * upath.implementations.smb: make rename work with older fsspec --------- Co-authored-by: fkuehnlenz <florian.kuehnlenz@e2m.energy> Co-authored-by: Andreas Poehlmann <ap--@users.noreply.github.com>
- Loading branch information
1 parent
68d5707
commit d412c63
Showing
7 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ dev = | |
# pyarrow | ||
pydantic | ||
pydantic-settings | ||
smbprotocol | ||
|
||
[options.package_data] | ||
upath = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import warnings | ||
|
||
import smbprotocol.exceptions | ||
|
||
from upath import UPath | ||
|
||
|
||
class SMBPath(UPath): | ||
__slots__ = () | ||
|
||
def mkdir(self, mode=0o777, parents=False, exist_ok=False): | ||
# smbclient does not support setting mode externally | ||
if parents and not exist_ok and self.exists(): | ||
raise FileExistsError(str(self)) | ||
try: | ||
self.fs.mkdir( | ||
self.path, | ||
create_parents=parents, | ||
) | ||
except smbprotocol.exceptions.SMBOSError: | ||
if not exist_ok: | ||
raise FileExistsError(str(self)) | ||
if not self.is_dir(): | ||
raise FileExistsError(str(self)) | ||
|
||
def iterdir(self): | ||
if not self.is_dir(): | ||
raise NotADirectoryError(str(self)) | ||
else: | ||
return super().iterdir() | ||
|
||
def rename(self, target, **kwargs): | ||
if "recursive" in kwargs: | ||
warnings.warn( | ||
"SMBPath.rename(): recursive is currently ignored.", | ||
UserWarning, | ||
stacklevel=2, | ||
) | ||
if "maxdepth" in kwargs: | ||
warnings.warn( | ||
"SMBPath.rename(): maxdepth is currently ignored.", | ||
UserWarning, | ||
stacklevel=2, | ||
) | ||
if not isinstance(target, UPath): | ||
target = self.parent.joinpath(target).resolve() | ||
self.fs.mv( | ||
self.path, | ||
target.path, | ||
**kwargs, | ||
) | ||
return target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
from fsspec import __version__ as fsspec_version | ||
from packaging.version import Version | ||
|
||
from upath import UPath | ||
from upath.tests.cases import BaseTests | ||
from upath.tests.utils import skip_on_windows | ||
|
||
|
||
@skip_on_windows | ||
class TestUPathSMB(BaseTests): | ||
|
||
@pytest.fixture(autouse=True) | ||
def path(self, smb_fixture): | ||
self.path = UPath(smb_fixture) | ||
|
||
@pytest.mark.parametrize( | ||
"pattern", | ||
( | ||
"*.txt", | ||
pytest.param( | ||
"*", | ||
marks=pytest.mark.xfail( | ||
reason="SMBFileSystem.info appends '/' to dirs" | ||
), | ||
), | ||
pytest.param( | ||
"**/*.txt", | ||
marks=( | ||
pytest.mark.xfail(reason="requires fsspec>=2023.9.0") | ||
if Version(fsspec_version) < Version("2023.9.0") | ||
else () | ||
), | ||
), | ||
), | ||
) | ||
def test_glob(self, pathlib_base, pattern): | ||
super().test_glob(pathlib_base, pattern) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"memory", | ||
"s3", | ||
"s3a", | ||
"smb", | ||
"webdav", | ||
"webdav+http", | ||
"webdav+https", | ||
|