Skip to content

Commit e0e2c16

Browse files
authored
Fix huggingface filesystem repo_type not forwarded (#1791)
1 parent 7b50c1b commit e0e2c16

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/huggingface_hub/hf_file_system.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def _fetch_range(self, start: int, end: int) -> bytes:
424424
repo_id=self.resolved_path.repo_id,
425425
revision=self.resolved_path.revision,
426426
filename=self.resolved_path.path_in_repo,
427+
repo_type=self.resolved_path.repo_type,
427428
endpoint=self.fs.endpoint,
428429
)
429430
r = http_backoff("GET", url, headers=headers)

tests/test_hf_file_system.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
import fsspec
77
import pytest
88

9-
from huggingface_hub.constants import REPO_TYPES_URL_PREFIXES
109
from huggingface_hub.hf_file_system import HfFileSystem
1110
from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError
1211

13-
from .testing_constants import ENDPOINT_STAGING, TOKEN, USER
12+
from .testing_constants import ENDPOINT_STAGING, TOKEN
1413
from .testing_utils import repo_name
1514

1615

@@ -22,36 +21,37 @@ def setUpClass(cls):
2221
fsspec.register_implementation(HfFileSystem.protocol, HfFileSystem)
2322

2423
def setUp(self):
25-
self.repo_id = f"{USER}/{repo_name()}"
26-
self.repo_type = "dataset"
27-
self.hf_path = REPO_TYPES_URL_PREFIXES.get(self.repo_type, "") + self.repo_id
2824
self.hffs = HfFileSystem(endpoint=ENDPOINT_STAGING, token=TOKEN)
2925
self.api = self.hffs._api
3026

3127
# Create dummy repo
32-
self.api.create_repo(self.repo_id, repo_type=self.repo_type)
28+
repo_url = self.api.create_repo(repo_name(), repo_type="dataset")
29+
self.repo_id = repo_url.repo_id
30+
self.hf_path = f"datasets/{self.repo_id}"
31+
32+
# Upload files
3333
self.api.upload_file(
3434
path_or_fileobj=b"dummy binary data on pr",
3535
path_in_repo="data/binary_data_for_pr.bin",
3636
repo_id=self.repo_id,
37-
repo_type=self.repo_type,
37+
repo_type="dataset",
3838
create_pr=True,
3939
)
4040
self.api.upload_file(
4141
path_or_fileobj="dummy text data".encode("utf-8"),
4242
path_in_repo="data/text_data.txt",
4343
repo_id=self.repo_id,
44-
repo_type=self.repo_type,
44+
repo_type="dataset",
4545
)
4646
self.api.upload_file(
4747
path_or_fileobj=b"dummy binary data",
4848
path_in_repo="data/binary_data.bin",
4949
repo_id=self.repo_id,
50-
repo_type=self.repo_type,
50+
repo_type="dataset",
5151
)
5252

5353
def tearDown(self):
54-
self.api.delete_repo(self.repo_id, repo_type=self.repo_type)
54+
self.api.delete_repo(self.repo_id, repo_type="dataset")
5555

5656
def test_glob(self):
5757
self.assertEqual(
@@ -141,7 +141,7 @@ def test_modified_time(self):
141141

142142
def test_initialize_from_fsspec(self):
143143
fs, _, paths = fsspec.get_fs_token_paths(
144-
f"hf://{self.repo_type}s/{self.repo_id}/data/text_data.txt",
144+
f"hf://datasets/{self.repo_id}/data/text_data.txt",
145145
storage_options={
146146
"endpoint": ENDPOINT_STAGING,
147147
"token": TOKEN,

0 commit comments

Comments
 (0)