Skip to content

Commit d6ac5e3

Browse files
authored
Merge pull request #76 from deepghs/dev/test
dev(narugo): update the test for huggingface_hub>=1
2 parents ab77998 + 5019583 commit d6ac5e3

File tree

22 files changed

+139
-53
lines changed

22 files changed

+139
-53
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ jobs:
5555
if: "!contains(github.event.head_commit.message, 'ci skip')"
5656
strategy:
5757
fail-fast: false
58+
max-parallel: 1
5859
matrix:
5960
os:
6061
- 'ubuntu-22.04'
6162
- 'windows-2022'
62-
- 'macos-13'
63+
- 'macos-14'
6364
python-version:
6465
- '3.8'
6566

.github/workflows/release_test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ jobs:
4949
if: "!contains(github.event.head_commit.message, 'ci skip')"
5050
strategy:
5151
fail-fast: false
52+
max-parallel: 1
5253
matrix:
5354
os:
5455
- 'ubuntu-22.04'
5556
- 'windows-2022'
56-
- 'macos-13'
57+
- 'macos-14'
5758
python-version:
5859
- '3.8'
5960

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ jobs:
1212
if: ${{ !contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'test skip') }}
1313
strategy:
1414
fail-fast: false
15-
max-parallel: 2
15+
max-parallel: 1
1616
matrix:
1717
os:
1818
- 'ubuntu-latest'
1919
- 'windows-latest'
2020
- 'macos-latest'
2121
python-version:
2222
- '3.8'
23-
- '3.9'
24-
- '3.10'
23+
# - '3.9'
24+
# - '3.10'
2525
- '3.11'
26-
- '3.12'
27-
- '3.13'
26+
# - '3.12'
27+
# - '3.13'
2828

2929
steps:
3030
- name: Get system version for Linux
@@ -132,7 +132,7 @@ jobs:
132132
os:
133133
- 'ubuntu-22.04'
134134
- 'windows-2022'
135-
- 'macos-13'
135+
- 'macos-14'
136136
python-version:
137137
- '3.8'
138138

hfutils/entry/download.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
from typing import Optional
1616

1717
import click
18-
from huggingface_hub import configure_http_backend
1918

2019
from .base import CONTEXT_SETTINGS, command_wrap, ClickErrorException
2120
from ..operate import download_file_to_file, download_archive_as_directory, download_directory_as_directory
2221
from ..operate.base import REPO_TYPES, RepoTypeTyping
23-
from ..utils import get_requests_session
22+
from ..utils import get_requests_session, HF_IS_VERSION_0_X_X
23+
24+
if HF_IS_VERSION_0_X_X:
25+
from huggingface_hub import configure_http_backend
26+
else:
27+
configure_http_backend = None
2428

2529

