Skip to content

Commit

Permalink
Better double asterisk support (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-jam authored Aug 25, 2023
1 parent 39125f7 commit b1d9880
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ async def _ls(self, path, detail=False, refresh=False, versions=False):
for o in files
if o["name"].rstrip("/") == path and o["type"] != "directory"
]
if not files:
raise FileNotFoundError(path)
if detail:
return files
return files if detail else sorted([o["name"] for o in files])
Expand Down
1 change: 1 addition & 0 deletions s3fs/tests/derived/s3fs_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def fs(self, _s3_base, _get_boto3_client):
def fs_path(self):
return test_bucket_name

@pytest.fixture
def supports_empty_directories(self):
return False

Expand Down
17 changes: 11 additions & 6 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ def test_info(s3):
s3.mkdir(new_parent)
with pytest.raises(FileNotFoundError):
s3.info(new_parent)
s3.ls(new_parent)
with pytest.raises(FileNotFoundError):
s3.ls(new_parent)
with pytest.raises(FileNotFoundError):
s3.info(new_parent)

Expand Down Expand Up @@ -2070,9 +2071,13 @@ def test_via_fsspec(s3):
import fsspec

s3.mkdir("mine")
with fsspec.open("mine/oi", "wb") as f:
with fsspec.open(
"s3://mine/oi", "wb", client_kwargs={"endpoint_url": endpoint_uri}
) as f:
f.write(b"hello")
with fsspec.open("mine/oi", "rb") as f:
with fsspec.open(
"s3://mine/oi", "rb", client_kwargs={"endpoint_url": endpoint_uri}
) as f:
assert f.read() == b"hello"


Expand Down Expand Up @@ -2151,11 +2156,11 @@ def test_shallow_find(s3):
``maxdepth=1``, the results of ``find`` should be the same as those of
``ls``, without returning subdirectories. See also issue 378.
"""

assert s3.ls(test_bucket_name) == s3.find(
ls_output = s3.ls(test_bucket_name)
assert sorted(ls_output + [test_bucket_name]) == s3.find(
test_bucket_name, maxdepth=1, withdirs=True
)
assert s3.ls(test_bucket_name) == s3.glob(test_bucket_name + "/*")
assert ls_output == s3.glob(test_bucket_name + "/*")


def test_multi_find(s3):
Expand Down

0 comments on commit b1d9880

Please sign in to comment.