huggingface-hub 0.13.2__py3-none-any.whl → 0.13.4__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.13.2"
49
+ __version__ = "0.13.4"
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
huggingface_hub/_login.py CHANGED
@@ -121,15 +121,13 @@ def interpreter_login() -> None:
121
121
 
122
122
  For more details, see [`login`].
123
123
  """
124
- print( # docstyle-ignore
125
- """
124
+ print("""
126
125
  _| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|
127
126
  _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
128
127
  _|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|
129
128
  _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
130
129
  _| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|
131
- """
132
- )
130
+ """) # docstyle-ignore
133
131
  if HfFolder.get_token() is not None:
134
132
  print(
135
133
  " A token is already saved on your machine. Run `huggingface-cli"
@@ -819,14 +819,30 @@ def _normalize_etag(etag: Optional[str]) -> Optional[str]:
819
819
  return etag.strip('"')
820
820
 
821
821
 
822
+ def _create_relative_symlink(src: str, dst: str, new_blob: bool = False) -> None:
823
+ """Alias method used in `transformers` conversion script."""
824
+ return _create_symlink(src=src, dst=dst, new_blob=new_blob)
825
+
826
+
822
827
  def _create_symlink(src: str, dst: str, new_blob: bool = False) -> None:
823
- """Create a symbolic link named dst pointing to src as an absolute path.
828
+ """Create a symbolic link named dst pointing to src.
829
+
830
+ By default, it will try to create a symlink using a relative path. Relative paths have 2 advantages:
831
+ - If the cache_folder is moved (example: back-up on a shared drive), relative paths within the cache folder will
832
+ not brake.
833
+ - Relative paths seems to be better handled on Windows. Issue was reported 3 times in less than a week when
834
+ changing from relative to absolute paths. See https://github.com/huggingface/huggingface_hub/issues/1398,
835
+ https://github.com/huggingface/diffusers/issues/2729 and https://github.com/huggingface/transformers/pull/22228.
836
+ NOTE: The issue with absolute paths doesn't happen on admin mode.
837
+ When creating a symlink from the cache to a local folder, it is possible that a relative path cannot be created.
838
+ This happens when paths are not on the same volume. In that case, we use absolute paths.
839
+
824
840
 
825
841
  The result layout looks something like
826
842
  └── [ 128] snapshots
827
843
  ├── [ 128] 2439f60ef33a0d46d85da5001d52aeda5b00ce9f
828
- │ ├── [ 52] README.md -> /path/to/cache/blobs/d7edf6bd2a681fb0175f7735299831ee1b22b812
829
- │ └── [ 76] pytorch_model.bin -> /path/to/cache/blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
844
+ │ ├── [ 52] README.md -> ../../../blobs/d7edf6bd2a681fb0175f7735299831ee1b22b812
845
+ │ └── [ 76] pytorch_model.bin -> ../../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
830
846
 
831
847
  If symlinks cannot be created on this platform (most likely to be Windows), the workaround is to avoid symlinks by
832
848
  having the actual file in `dst`. If it is a new file (`new_blob=True`), we move it to `dst`. If it is not a new file
@@ -844,6 +860,15 @@ def _create_symlink(src: str, dst: str, new_blob: bool = False) -> None:
844
860
  abs_src = os.path.abspath(os.path.expanduser(src))
845
861
  abs_dst = os.path.abspath(os.path.expanduser(dst))
846
862
 
863
+ # Use relative_dst in priority
864
+ try:
865
+ relative_src = os.path.relpath(abs_src, os.path.dirname(abs_dst))
866
+ except ValueError:
867
+ # Raised on Windows if src and dst are not on the same volume. This is the case when creating a symlink to a
868
+ # local_dir instead of within the cache directory.
869
+ # See https://docs.python.org/3/library/os.path.html#os.path.relpath
870
+ relative_src = None
871
+
847
872
  try:
848
873
  _support_symlinks = are_symlinks_supported(os.path.dirname(os.path.commonpath([abs_src, abs_dst])))
849
874
  except PermissionError:
@@ -852,9 +877,10 @@ def _create_symlink(src: str, dst: str, new_blob: bool = False) -> None:
852
877
  _support_symlinks = are_symlinks_supported(os.path.dirname(abs_dst))
853
878
 
854
879
  if _support_symlinks:
855
- logger.info(f"Creating pointer from {abs_src} to {abs_dst}")
880
+ src_rel_or_abs = relative_src or abs_src
881
+ logger.info(f"Creating pointer from {src_rel_or_abs} to {abs_dst}")
856
882
  try:
857
- os.symlink(abs_src, abs_dst)
883
+ os.symlink(src_rel_or_abs, abs_dst)
858
884
  except FileExistsError:
859
885
  if os.path.islink(abs_dst) and os.path.realpath(abs_dst) == os.path.realpath(abs_src):
860
886
  # `abs_dst` already exists and is a symlink to the `abs_src` blob. It is most likely that the file has
@@ -1106,11 +1132,17 @@ def hf_hub_download(
1106
1132
 
1107
1133
  # cross platform transcription of filename, to be used as a local file path.
1108
1134
  relative_filename = os.path.join(*filename.split("/"))
1135
+ if os.name == "nt":
1136
+ if relative_filename.startswith("..\\") or "\\..\\" in relative_filename:
1137
+ raise ValueError(
1138
+ f"Invalid filename: cannot handle filename '{relative_filename}' on Windows. Please ask the repository"
1139
+ " owner to rename this file."
1140
+ )
1109
1141
 
1110
1142
  # if user provides a commit_hash and they already have the file on disk,
1111
1143
  # shortcut everything.
1112
1144
  if REGEX_COMMIT_HASH.match(revision):
1113
- pointer_path = os.path.join(storage_folder, "snapshots", revision, relative_filename)
1145
+ pointer_path = _get_pointer_path(storage_folder, revision, relative_filename)
1114
1146
  if os.path.exists(pointer_path):
1115
1147
  if local_dir is not None:
1116
1148
  return _to_local_dir(pointer_path, local_dir, relative_filename, use_symlinks=local_dir_use_symlinks)
@@ -1205,7 +1237,7 @@ def hf_hub_download(
1205
1237
 
1206
1238
  # Return pointer file if exists
1207
1239
  if commit_hash is not None:
1208
- pointer_path = os.path.join(storage_folder, "snapshots", commit_hash, relative_filename)
1240
+ pointer_path = _get_pointer_path(storage_folder, commit_hash, relative_filename)
1209
1241
  if os.path.exists(pointer_path):
1210
1242
  if local_dir is not None:
1211
1243
  return _to_local_dir(
@@ -1234,7 +1266,7 @@ def hf_hub_download(
1234
1266
  assert etag is not None, "etag must have been retrieved from server"
1235
1267
  assert commit_hash is not None, "commit_hash must have been retrieved from server"
1236
1268
  blob_path = os.path.join(storage_folder, "blobs", etag)
1237
- pointer_path = os.path.join(storage_folder, "snapshots", commit_hash, relative_filename)
1269
+ pointer_path = _get_pointer_path(storage_folder, commit_hash, relative_filename)
1238
1270
 
1239
1271
  os.makedirs(os.path.dirname(blob_path), exist_ok=True)
1240
1272
  os.makedirs(os.path.dirname(pointer_path), exist_ok=True)
@@ -1523,6 +1555,19 @@ def _chmod_and_replace(src: str, dst: str) -> None:
1523
1555
  os.replace(src, dst)
1524
1556
 
1525
1557
 
1558
+ def _get_pointer_path(storage_folder: str, revision: str, relative_filename: str) -> str:
1559
+ # Using `os.path.abspath` instead of `Path.resolve()` to avoid resolving symlinks
1560
+ snapshot_path = os.path.join(storage_folder, "snapshots")
1561
+ pointer_path = os.path.join(snapshot_path, revision, relative_filename)
1562
+ if Path(os.path.abspath(snapshot_path)) not in Path(os.path.abspath(pointer_path)).parents:
1563
+ raise ValueError(
1564
+ "Invalid pointer path: cannot create pointer path in snapshot folder if"
1565
+ f" `storage_folder='{storage_folder}'`, `revision='{revision}'` and"
1566
+ f" `relative_filename='{relative_filename}'`."
1567
+ )
1568
+ return pointer_path
1569
+
1570
+
1526
1571
  def _to_local_dir(
1527
1572
  path: str, local_dir: str, relative_filename: str, use_symlinks: Union[bool, Literal["auto"]]
1528
1573
  ) -> str:
@@ -1530,7 +1575,14 @@ def _to_local_dir(
1530
1575
 
1531
1576
  Either symlink to blob file in cache or duplicate file depending on `use_symlinks` and file size.
1532
1577
  """