2630
class NoRemotePathAssignedWithDownload(ClickErrorException):
@@ -122,7 +126,8 @@ def download(
122126
123127
:raises NoRemotePathAssignedWithDownload: If no remote path in repository is assigned.
124128
"""
125-
configure_http_backend(get_requests_session)
129+
if HF_IS_VERSION_0_X_X:
130+
configure_http_backend(get_requests_session)
126131

127132
if tmpdir:
128133
os.environ['TMPDIR'] = tmpdir

hfutils/entry/duplicate.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
"""
77

88
import click
9-
from huggingface_hub import configure_http_backend
109

1110
from .base import CONTEXT_SETTINGS, command_wrap
1211
from ..operate import hf_repo_duplicate
1312
from ..operate.base import REPO_TYPES, RepoTypeTyping
14-
from ..utils import get_requests_session
13+
from ..utils import get_requests_session, HF_IS_VERSION_0_X_X
14+
15+
if HF_IS_VERSION_0_X_X:
16+
from huggingface_hub import configure_http_backend
17+
else:
18+
configure_http_backend = None
1519

1620

1721
def _add_duplicate_subcommand(cli: click.Group) -> click.Group:
@@ -59,7 +63,9 @@ def duplicate(src_repo_id: str, dst_repo_id: str, repo_type: RepoTypeTyping, pri
5963
6064
:raises: Various exceptions from huggingface_hub based on operation status
6165
"""
62-
configure_http_backend(get_requests_session)
66+
if HF_IS_VERSION_0_X_X:
67+
configure_http_backend(get_requests_session)
68+
6369
hf_repo_duplicate(
6470
src_repo_id=src_repo_id,
6571
dst_repo_id=dst_repo_id,

hfutils/entry/ils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
import click
2727
from hbutils.scale import size_to_bytes_str
2828
from hbutils.string import plural_word, titleize
29-
from huggingface_hub import configure_http_backend
3029

3130
from .base import CONTEXT_SETTINGS
3231
from ..index import hf_tar_get_index, hf_tar_validate
3332
from ..operate.base import REPO_TYPES
34-
from ..utils import get_requests_session, get_file_type, FileItemType
33+
from ..utils import get_requests_session, get_file_type, FileItemType, HF_IS_VERSION_0_X_X
3534
from ..utils.path import RepoTypeTyping, hf_normpath
3635

36+
if HF_IS_VERSION_0_X_X:
37+
from huggingface_hub import configure_http_backend
38+
else:
39+
configure_http_backend = None
40+
3741
_FT_NAME_MAP = {
3842
FileItemType.IMAGE: 'image',
3943
FileItemType.ARCHIVE: 'archive/compressed',
@@ -133,7 +137,8 @@ def ls(repo_id: str, idx_repo_id: Optional[str], repo_type: RepoTypeTyping, revi
133137
134138
The function uses click styles to format the output for better readability in the terminal.
135139
"""
136-
configure_http_backend(get_requests_session)
140+
if HF_IS_VERSION_0_X_X:
141+
configure_http_backend(get_requests_session)
137142

138143
idx_info = hf_tar_get_index(
139144
repo_id=repo_id,

hfutils/entry/index.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818

1919
import click
2020
from hbutils.string import plural_word
21-
from huggingface_hub import configure_http_backend
2221

2322
from .base import CONTEXT_SETTINGS
2423
from ..cache import delete_detached_cache
2524
from ..index import hf_tar_validate, tar_create_index
2625
from ..operate import get_hf_fs, download_file_to_file, upload_directory_as_directory
2726
from ..operate.base import REPO_TYPES, RepoTypeTyping, get_hf_client
2827
from ..utils import tqdm, hf_fs_path, parse_hf_fs_path, TemporaryDirectory, hf_normpath, ColoredFormatter, \
29-
get_requests_session
28+
get_requests_session, HF_IS_VERSION_0_X_X
29+
30+
if HF_IS_VERSION_0_X_X:
31+
from huggingface_hub import configure_http_backend
32+
else:
33+
configure_http_backend = None
3034

3135

3236
def _add_index_subcommand(cli: click.Group) -> click.Group:
@@ -90,7 +94,8 @@ def index(repo_id: str, idx_repo_id: Optional[str], repo_type: RepoTypeTyping, r
9094
This function is typically invoked through the CLI interface, like:
9195
$ python script.py index -r my_repo -x my_index_repo -t dataset -R main --min_upload_interval 120
9296
"""
93-
configure_http_backend(get_requests_session)
97+
if HF_IS_VERSION_0_X_X:
98+
configure_http_backend(get_requests_session)
9499

95100
logger = logging.getLogger()
96101
logger.setLevel(logging.INFO)

hfutils/entry/ls.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
import click
66
import tzlocal
7-
from huggingface_hub import configure_http_backend
87
from huggingface_hub.hf_api import RepoFolder, RepoFile
98

109
from .base import CONTEXT_SETTINGS
1110
from ..operate.base import REPO_TYPES, get_hf_client
12-
from ..utils import get_requests_session, FileItemType, get_file_type
11+
from ..utils import get_requests_session, FileItemType, get_file_type, HF_IS_VERSION_0_X_X
12+
13+
if HF_IS_VERSION_0_X_X:
14+
from huggingface_hub import configure_http_backend
15+
else:
16+
configure_http_backend = None
1317

1418

1519
class ListItem:
@@ -73,7 +77,8 @@ def ls(repo_id: str, repo_type: str, dir_in_repo, revision: str, show_all: bool,
7377
:param show_detailed: Flag to indicate whether to show detailed file information.
7478
:type show_detailed: bool
7579
"""
76-
configure_http_backend(get_requests_session)
80+
if HF_IS_VERSION_0_X_X:
81+
configure_http_backend(get_requests_session)
7782

7883
hf_client = get_hf_client()
7984
items: List[ListItem] = []

hfutils/entry/ls_repo.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
from typing import Optional
33

44
import click
5-
from huggingface_hub import configure_http_backend
65
from huggingface_hub.utils import LocalTokenNotFoundError
76

87
from .base import CONTEXT_SETTINGS, ClickErrorException
98
from ..operate.base import REPO_TYPES, get_hf_client
10-
from ..utils import get_requests_session
9+
from ..utils import get_requests_session, HF_IS_VERSION_0_X_X
10+
11+
if HF_IS_VERSION_0_X_X:
12+
from huggingface_hub import configure_http_backend
13+
else:
14+
configure_http_backend = None
1115

1216

1317
class NoLocalAuthentication(ClickErrorException):
@@ -48,11 +52,15 @@ def ls(author: Optional[str], repo_type: str, pattern: str):
4852
:param pattern: Pattern of the repository names.
4953
:type pattern: str
5054
"""
51-
configure_http_backend(get_requests_session)
55+
if HF_IS_VERSION_0_X_X:
56+
configure_http_backend(get_requests_session)
5257

5358
hf_client = get_hf_client()
5459
if not author:
5560
try:
61+
if not hf_client.token:
62+
raise LocalTokenNotFoundError
63+
5664
info = hf_client.whoami()
5765
author = author or info['name']
5866
except LocalTokenNotFoundError:

hfutils/entry/rollback.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from .base import CONTEXT_SETTINGS
66
from ..operate.base import REPO_TYPES, RepoTypeTyping
77
from ..repository import hf_hub_rollback
8-
from ..utils import ColoredFormatter
8+
from ..utils import ColoredFormatter, HF_IS_VERSION_0_X_X, get_requests_session
9+
10+
if HF_IS_VERSION_0_X_X:
11+
from huggingface_hub import configure_http_backend
12+
else:
13+
configure_http_backend = None
914

1015

1116
def _add_rollback_subcommand(cli: click.Group) -> click.Group:
@@ -43,6 +48,9 @@ def rollback(repo_id: str, repo_type: RepoTypeTyping, revision: str, rollback_to
4348
:param revision: The revision of the repository to rollback.
4449
:param rollback_to_commit_id: The commit ID to rollback to.
4550
"""
51+
if HF_IS_VERSION_0_X_X:
52+
configure_http_backend(get_requests_session)
53+
4654
# Set up logging
4755
logger = logging.getLogger()
4856
logger.setLevel(logging.INFO)

0 commit comments

Comments
 (0)