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

Better double asterisk support #769

Merged
merged 4 commits into from
Aug 25, 2023
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
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)
Copy link
Contributor Author

@john-jam john-jam Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should raise FileNotFoundError when no files are found to be consistent.

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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is unrelated to glob double asterisk but I think it was wrong. It tested the LocalFileSystem implementation instead of the S3 one.

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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find now returns the current folder as well.

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
Loading