1578
+ # Using `os.path.abspath` instead of `Path.resolve()` to avoid resolving symlinks
1533
1579
  local_dir_filepath = os.path.join(local_dir, relative_filename)
1580
+ if Path(os.path.abspath(local_dir)) not in Path(os.path.abspath(local_dir_filepath)).parents:
1581
+ raise ValueError(
1582
+ f"Cannot copy file '{relative_filename}' to local dir '{local_dir}': file would not be in the local"
1583
+ " directory."
1584
+ )
1585
+
1534
1586
  os.makedirs(os.path.dirname(local_dir_filepath), exist_ok=True)
1535
1587
  real_blob_path = os.path.realpath(path)
1536
1588
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: huggingface-hub
3
- Version: 0.13.2
3
+ Version: 0.13.4
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,12 +1,12 @@
1
- huggingface_hub/__init__.py,sha256=mKZG1DJTUD_N719LQeNIai1eNE7oAVl6SWKzAgm7xgI,14645
1
+ huggingface_hub/__init__.py,sha256=M4fdGRVLQGaOF8nrc9XBSyu_o6OuXcmzvAXD6vbxxfo,14645
2
2
  huggingface_hub/_commit_api.py,sha256=QP3YtZdMOFKW0EchiS9JGPo5EVlkUz6cGktCagvoOx0,22558
