-
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.
Merge pull request #8 from Quansight/refactor
refactors code to move implimentations into their own folders
- Loading branch information
Showing
9 changed files
with
186 additions
and
102 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
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,28 @@ | ||
from upath.universal_path import _FSSpecAccessor, UniversalPath | ||
|
||
|
||
class _HDFSAccessor(_FSSpecAccessor): | ||
def __init__(self, parsed_url, *args, **kwargs): | ||
super().__init__(parsed_url, *args, **kwargs) | ||
self._fs.root_marker = "/" | ||
|
||
def argument_upath_self_to_filepath(self, func): | ||
"""if arguments are passed to the wrapped function, and if the first | ||
argument is a UniversalPath instance, that argument is replaced with | ||
the UniversalPath's path attribute | ||
""" | ||
|
||
def wrapper(*args, **kwargs): | ||
args, kwargs = self._format_path(args, kwargs) | ||
print(args, kwargs) | ||
if "trunicate" in kwargs: | ||
kwargs.pop("trunicate") | ||
if func.__name__ == "mkdir": | ||
args = args[:1] | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
|
||
class HDFSPath(UniversalPath): | ||
_default_accessor = _HDFSAccessor |
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,10 @@ | ||
from upath.universal_path import _FSSpecAccessor, UniversalPath | ||
|
||
|
||
class _S3Accessor(_FSSpecAccessor): | ||
def __init__(self, parsed_url, *args, **kwargs): | ||
super().__init__(parsed_url, *args, **kwargs) | ||
|
||
|
||
class S3Path(UniversalPath): | ||
_default_accessor = _S3Accessor |
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 |
---|---|---|
@@ -1,3 +1,25 @@ | ||
from upath.implementations import http | ||
import warnings | ||
|
||
_registry = {"http": http.HTTPPath} | ||
from upath.universal_path import UniversalPath | ||
from upath.implementations import http, hdfs, s3 | ||
|
||
|
||
class _Registry: | ||
http = http.HTTPPath | ||
hdfs = hdfs.HDFSPath | ||
s3 = s3.S3Path | ||
|
||
def __getitem__(self, item): | ||
implimented_path = getattr(self, item, None) | ||
if not implimented_path: | ||
warning_str = ( | ||
f"{item} filesystem path not explicitely implimented. " | ||
"falling back to default implimentation UniversalPath. " | ||
"This filesystem may not be tested" | ||
) | ||
warnings.warn(warning_str, UserWarning) | ||
return UniversalPath | ||
return implimented_path | ||
|
||
|
||
_registry = _Registry() |
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,23 @@ | ||
"""see upath/tests/conftest.py for fixtures | ||
""" | ||
import pytest # noqa: F401 | ||
|
||
from upath import UPath | ||
from upath.implementations.hdfs import HDFSPath | ||
from upath.tests.test_core import TestUpath | ||
|
||
|
||
@pytest.mark.hdfs | ||
class TestUPathHDFS(TestUpath): | ||
@pytest.fixture(autouse=True) | ||
def path(self, local_testdir, hdfs): | ||
host, user, port = hdfs | ||
path = f"hdfs:{local_testdir}" | ||
self.path = UPath(path, host=host, user=user, port=port) | ||
|
||
def test_is_HDFSPath(self): | ||
assert isinstance(self.path, HDFSPath) | ||
|
||
def test_chmod(self): | ||
# todo | ||
pass |
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,54 @@ | ||
"""see upath/tests/conftest.py for fixtures | ||
""" | ||
import pytest # noqa: F401 | ||
|
||
from upath import UPath | ||
from upath.errors import NotDirectoryError | ||
from upath.implementations.s3 import S3Path | ||
from upath.tests.test_core import TestUpath | ||
|
||
|
||
class TestUPathS3(TestUpath): | ||
@pytest.fixture(autouse=True) | ||
def path(self, local_testdir, s3): | ||
anon, s3so = s3 | ||
path = f"s3:{local_testdir}" | ||
self.path = UPath(path, anon=anon, **s3so) | ||
|
||
def test_is_S3Path(self): | ||
assert isinstance(self.path, S3Path) | ||
|
||
def test_chmod(self): | ||
# todo | ||
pass | ||
|
||
def test_mkdir(self): | ||
new_dir = self.path.joinpath("new_dir") | ||
# new_dir.mkdir() | ||
# mkdir doesnt really do anything. A directory only exists in s3 | ||
# if some file or something is written to it | ||
new_dir.joinpath("test.txt").touch() | ||
assert new_dir.exists() | ||
|
||
def test_rmdir(self, local_testdir): | ||
dirname = "rmdir_test" | ||
mock_dir = self.path.joinpath(dirname) | ||
mock_dir.joinpath("test.txt").touch() | ||
mock_dir.rmdir() | ||
assert not mock_dir.exists() | ||
with pytest.raises(NotDirectoryError): | ||
self.path.joinpath("file1.txt").rmdir() | ||
|
||
def test_touch_unlink(self): | ||
path = self.path.joinpath("test_touch.txt") | ||
path.touch() | ||
assert path.exists() | ||
path.unlink() | ||
assert not path.exists() | ||
|
||
# should raise FileNotFoundError since file is missing | ||
with pytest.raises(FileNotFoundError): | ||
path.unlink() | ||
|
||
# file doesn't exists, but missing_ok is True | ||
path.unlink(missing_ok=True) |
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