Skip to content

Commit 65e09cf

Browse files
author
Thomas Gilgenast
committed
alternate approach to deferred import that allows HTTPFileSystem reuse
1 parent 083392b commit 65e09cf

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

fsspec/implementations/github.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def __init__(
6565

6666
self.root = sha
6767
self.ls("")
68-
self.kwargs = kwargs
68+
try:
69+
from .http import HTTPFileSystem
70+
71+
self.http_fs = HTTPFileSystem(**kwargs)
72+
except ImportError:
73+
self.http_fs = None
6974

7075
@property
7176
def kw(self):
@@ -248,14 +253,12 @@ def _open(
248253
# we land here if the content was not present in the first response
249254
# (regular file over 1MB or git-lfs tracked file)
250255
# in this case, we get let the HTTPFileSystem handle the download
251-
try:
252-
from .http import HTTPFileSystem
253-
except ImportError as e:
256+
if self.http_fs is None:
254257
raise ImportError(
255258
"Please install fsspec[http] to acccess github files >1 MB "
256259
"or git-lfs tracked files."
257-
) from e
258-
return HTTPFileSystem(**self.kwargs).open(
260+
)
261+
return self.http_fs.open(
259262
content_json["download_url"],
260263
mode=mode,
261264
block_size=block_size,

0 commit comments

Comments
 (0)