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

Fix glob path in get_file_list #44

Merged
merged 3 commits into from
Jan 6, 2024

Conversation

bencwallace
Copy link
Contributor

The 2023.12.0 release of fsspec introduced a change to the globbing of **. As a result, get_file_list is broken:

from embedding_reader.get_file_list import get_file_list
get_file_list(".", "py")

raises

ValueError: Invalid pattern: '**' can only be an entire path component

This PR fixes this issue by changing **.{file_format} to **/*.{file_format}, which should be backwards-compatible.

@bencwallace
Copy link
Contributor Author

Looks like the tests for older versions of Python are failing due to the way older versions of fsspec (2023.1.0 or below) handle globbing. Thoughts on bumping the fsspec dependency?

@rom1504
Copy link
Owner

rom1504 commented Dec 4, 2023

"Thoughts on bumping the fsspec dependency?" do you mean dropping support for python less than 3.8 ?

@bencwallace
Copy link
Contributor Author

Hadn't considered that. I suppose requiring a newer version of fsspec would require Python>=3.8.
Instead, I should be able to fix the errors in older versions (without compromising newer versions using the latest fsspec release) by merging the results of globbing *.{file_format} and **/*.{file_format}.

@@ -42,7 +42,7 @@ def _get_file_list(
path = make_path_absolute(path)
fs, path_in_fs = fsspec.core.url_to_fs(path)
prefix = path[: -len(path_in_fs)]
glob_pattern = path.rstrip("/") + f"/**.{file_format}"
glob_pattern = path.rstrip("/") + f"/**/*.{file_format}"
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 works in both Python 3.7 and 3.8

Suggested change
glob_pattern = path.rstrip("/") + f"/**/*.{file_format}"
glob_pattern_root = path.rstrip("/") + f"/*.{file_format}"
glob_pattern_sub = path.rstrip("/") + f"/**/*.{file_format}"
file_path_root = fs.glob(glob_pattern_root)
file_path_sub = fs.glob(glob_pattern_sub)
file_paths = list(set(file_path_root + file_path_sub))

@bencwallace
Copy link
Contributor Author

What do you think about the changes above? They support newer and older versions of fsspec without altering the behavior.

@rom1504
Copy link
Owner

rom1504 commented Jan 6, 2024

sorry for the delay here

let's drop support for 3.6 and 3.7 ; there are other reasons to do this anyway

@rom1504 rom1504 merged commit c1130b8 into rom1504:main Jan 6, 2024
5 checks passed
@loretoparisi
Copy link

@rom1504 I think the issue people are having on auto-faiss it may be caused by the drop of support mentioned here. In fact I'm using Python 3.7.5. so I did something like

if sys.version_info >= (3,8,0): 
        # LP: python > 3.8.x
        glob_pattern = path.rstrip("/") + f"/**/*.{file_format}"
    else:
        # LP: python <= 3.7.x
         glob_pattern = path.rstrip("/") + f"/**.{file_format}"

in get_file_list._get_file_list to make it working back, beucase unfortunately I cannot upgrade the python version in the short term.

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

Successfully merging this pull request may close these issues.

3 participants