Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fsspec: Add fsspec compatibility test cases #54

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ def cp_file(
bucket, key, vers = self._split_path(path1)

info = self.info(path1, bucket, key, version_id=vers)
if info["type"] == "directory":
logger.warning("Do not support copy directory %s.", path1)
return

size = info["size"]

_, _, parts_suffix = info.get("ETag", "").strip('"').partition("-")
Expand Down Expand Up @@ -1128,22 +1132,25 @@ def _find_file_dir(
out = [self.info(path)]
except FileNotFoundError:
out = []
dirs = []
for o in out:
par = self._parent(o["name"])
if len(path) <= len(par):
d = {
"Key": self._split_path(par)[1].rstrip("/"),
"Size": 0,
"name": par.rstrip("/"),
"type": "directory",
}
dirs.append(d)
dirs = {
self._parent(o["name"]): {
"Key": self._parent(o["name"]).rstrip("/"),
"Size": 0,
"name": self._parent(o["name"]).rstrip("/"),
"type": "directory",
}
for o in out
if len(path) <= len(self._parent(o["name"]))
}

if withdirs:
out = sorted(out + dirs, key=lambda x: x["name"])
for dir_info in dirs.values():
if dir_info not in out:
out.append(dir_info)
else:
out = [o for o in out if o["type"] == "file"]
return out

return sorted(out, key=lambda x: x["name"])

def _open_remote_file(
self,
Expand Down
17 changes: 16 additions & 1 deletion tosfs/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# limitations under the License.

import os
from typing import Generator
from typing import Any, Generator

import fsspec
import pytest
from fsspec.registry import known_implementations
from tos import EnvCredentialsProvider

from tosfs.core import TosFileSystem, logger
Expand All @@ -40,6 +42,19 @@ def tosfs(_tosfs_env_prepare: None) -> TosFileSystem:
return tosfs


@pytest.fixture(scope="module")
def fsspecfs(_tosfs_env_prepare: None) -> Any:
known_implementations["tos"] = {"class": "tosfs.core.TosFileSystem"}

fsspecfs, _ = fsspec.core.url_to_fs(
"tos://",
endpoint_url=os.environ.get("TOS_ENDPOINT"),
region=os.environ.get("TOS_REGION"),
credentials_provider=EnvCredentialsProvider(),
)
return fsspecfs


@pytest.fixture(scope="module")
def bucket() -> str:
return os.environ.get("TOS_BUCKET", "proton-ci")
Expand Down
Loading