3
- huggingface_hub/_login.py,sha256=iKK6-4tDBcdCoJar_TXILUdJ76G00QYbgFVM5Dtput8,11531
3
+ huggingface_hub/_login.py,sha256=X0hXt2AwMZbMlH0gnRQALyD48QJ_aDMGBEN6Gs0Hmz0,11517
4
4
  huggingface_hub/_snapshot_download.py,sha256=eY0OWOpunWJY32d1d30ggV3rr3ND_LpEnYmu87nzZcY,11339
5
5
  huggingface_hub/_space_api.py,sha256=URSt8IDDnzZ4wiGiuoZgwNP3ZMgNmXZQGFcOQhfkQEU,3120
6
6
  huggingface_hub/community.py,sha256=WwVSOtephAX0OqALlOW_1EPu09r-Y5WpIF7jPkn0ze8,11062
7
7
  huggingface_hub/constants.py,sha256=EIhFt9LSDZKnstgJ3Zwqu2coHBHg8ms7dXNPE6QkFU8,4714
8
8
  huggingface_hub/fastai_utils.py,sha256=5I7zAfgHJU_mZnxnf9wgWTHrCRu_EAV8VTangDVfE_o,16676
9
- huggingface_hub/file_download.py,sha256=hL8lqdDQwD5dlCzztl0X41lVZW_yUuKNEB2LCdQ4NnI,63600
9
+ huggingface_hub/file_download.py,sha256=APkKWCyBRqx0g4-Uhs3oqyFP5Wt5HiNYrK708MqcmUs,66482
10
10
  huggingface_hub/hf_api.py,sha256=Zh_iIV_Qhk79nbKaXigtcanCeGVfIpqdkqU9yYhaH3M,173043
11
11
  huggingface_hub/hub_mixin.py,sha256=94BN_vzHDBX2tDgVV8la4CfkUzN2OgLsV9p9sz4OP7c,16783
12
12
  huggingface_hub/inference_api.py,sha256=3NkHAAGS9wK8PbXxly8YI-0V6gfZgZvV3N5bTdRfvDM,7882
@@ -48,9 +48,9 @@ huggingface_hub/utils/endpoint_helpers.py,sha256=wXE3U1resSFvfdZbNevzrFyf39o9LfE
48
48
  huggingface_hub/utils/logging.py,sha256=-Uov2WGLv16hS-V4Trvs_XO-TvSeZ1xIWZ-cfvDl7ac,4778
49
49
  huggingface_hub/utils/sha.py,sha256=Wmeh2lwS2H0_CNLqDk_mNyb4jAjfTdlG6FZsuh6LqVg,890
50
50
  huggingface_hub/utils/tqdm.py,sha256=iTe9IhbPWIezSn6GBAuPlZe_q-5T47ARwUJAQZ6xepc,5741
51
- huggingface_hub-0.13.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
52
- huggingface_hub-0.13.2.dist-info/METADATA,sha256=6Eyt7W32_uAj1Sr7rN8VfS_Y0XEYykqpCYuXh-Qvet4,7476
53
- huggingface_hub-0.13.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
54
- huggingface_hub-0.13.2.dist-info/entry_points.txt,sha256=7-_O79Kk26OM9R3QgywVzfyrNjZ3F8tCUhDtozJ7yIc,83
55
- huggingface_hub-0.13.2.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
56
- huggingface_hub-0.13.2.dist-info/RECORD,,
51
+ huggingface_hub-0.13.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
52
+ huggingface_hub-0.13.4.dist-info/METADATA,sha256=SSrUKfQQ8XvDsppt1h-fwdelK47KD_h_12VRL8USH8o,7476
53
+ huggingface_hub-0.13.4.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
54
+ huggingface_hub-0.13.4.dist-info/entry_points.txt,sha256=7-_O79Kk26OM9R3QgywVzfyrNjZ3F8tCUhDtozJ7yIc,83
55
+ huggingface_hub-0.13.4.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
56
+ huggingface_hub-0.13.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: bdist_wheel (0.40.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5