huggingface-hub 0.20.1__py3-none-any.whl → 0.20.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of huggingface-hub might be problematic. Click here for more details.

@@ -46,7 +46,7 @@ import sys
46
46
  from typing import TYPE_CHECKING
47
47
 
48
48
 
49
- __version__ = "0.20.1"
49
+ __version__ = "0.20.2"
50
50
 
51
51
  # Alphabetical order of definitions is ensured in tests
52
52
  # WARNING: any comment added in this dictionary definition will be lost when
@@ -15,13 +15,16 @@
15
15
  import os
16
16
  import warnings
17
17
  from pathlib import Path
18
+ from threading import Lock
18
19
  from typing import Optional
19
20
 
20
21
  from .. import constants
21
22
  from ._runtime import is_google_colab
22
23
 
23
24
 
24
- _CHECK_GOOGLE_COLAB_SECRET = True
25
+ _IS_GOOGLE_COLAB_CHECKED = False
26
+ _GOOGLE_COLAB_SECRET_LOCK = Lock()
27
+ _GOOGLE_COLAB_SECRET: Optional[str] = None
25
28
 
26
29
 
27
30
  def get_token() -> Optional[str]:
@@ -42,52 +45,66 @@ def get_token() -> Optional[str]:
42
45
 
43
46
 
44
47
  def _get_token_from_google_colab() -> Optional[str]:
45
- if not is_google_colab():
46
- return None
47
-
48
- global _CHECK_GOOGLE_COLAB_SECRET
49
- if not _CHECK_GOOGLE_COLAB_SECRET: # request access only once
50
- return None
51
-
52
- try:
53
- from google.colab import userdata
54
- from google.colab.errors import Error as ColabError
55
- except ImportError:
56
- return None
48
+ """Get token from Google Colab secrets vault using `google.colab.userdata.get(...)`.
57
49
 
58
- try:
59
- token = userdata.get("HF_TOKEN")
60
- except userdata.NotebookAccessError:
61
- # Means the user has a secret call `HF_TOKEN` and got a popup "please grand access to HF_TOKEN" and refused it
62
- # => warn user but ignore error => do not re-request access to user
63
- warnings.warn(
64
- "\nAccess to the secret `HF_TOKEN` has not been granted on this notebook."
65
- "\nYou will not be requested again."
66
- "\nPlease restart the session if you want to be prompted again."
67
- )
68
- _CHECK_GOOGLE_COLAB_SECRET = False
69
- return None
70
- except userdata.SecretNotFoundError:
71
- # Means the user did not define a `HF_TOKEN` secret => warn
72
- warnings.warn(
73
- "\nThe secret `HF_TOKEN` does not exist in your Colab secrets."
74
- "\nTo authenticate with the Hugging Face Hub, create a token in your settings tab "
75
- "(https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session."
76
- "\nYou will be able to reuse this secret in all of your notebooks."
77
- "\nPlease note that authentication is recommended but still optional to access public models or datasets."
78
- )
79
- return None
80
- except ColabError as e:
81
- # Something happen but we don't know what => recommend to open a GitHub issue
82
- warnings.warn(
83
- f"\nError while fetching `HF_TOKEN` secret value from your vault: '{str(e)}'."
84
- "\nYou are not authenticated with the Hugging Face Hub in this notebook."
85
- "\nIf the error persists, please let us know by opening an issue on GitHub "
86
- "(https://github.com/huggingface/huggingface_hub/issues/new)."
87
- )
50
+ Token is read from the vault only once per session and then stored in a global variable to avoid re-requesting
51
+ access to the vault.
52
+ """
53
+ if not is_google_colab():
88
54
  return None
89
55
 
90
- return _clean_token(token)
56
+ # `google.colab.userdata` is not thread-safe
57
+ # This can lead to a deadlock if multiple threads try to access it at the same time
58
+ # (typically when using `snapshot_download`)
59
+ # => use a lock
60
+ # See https://github.com/huggingface/huggingface_hub/issues/1952 for more details.
61
+ with _GOOGLE_COLAB_SECRET_LOCK:
62
+ global _GOOGLE_COLAB_SECRET
63
+ global _IS_GOOGLE_COLAB_CHECKED
64
+
65
+ if _IS_GOOGLE_COLAB_CHECKED: # request access only once
66
+ return _GOOGLE_COLAB_SECRET
67
+
68
+ try:
69
+ from google.colab import userdata
70
+ from google.colab.errors import Error as ColabError
71
+ except ImportError:
72
+ return None
73
+
74
+ try:
75
+ token = userdata.get("HF_TOKEN")
76
+ _GOOGLE_COLAB_SECRET = _clean_token(token)
77
+ except userdata.NotebookAccessError:
78
+ # Means the user has a secret call `HF_TOKEN` and got a popup "please grand access to HF_TOKEN" and refused it
79
+ # => warn user but ignore error => do not re-request access to user
80
+ warnings.warn(
81
+ "\nAccess to the secret `HF_TOKEN` has not been granted on this notebook."
82
+ "\nYou will not be requested again."
83
+ "\nPlease restart the session if you want to be prompted again."
84
+ )
85
+ _GOOGLE_COLAB_SECRET = None
86
+ except userdata.SecretNotFoundError:
87
+ # Means the user did not define a `HF_TOKEN` secret => warn
88
+ warnings.warn(
89
+ "\nThe secret `HF_TOKEN` does not exist in your Colab secrets."
90
+ "\nTo authenticate with the Hugging Face Hub, create a token in your settings tab "
91
+ "(https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session."
92
+ "\nYou will be able to reuse this secret in all of your notebooks."
93
+ "\nPlease note that authentication is recommended but still optional to access public models or datasets."
94
+ )
95
+ _GOOGLE_COLAB_SECRET = None
96
+ except ColabError as e:
97
+ # Something happen but we don't know what => recommend to open a GitHub issue
98
+ warnings.warn(
99
+ f"\nError while fetching `HF_TOKEN` secret value from your vault: '{str(e)}'."
100
+ "\nYou are not authenticated with the Hugging Face Hub in this notebook."
101
+ "\nIf the error persists, please let us know by opening an issue on GitHub "
102
+ "(https://github.com/huggingface/huggingface_hub/issues/new)."
103
+ )
104
+ _GOOGLE_COLAB_SECRET = None
105
+
106
+ _IS_GOOGLE_COLAB_CHECKED = True
107
+ return _GOOGLE_COLAB_SECRET
91
108
 
