Skip to content

Commit 83bcc0b

Browse files
authored
Suppress xet install WARN if HF_HUB_DISABLE_XET (#3206)
* Suppress xet install WARN if HF_HUB_DISABLE_XET * PR feedback, removing is_xet_disabled() * Created contants.HF_HUB_DISABLE_XET and using it * Fixed unit test
1 parent 6e944cf commit 83bcc0b

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

src/huggingface_hub/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,4 @@ def _as_int(value: Optional[str]) -> Optional[int]:
291291

292292
default_xet_cache_path = os.path.join(HF_HOME, "xet")
293293
HF_XET_CACHE = os.getenv("HF_XET_CACHE", default_xet_cache_path)
294+
HF_HUB_DISABLE_XET: bool = _is_true(os.environ.get("HF_HUB_DISABLE_XET"))

src/huggingface_hub/file_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ def _download_to_tmp_and_move(
17181718
displayed_filename=filename,
17191719
)
17201720
else:
1721-
if xet_file_data is not None:
1721+
if xet_file_data is not None and not constants.HF_HUB_DISABLE_XET:
17221722
logger.warning(
17231723
"Xet Storage is enabled for this repo, but the 'hf_xet' package is not installed. "
17241724
"Falling back to regular HTTP download. "

src/huggingface_hub/utils/_runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def get_hf_transfer_version() -> str:
155155
# xet
156156
def is_xet_available() -> bool:
157157
# since hf_xet is automatically used if available, allow explicit disabling via environment variable
158-
if constants._is_true(os.environ.get("HF_HUB_DISABLE_XET")): # type: ignore
158+
if constants.HF_HUB_DISABLE_XET:
159159
return False
160160

161161
return is_package_available("hf_xet")

tests/test_xet_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,6 @@ def test_env_var_hf_hub_disable_xet() -> None:
288288
from huggingface_hub.utils._runtime import is_xet_available
289289

290290
monkeypatch = MonkeyPatch()
291-
monkeypatch.setenv("HF_HUB_DISABLE_XET", "1")
291+
monkeypatch.setattr("huggingface_hub.constants.HF_HUB_DISABLE_XET", True)
292+
292293
assert not is_xet_available()

0 commit comments

Comments
 (0)