Skip to content

Commit 4ed6e69

Browse files
committed
review suggestions
1 parent 3b6f462 commit 4ed6e69

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import warnings
2323
from collections import defaultdict
2424
from concurrent.futures import Future, ThreadPoolExecutor
25-
from dataclasses import asdict, dataclass, field, replace
25+
from dataclasses import asdict, dataclass, field
2626
from datetime import datetime
2727
from functools import wraps
2828
from itertools import islice
@@ -3148,12 +3148,13 @@ def verify_repo_checksums(
31483148
):
31493149
remote_by_path[entry.path] = entry
31503150

3151-
verification = verify_maps(
3152-
remote_by_path=remote_by_path, local_by_path=local_by_path, revision=remote_revision
3151+
return verify_maps(
3152+
remote_by_path=remote_by_path,
3153+
local_by_path=local_by_path,
3154+
revision=remote_revision,
3155+
verified_path=root,
31533156
)
31543157

3155-
return replace(verification, verified_path=root)
3156-
31573158
@validate_hf_hub_args
31583159
def list_repo_refs(
31593160
self,

src/huggingface_hub/utils/_verification.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FolderVerification:
3333
mismatches: list[Mismatch]
3434
missing_paths: list[str]
3535
extra_paths: list[str]
36-
verified_path: Optional[Path] = None
36+
verified_path: Path
3737

3838

3939
def collect_local_files(root: Path) -> dict[str, Path]:
@@ -76,7 +76,7 @@ def _resolve_commit_hash_from_cache(storage_folder: Path, revision: Optional[str
7676
)
7777

7878

79-
def compute_file_hash(path: Path, algorithm: HashAlgo, *, git_hash_cache: dict[Path, str]) -> str:
79+
def compute_file_hash(path: Path, algorithm: HashAlgo) -> str:
8080
"""
8181
Compute the checksum of a local file using the requested algorithm.
8282
"""
@@ -86,19 +86,18 @@ def compute_file_hash(path: Path, algorithm: HashAlgo, *, git_hash_cache: dict[P
8686
return sha_fileobj(stream).hex()
8787

8888
if algorithm == "git-sha1":
89-
try:
90-
return git_hash_cache[path]
91-
except KeyError:
92-
with path.open("rb") as stream:
93-
digest = git_hash(stream.read())
94-
git_hash_cache[path] = digest
95-
return digest
89+
with path.open("rb") as stream:
90+
return git_hash(stream.read())
9691

9792
raise ValueError(f"Unsupported hash algorithm: {algorithm}")
9893

9994

10095
def verify_maps(
101-
*, remote_by_path: dict[str, Union["RepoFile", "RepoFolder"]], local_by_path: dict[str, Path], revision: str
96+
*,
97+
remote_by_path: dict[str, Union["RepoFile", "RepoFolder"]],
98+
local_by_path: dict[str, Path],
99+
revision: str,
100+
verified_path: Path,
102101
) -> FolderVerification:
103102
"""Compare remote entries and local files and return a verification result."""
104103
remote_paths = set(remote_by_path)
@@ -109,7 +108,6 @@ def verify_maps(
109108
both = sorted(remote_paths & local_paths)
110109

111110
mismatches: list[Mismatch] = []
112-
git_hash_cache: dict[Path, str] = {}
113111

114112
for rel_path in both:
115113
remote_entry = remote_by_path[rel_path]
@@ -127,7 +125,7 @@ def verify_maps(
127125
algorithm = "git-sha1"
128126
expected = str(blob_id).lower()
129127
try:
130-
actual = compute_file_hash(local_path, algorithm, git_hash_cache=git_hash_cache)
128+
actual = compute_file_hash(local_path, algorithm)
131129
except OSError as exc:
132130
mismatches.append(
133131
Mismatch(path=rel_path, expected="<unavailable>", actual=f"io-error:{exc}", algorithm="io")
@@ -143,6 +141,7 @@ def verify_maps(
143141
mismatches=mismatches,
144142
missing_paths=missing,
145143
extra_paths=extra,
144+
verified_path=verified_path,
146145
)
147146

148147

0 commit comments

Comments
 (0)