-
Notifications
You must be signed in to change notification settings - Fork 378
rework github _open() implementation to support LFS #1810
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
Merged
martindurant
merged 9 commits into
fsspec:master
from
thomasgilgenast:support-github-lfs
Mar 17, 2025
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c085e2d
rework github implementation to support lfs
a751042
make github _open() return HTTPFile when getting content from downloa…
f505aff
tweak tests for github implementation
7d88086
tweak tests for github implementation
75a6f4e
delegate HTTPFile creation to HTTPFileSystem.open()
8e7fb56
rework github large file open to treat http extra as optional
083392b
update docstring
65e09cf
alternate approach to deferred import that allows HTTPFileSystem reuse
38aadce
lint
martindurant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import fsspec | ||
|
||
|
||
def test_github_open_small_file(): | ||
# test opening a small file <1 MB | ||
with fsspec.open("github://mwaskom:seaborn-data@4e06bf0/penguins.csv") as f: | ||
assert f.readline().startswith(b"species,island") | ||
|
||
|
||
def test_github_open_large_file(): | ||
# test opening a large file >1 MB | ||
with fsspec.open("github://mwaskom:seaborn-data@83bfba7/brain_networks.csv") as f: | ||
assert f.readline().startswith(b"network,1,1,2,2") | ||
|
||
|
||
def test_github_open_lfs_file(): | ||
# test opening a git-lfs tracked file | ||
with fsspec.open( | ||
"github://cBioPortal:datahub@55cd360" | ||
"/public/acc_2019/data_gene_panel_matrix.txt", | ||
) as f: | ||
assert f.readline().startswith(b"SAMPLE_ID\tmutations") | ||
|
||
|
||
def test_github_cat(): | ||
# test using cat to fetch the content of multiple files | ||
fs = fsspec.filesystem("github", org="mwaskom", repo="seaborn-data") | ||
paths = ["penguins.csv", "mpg.csv"] | ||
cat_result = fs.cat(paths) | ||
assert set(cat_result.keys()) == {"penguins.csv", "mpg.csv"} | ||
assert cat_result["penguins.csv"].startswith(b"species,island") | ||
assert cat_result["mpg.csv"].startswith(b"mpg,cylinders") | ||
|
||
|
||
def test_github_ls(): | ||
# test using ls to list the files in a resository | ||
fs = fsspec.filesystem("github", org="mwaskom", repo="seaborn-data") | ||
ls_result = set(fs.ls("")) | ||
expected = {"brain_networks.csv", "mpg.csv", "penguins.csv", "README.md", "raw"} | ||
# check if the result is a subset of the expected files | ||
assert expected.issubset(ls_result) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: this will download the whole file in one shot, even though it's "large". Do you think we can generate a buffered file (like a HTTPFile), given that we expect the remote to accept HTTP range requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a great idea - thank you for mentioning this. I will rework this and then rewrite this test to use a range request to avoid fetching the whole file over the network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have thoughts on if it would also be important to introduce other concepts from the http implementation such as support for async, reuse of an aiohttp ClientSession for the multiple calls to the GitHub API, etc.? Or would it be fine to just use HTTPFile and ensure that range requests are supported, but otherwise not reach for full feature parity with the http implementation in this first PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess maybe my question may not make sense to ask if the relevant async support is already "enabled" just by virtue of the
asynchronous
kwarg on the HTTPFile constructor. I should probably take a closer look before asking this question 😅 .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not think about the async-ness. We probably don't want this for github, since there is a fairly onerous API rate limit, even if you come with a developer token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a751042 I tweaked
_open()
to return an HTTPFile wrapping thedownload_url
in cases where the initial response from the GitHub API does not include the file content already. I believe this should enable streaming and range queries.