From 21fc06e9479861112f09108c644d594635ae4b29 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Mon, 22 Mar 2021 03:01:06 +0300 Subject: [PATCH] fsspec: support raw buckets on path splitting (#5658) --- dvc/fs/fsspec_wrapper.py | 10 ++++++++-- tests/func/test_fs.py | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dvc/fs/fsspec_wrapper.py b/dvc/fs/fsspec_wrapper.py index 1550d69ec..3896b73e2 100644 --- a/dvc/fs/fsspec_wrapper.py +++ b/dvc/fs/fsspec_wrapper.py @@ -19,8 +19,14 @@ class FSSpecWrapper(BaseFileSystem): return path def _strip_bucket(self, entry): - _, entry = entry.split("/", 1) - return entry + try: + bucket, path = entry.split("/", 1) + except ValueError: + # If there is no path attached, only returns + # the bucket (top-level). + bucket, path = entry, None + + return path or bucket def _strip_buckets(self, entries, detail, prefix=None): for entry in entries: diff --git a/tests/func/test_fs.py b/tests/func/test_fs.py index f5330ee53..84f3658d8 100644 --- a/tests/func/test_fs.py +++ b/tests/func/test_fs.py @@ -349,3 +349,23 @@ def test_fs_ls_with_etag(dvc, cloud): fs.info(path_info.replace(path=details["name"]))["etag"] == details["etag"] ) + + +@pytest.mark.parametrize( + "cloud", [pytest.lazy_fixture("azure"), pytest.lazy_fixture("gs")] +) +def test_fs_fsspec_path_management(dvc, cloud): + cloud.gen({"foo": "foo", "data": {"bar": "bar", "baz": {"foo": "foo"}}}) + fs = get_cloud_fs(dvc, **cloud.config) + + root = cloud.parents[len(cloud.parents) - 1] + bucket_details = fs.info(root) + + # special conditions: name always points to the bucket name + assert bucket_details["name"] == root.bucket + assert bucket_details["type"] == "directory" + + data = cloud / "data" + data_details = fs.info(data) + assert data_details["name"].rstrip("/") == data.path + assert data_details["type"] == "directory"