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

MNT Fixes for huggingface_hub 0.12 compatibility #274

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion skops/hub_utils/_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,11 @@ def download(
if dst.exists():
dst.rmdir()

# TODO: Switch from use_auth_token to token once huggingface_hub<0.11 is
# dropped. Until then, we ignore the mypy type check, because mypy doesn't
# see that use_auth_token is handled by the decorator of snapshot_download.
cached_folder = snapshot_download(
repo_id=repo_id, revision=revision, use_auth_token=token, **kwargs
repo_id=repo_id, revision=revision, use_auth_token=token, **kwargs # type: ignore
)
shutil.copytree(cached_folder, dst)
if not keep_cache:
Expand Down
13 changes: 9 additions & 4 deletions skops/hub_utils/tests/test_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,15 @@ def test_push_download(
private=True,
)

with pytest.raises(
RepositoryNotFoundError,
match="If the repo is private, make sure you are authenticated.",
):
# TODO: remove 1st message when huggingface_hub < v0.12 is dropped
# message changes in huggingface_hub v0.12, test both
match = (
"If the repo is private, make sure you are authenticated"
"|"
"If you are trying to access a private or gated repo, "
"make sure you are authenticated"
)
with pytest.raises(RepositoryNotFoundError, match=match):
download(repo_id=repo_id, dst="/tmp/test")

with pytest.raises(OSError, match="None-empty dst path already exists!"):
Expand Down