From a1b90fa3c445a9be4438a259f1e4a25ec79db66a Mon Sep 17 00:00:00 2001 From: Lucain Date: Wed, 15 Nov 2023 10:00:41 +0100 Subject: [PATCH] Expose `HF_HOME` in constants (#1825) * Expose HF_HOME in constants * style --- src/huggingface_hub/constants.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/huggingface_hub/constants.py b/src/huggingface_hub/constants.py index bf72e2ae91..26bf8a410d 100644 --- a/src/huggingface_hub/constants.py +++ b/src/huggingface_hub/constants.py @@ -82,15 +82,16 @@ def _as_int(value: Optional[str]) -> Optional[int]: # default cache default_home = os.path.join(os.path.expanduser("~"), ".cache") -hf_cache_home = os.path.expanduser( +HF_HOME = os.path.expanduser( os.getenv( "HF_HOME", os.path.join(os.getenv("XDG_CACHE_HOME", default_home), "huggingface"), ) ) +hf_cache_home = HF_HOME # for backward compatibility. TODO: remove this in 1.0.0 -default_cache_path = os.path.join(hf_cache_home, "hub") -default_assets_cache_path = os.path.join(hf_cache_home, "assets") +default_cache_path = os.path.join(HF_HOME, "hub") +default_assets_cache_path = os.path.join(HF_HOME, "assets") # Legacy env variables HUGGINGFACE_HUB_CACHE = os.getenv("HUGGINGFACE_HUB_CACHE", default_cache_path) @@ -109,7 +110,7 @@ def _as_int(value: Optional[str]) -> Optional[int]: # `_OLD_HF_TOKEN_PATH` is deprecated and will be removed "at some point". # See https://github.com/huggingface/huggingface_hub/issues/1232 _OLD_HF_TOKEN_PATH = os.path.expanduser("~/.huggingface/token") -HF_TOKEN_PATH = os.path.join(hf_cache_home, "token") +HF_TOKEN_PATH = os.path.join(HF_HOME, "token") if _staging_mode: