1414# limitations under the License.
1515"""Contain helper class to retrieve/store token from/to local cache."""
1616
17- import warnings
1817from pathlib import Path
1918from typing import Optional
2019
2322
2423
2524class HfFolder :
26- path_token = Path (constants .HF_TOKEN_PATH )
27- # Private attribute. Will be removed in v0.15
28- _old_path_token = Path (constants ._OLD_HF_TOKEN_PATH )
29-
3025 # TODO: deprecate when adapted in transformers/datasets/gradio
3126 # @_deprecate_method(version="1.0", message="Use `huggingface_hub.login` instead.")
3227 @classmethod
@@ -41,8 +36,9 @@ def save_token(cls, token: str) -> None:
4136 token (`str`):
4237 The token to save to the [`HfFolder`]
4338 """
44- cls .path_token .parent .mkdir (parents = True , exist_ok = True )
45- cls .path_token .write_text (token )
39+ path_token = Path (constants .HF_TOKEN_PATH )
40+ path_token .parent .mkdir (parents = True , exist_ok = True )
41+ path_token .write_text (token )
4642
4743 # TODO: deprecate when adapted in transformers/datasets/gradio
4844 # @_deprecate_method(version="1.0", message="Use `huggingface_hub.get_token` instead.")
@@ -57,12 +53,6 @@ def get_token(cls) -> Optional[str]:
5753 Returns:
5854 `str` or `None`: The token, `None` if it doesn't exist.
5955 """
60- # 0. Check if token exist in old path but not new location
61- try :
62- cls ._copy_to_new_path_and_warn ()
63- except Exception : # if not possible (e.g. PermissionError), do not raise
64- pass
65-
6656 return get_token ()
6757
6858 # TODO: deprecate when adapted in transformers/datasets/gradio
@@ -73,24 +63,6 @@ def delete_token(cls) -> None:
7363 Deletes the token from storage. Does not fail if token does not exist.
7464 """
7565 try :
76- cls .path_token .unlink ()
77- except FileNotFoundError :
78- pass
79-
80- try :
81- cls ._old_path_token .unlink ()
66+ Path (constants .HF_TOKEN_PATH ).unlink ()
8267 except FileNotFoundError :
8368 pass
84-
85- @classmethod
86- def _copy_to_new_path_and_warn (cls ):
87- if cls ._old_path_token .exists () and not cls .path_token .exists ():
88- cls .save_token (cls ._old_path_token .read_text ())
89- warnings .warn (
90- f"A token has been found in `{ cls ._old_path_token } `. This is the old"
91- " path where tokens were stored. The new location is"
92- f" `{ cls .path_token } ` which is configurable using `HF_HOME` environment"
93- " variable. Your token has been copied to this new location. You can"
94- " now safely delete the old token file manually or use"
95- " `huggingface-cli logout`."
96- )
0 commit comments