92
109
 
93
110
  def _get_token_from_environment() -> Optional[str]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: huggingface-hub
3
- Version: 0.20.1
3
+ Version: 0.20.2
4
4
  Summary: Client library to download and publish models, datasets and other repos on the huggingface.co hub
5
5
  Home-page: https://github.com/huggingface/huggingface_hub
6
6
  Author: Hugging Face, Inc.
@@ -1,4 +1,4 @@
1
- huggingface_hub/__init__.py,sha256=WvvtgmprtEwfH1CVyhFwhOmWzxwyuIs4Ydqm3MQQ67A,20809
1
+ huggingface_hub/__init__.py,sha256=ixK6-0G7PFdH1mCZ9c5g8ZuYHsxSpVo8TTuA7O0mun8,20809
2
2
  huggingface_hub/_commit_api.py,sha256=LWwx0PmTHzh-gwO6-cl0GWTrSnzCy8tfZ8DDCxnfb7Y,27795
3
3
  huggingface_hub/_commit_scheduler.py,sha256=FgfjYv3E0oK3iBxDdy45Y7t78FWkmjnBR4dRd5aZviU,13653
4
4
  huggingface_hub/_inference_endpoints.py,sha256=FW36nfm9UNNnc6L6hyL2KLiItglPGcQuYJ6DA2w4Gp4,14929
@@ -60,7 +60,7 @@ huggingface_hub/utils/_runtime.py,sha256=6sMMfwixkJAJj7pqYAva9A1g3-MBNWenKtlvBB9
60
60
  huggingface_hub/utils/_safetensors.py,sha256=EE9v9HflWBUqIegn0dCGHgNu9G9Db3v2aszvG4ldPF8,4876
61
61
  huggingface_hub/utils/_subprocess.py,sha256=LW9b8TWh9rsm3pW9_5b-mVV_AtYNyLXgC6e09SthkWI,4616
62
62
  huggingface_hub/utils/_telemetry.py,sha256=jHAdgWNcL9nVvMT3ec3i78O-cwL09GnlifuokzpQjMI,4641
63
- huggingface_hub/utils/_token.py,sha256=3DYRsV6z2byAg0rjuz7mFD2Q52qN2K2craVYEEXhMqo,4502
63
+ huggingface_hub/utils/_token.py,sha256=e3GGABkd6zPYLE4-RdUxnH6vyen4vsvNxEl2PgStiTA,5475
64
64
  huggingface_hub/utils/_typing.py,sha256=zTA0nTJAILGveXbJKyeh6u9uIagrFgPoRqr-uCEGDQI,921
65
65
  huggingface_hub/utils/_validators.py,sha256=3ZmHubjslDRwFYe1oKyaUw6DZrc3DsuV2gABPrx7PTw,9358
66
66
  huggingface_hub/utils/endpoint_helpers.py,sha256=reLS2ic6_BTe9RuZY5WLcd5dLjIWt5Klh5EHZ7XvHng,8533
@@ -68,9 +68,9 @@ huggingface_hub/utils/insecure_hashlib.py,sha256=OjxlvtSQHpbLp9PWSrXBDJ0wHjxCBU-
68
68
  huggingface_hub/utils/logging.py,sha256=mARNwc5gY6apMQ9IM5zymn-RsYnFbYW3b0HDMYXmBS0,4729
69
69
  huggingface_hub/utils/sha.py,sha256=IVi7CfBthfu-ExLduY_CQltTy-tVGTbrvURCTOWKcLA,901
70
70
  huggingface_hub/utils/tqdm.py,sha256=zBWgoxxwHooOceABVREVqSNpJGcMpaByKFVDU8VbuUQ,6334
71
- huggingface_hub-0.20.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
72
- huggingface_hub-0.20.1.dist-info/METADATA,sha256=_mwPR3T6IoDiH8sbuyp_os1yo5_h5MCYFgYb2wuKj5Q,12930
73
- huggingface_hub-0.20.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
74
- huggingface_hub-0.20.1.dist-info/entry_points.txt,sha256=Y3Z2L02rBG7va_iE6RPXolIgwOdwUFONyRN3kXMxZ0g,131
75
- huggingface_hub-0.20.1.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
76
- huggingface_hub-0.20.1.dist-info/RECORD,,
71
+ huggingface_hub-0.20.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
72
+ huggingface_hub-0.20.2.dist-info/METADATA,sha256=D1vK91f8NEHzMiWLSl7_TQs6rZ6cr0E4ecRkkFB0lMM,12930
73
+ huggingface_hub-0.20.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
74
+ huggingface_hub-0.20.2.dist-info/entry_points.txt,sha256=Y3Z2L02rBG7va_iE6RPXolIgwOdwUFONyRN3kXMxZ0g,131
75
+ huggingface_hub-0.20.2.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
76
+ huggingface_hub-0.20.2.dist-info/RECORD,,