8
8
import requests
9
9
from huggingface_hub .hf_api import HfApi , RepositoryNotFoundError
10
10
from huggingface_hub .utils import hf_raise_for_status
11
+ from huggingface_hub .utils ._headers import _http_user_agent
11
12
12
13
13
14
CI_HUB_USER = "__DUMMY_TRANSFORMERS_USER__"
19
20
CI_HFH_HUGGINGFACE_CO_URL_TEMPLATE = CI_HUB_ENDPOINT + "/{repo_id}/resolve/{revision}/{filename}"
20
21
21
22
22
- @pytest .fixture
23
- def ci_hfh_hf_hub_url (monkeypatch ):
24
- monkeypatch .setattr (
25
- "huggingface_hub.file_download.HUGGINGFACE_CO_URL_TEMPLATE" , CI_HFH_HUGGINGFACE_CO_URL_TEMPLATE
26
- )
27
-
28
-
29
23
@pytest .fixture
30
24
def ci_hub_config (monkeypatch ):
31
25
monkeypatch .setattr ("datasets.config.HF_ENDPOINT" , CI_HUB_ENDPOINT )
32
26
monkeypatch .setattr ("datasets.config.HUB_DATASETS_URL" , CI_HUB_DATASETS_URL )
27
+ monkeypatch .setattr (
28
+ "huggingface_hub.file_download.HUGGINGFACE_CO_URL_TEMPLATE" , CI_HFH_HUGGINGFACE_CO_URL_TEMPLATE
29
+ )
30
+ old_environ = dict (os .environ )
31
+ os .environ ["HF_ENDPOINT" ] = CI_HUB_ENDPOINT
32
+ yield
33
+ os .environ .clear ()
34
+ os .environ .update (old_environ )
33
35
34
36
35
37
@pytest .fixture
@@ -38,6 +40,22 @@ def set_ci_hub_access_token(ci_hub_config, monkeypatch):
38
40
monkeypatch .setattr ("huggingface_hub.constants.HF_HUB_DISABLE_IMPLICIT_TOKEN" , False )
39
41
old_environ = dict (os .environ )
40
42
os .environ ["HF_TOKEN" ] = CI_HUB_USER_TOKEN
43
+ os .environ ["HF_HUB_DISABLE_IMPLICIT_TOKEN" ] = "0"
44
+ yield
45
+ os .environ .clear ()
46
+ os .environ .update (old_environ )
47
+
48
+
49
+ def _http_ci_user_agent (* args , ** kwargs ):
50
+ ua = _http_user_agent (* args , ** kwargs )
51
+ return ua + os .environ .get ("CI_HEADERS" , "" )
52
+
53
+
54
+ @pytest .fixture (autouse = True )
55
+ def set_hf_ci_headers (monkeypatch ):
56
+ old_environ = dict (os .environ )
57
+ os .environ ["TRANSFORMERS_IS_CI" ] = "1"
58
+ monkeypatch .setattr ("huggingface_hub.utils._headers._http_user_agent" , _http_ci_user_agent )
41
59
yield
42
60
os .environ .clear ()
43
61
os .environ .update (old_environ )
@@ -105,7 +123,7 @@ def _hf_gated_dataset_repo_txt_data(hf_api: HfApi, hf_token, text_file_content):
105
123
106
124
107
125
@pytest .fixture ()
108
- def hf_gated_dataset_repo_txt_data (_hf_gated_dataset_repo_txt_data , ci_hub_config , ci_hfh_hf_hub_url ):
126
+ def hf_gated_dataset_repo_txt_data (_hf_gated_dataset_repo_txt_data , ci_hub_config ):
109
127
return _hf_gated_dataset_repo_txt_data
110
128
111
129
@@ -129,7 +147,7 @@ def hf_private_dataset_repo_txt_data_(hf_api: HfApi, hf_token, text_file_content
129
147
130
148
131
149
@pytest .fixture ()
132
- def hf_private_dataset_repo_txt_data (hf_private_dataset_repo_txt_data_ , ci_hub_config , ci_hfh_hf_hub_url ):
150
+ def hf_private_dataset_repo_txt_data (hf_private_dataset_repo_txt_data_ , ci_hub_config ):
133
151
return hf_private_dataset_repo_txt_data_
134
152
135
153
@@ -153,9 +171,7 @@ def hf_private_dataset_repo_zipped_txt_data_(hf_api: HfApi, hf_token, zip_csv_wi
153
171
154
172
155
173
@pytest .fixture ()
156
- def hf_private_dataset_repo_zipped_txt_data (
157
- hf_private_dataset_repo_zipped_txt_data_ , ci_hub_config , ci_hfh_hf_hub_url
158
- ):
174
+ def hf_private_dataset_repo_zipped_txt_data (hf_private_dataset_repo_zipped_txt_data_ , ci_hub_config ):
159
175
return hf_private_dataset_repo_zipped_txt_data_
160
176
161
177
@@ -179,7 +195,5 @@ def hf_private_dataset_repo_zipped_img_data_(hf_api: HfApi, hf_token, zip_image_
179
195
180
196
181
197
@pytest .fixture ()
182
- def hf_private_dataset_repo_zipped_img_data (
183
- hf_private_dataset_repo_zipped_img_data_ , ci_hub_config , ci_hfh_hf_hub_url
184
- ):
198
+ def hf_private_dataset_repo_zipped_img_data (hf_private_dataset_repo_zipped_img_data_ , ci_hub_config ):
185
199
return hf_private_dataset_repo_zipped_img_data_
0 commit comments