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

fs.glob("/dir/**/*") is inconsitent with glob.glob #1394

Closed
alanhdu opened this issue Oct 19, 2023 · 5 comments
Closed

fs.glob("/dir/**/*") is inconsitent with glob.glob #1394

alanhdu opened this issue Oct 19, 2023 · 5 comments

Comments

@alanhdu
Copy link
Contributor

alanhdu commented Oct 19, 2023

If you run the following code:

import fsspec

fs, __ = fsspec.core.url_to_fs("memory://")
fs.touch("/a/1")
fs.touch("/a/2")
fs.touch("/a/b/1")
fs.touch("/a/b/2")

print(fs.glob("/a/**/*"))

you will get different ansewrs -- on fsspec 2023.5, you get ['/a/b/1', '/a/b/2'] but in fsspec 2023.9 you get ['/a/1', '/a/2', '/a/b', '/a/b/1', '/a/b/2'].

I believe the 2023.5 behavior is more consistent with how Python's glob.glob works, but don't have a strong opinion.

I believe this separate from #1380, since this has to do with the behavior of /dir/**/*, not the behavior of **/, but happy to be corrected!

@martindurant
Copy link
Member

Does #1382 fix the situation?

@alanhdu
Copy link
Contributor Author

alanhdu commented Oct 20, 2023

It does not -- I just checked it out 046edda locally and you get:

In [1]: import fsspec

In [2]: fs, __ = fsspec.core.url_to_fs("memory://")
   ...: fs.touch("/a/1")
   ...: fs.touch("/a/2")
   ...: fs.touch("/a/b/1")
   ...: fs.touch("/a/b/2")
   ...:
   ...: print(fs.glob("/a/**/*"))
['/a/1', '/a/2', '/a/b', '/a/b/1', '/a/b/2']

In [3]: fsspec.__version__
Out[3]: '2021.11.1+324.g046edda'

@mariosasko
Copy link
Contributor

glob.glob should also return ['/a/1', '/a/2', '/a/b', '/a/b/1', '/a/b/2'] with recursive=True. By default, recursive is False, so "/a/**/*" is effectively the same as "/a/*/*". fsspec's glob treats ** as if recursive=True, which is also consistent with Unix globbing.

Switching to the non-recursive mode would be a big breaking change for fsspec. Still, I can add a flag for switching between the modes in the PR, but I don't think it will be used a lot.

@martindurant
Copy link
Member

This is the posix behaviour, suggesting fsspec is getting this right

$ mkdir a
$ mkdir a/b
$ touch a/1
$ touch a/2
$ touch a/b/1
$ touch a/b/2
$ echo a/**/*
a/1 a/2 a/b a/b/1 a/b/2

@alanhdu
Copy link
Contributor Author

alanhdu commented Oct 23, 2023

Yeah, I think it's reasonable to say that this is expected behavior -- I was just surprised that the behavior changed from 2023.5 to 2023.9. Happy to close this as "working as expected".

alanhdu added a commit to alanhdu/torchx that referenced this issue Oct 25, 2023
Summary: Need to update code for fsspec/filesystem_spec#1394.

Reviewed By: stepanhruda

Differential Revision: D50388544

fbshipit-source-id: 49944758ac7c87e828950d997ad1d6a386b125d2
alanhdu added a commit to alanhdu/torchx that referenced this issue Dec 14, 2023
Summary:

Need to update code for fsspec/filesystem_spec#1394.

Reviewed By: stepanhruda

Differential Revision: D50388544
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants