-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ilongin/266-refactor-from-storage' into ilongin/329-ref…
…actor-storages
- Loading branch information
Showing
10 changed files
with
134 additions
and
102 deletions.
There are no files selected for viewing
This file contains 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 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 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,47 @@ | ||
import os | ||
import posixpath | ||
from typing import Any, cast | ||
|
||
from huggingface_hub import HfFileSystem | ||
|
||
from datachain.lib.file import File | ||
from datachain.node import Entry | ||
|
||
from .fsspec import Client | ||
|
||
|
||
class HfClient(Client): | ||
FS_CLASS = HfFileSystem | ||
PREFIX = "hf://" | ||
protocol = "hf" | ||
|
||
@classmethod | ||
def create_fs(cls, **kwargs) -> HfFileSystem: | ||
if os.environ.get("HF_TOKEN"): | ||
kwargs["token"] = os.environ["HF_TOKEN"] | ||
|
||
return cast(HfFileSystem, super().create_fs(**kwargs)) | ||
|
||
def convert_info(self, v: dict[str, Any], path: str) -> Entry: | ||
return Entry.from_file( | ||
path=path, | ||
size=v["size"], | ||
version=v["last_commit"].oid, | ||
etag=v.get("blob_id", ""), | ||
last_modified=v["last_commit"].date, | ||
) | ||
|
||
def info_to_file(self, v: dict[str, Any], path: str) -> File: | ||
return File( | ||
path=path, | ||
size=v["size"], | ||
version=v["last_commit"].oid, | ||
etag=v.get("blob_id", ""), | ||
last_modified=v["last_commit"].date, | ||
) | ||
|
||
async def ls_dir(self, path): | ||
return self.fs.ls(path, detail=True) | ||
|
||
def rel_path(self, path): | ||
return posixpath.relpath(path, self.name) |
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
dogs-and-cats/cat.1001.jpg | ||
""" | ||
), | ||
"listing": True, | ||
}, | ||
{ | ||
"command": ( | ||
|
This file contains 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