Skip to content

Commit 70f3a7a

Browse files
Migrate to new Ruff "2025 style guide" formatter (#2749)
* run new ruff style formatter * upgrade the ruff version
1 parent 2702ec2 commit 70f3a7a

File tree

11 files changed

+19
-20
lines changed

11 files changed

+19
-20
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_version() -> str:
9292
]
9393

9494
extras["quality"] = [
95-
"ruff>=0.5.0",
95+
"ruff>=0.9.0",
9696
"mypy==1.5.1",
9797
"libcst==1.4.0",
9898
]

src/huggingface_hub/_commit_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def _upload_lfs_files(
400400
if batch_errors_chunk:
401401
message = "\n".join(
402402
[
403-
f'Encountered error for file with OID {err.get("oid")}: `{err.get("error", {}).get("message")}'
403+
f"Encountered error for file with OID {err.get('oid')}: `{err.get('error', {}).get('message')}"
404404
for err in batch_errors_chunk
405405
]
406406
)

src/huggingface_hub/commands/scan_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(self):
6767
self._print_hf_cache_info_as_table(hf_cache_info)
6868

6969
print(
70-
f"\nDone in {round(t1-t0,1)}s. Scanned {len(hf_cache_info.repos)} repo(s)"
70+
f"\nDone in {round(t1 - t0, 1)}s. Scanned {len(hf_cache_info.repos)} repo(s)"
7171
f" for a total of {ANSI.red(hf_cache_info.size_on_disk_str)}."
7272
)
7373
if len(hf_cache_info.warnings) > 0:

src/huggingface_hub/file_download.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,8 +1581,7 @@ def _chmod_and_move(src: Path, dst: Path) -> None:
15811581
os.chmod(str(src), stat.S_IMODE(cache_dir_mode))
15821582
except OSError as e:
15831583
logger.warning(
1584-
f"Could not set the permissions on the file '{src}'. "
1585-
f"Error: {e}.\nContinuing without setting permissions."
1584+
f"Could not set the permissions on the file '{src}'. Error: {e}.\nContinuing without setting permissions."
15861585
)
15871586
finally:
15881587
try:

src/huggingface_hub/hf_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5612,7 +5612,7 @@ def parse_safetensors_file_metadata(
56125612
if metadata_size <= 100000:
56135613
metadata_as_bytes = response.content[8 : 8 + metadata_size]
56145614
else: # 3.b. Request full metadata
5615-
response = get_session().get(url, headers={**_headers, "range": f"bytes=8-{metadata_size+7}"})
5615+
response = get_session().get(url, headers={**_headers, "range": f"bytes=8-{metadata_size + 7}"})
56165616
hf_raise_for_status(response)
56175617
metadata_as_bytes = response.content
56185618

src/huggingface_hub/serialization/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def split_state_dict_into_shards_factory(
164164
tensor_name_to_filename = {}
165165
filename_to_tensors = {}
166166
for idx, shard in enumerate(shard_list):
167-
filename = filename_pattern.format(suffix=f"-{idx+1:05d}-of-{nb_shards:05d}")
167+
filename = filename_pattern.format(suffix=f"-{idx + 1:05d}-of-{nb_shards:05d}")
168168
for key in shard:
169169
tensor_name_to_filename[key] = filename
170170
filename_to_tensors[filename] = list(shard.keys())

src/huggingface_hub/serialization/_torch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def load_state_dict_from_file(
649649
from torch import load
650650
except ImportError as e:
651651
raise ImportError(
652-
"Please install `torch` to load torch tensors. " "You can install it with `pip install torch`."
652+
"Please install `torch` to load torch tensors. You can install it with `pip install torch`."
653653
) from e
654654
# Add additional kwargs, mmap is only supported in torch >= 2.1.0
655655
additional_kwargs = {}

src/huggingface_hub/utils/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _get_default_logging_level():
5959
return log_levels[env_level_str]
6060
else:
6161
logging.getLogger().warning(
62-
f"Unknown option HF_HUB_VERBOSITY={env_level_str}, has to be one of: { ', '.join(log_levels.keys()) }"
62+
f"Unknown option HF_HUB_VERBOSITY={env_level_str}, has to be one of: {', '.join(log_levels.keys())}"
6363
)
6464
return _default_log_level
6565

tests/test_cache_layout.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_file_downloaded_in_cache(self):
4242
revision=revision,
4343
)
4444

45-
expected_directory_name = f'models--{MODEL_IDENTIFIER.replace("/", "--")}'
45+
expected_directory_name = f"models--{MODEL_IDENTIFIER.replace('/', '--')}"
4646
expected_path = os.path.join(cache, expected_directory_name)
4747

4848
refs = os.listdir(os.path.join(expected_path, "refs"))
@@ -87,7 +87,7 @@ def test_no_exist_file_is_cached(self):
8787
# The file does not exist, so we get an exception.
8888
hf_hub_download(MODEL_IDENTIFIER, filename, cache_dir=cache, revision=revision)
8989

90-
expected_directory_name = f'models--{MODEL_IDENTIFIER.replace("/", "--")}'
90+
expected_directory_name = f"models--{MODEL_IDENTIFIER.replace('/', '--')}"
9191
expected_path = os.path.join(cache, expected_directory_name)
9292

9393
refs = os.listdir(os.path.join(expected_path, "refs"))
@@ -151,7 +151,7 @@ def test_multiple_refs_for_same_file(self):
151151
hf_hub_download(MODEL_IDENTIFIER, "file_0.txt", cache_dir=cache)
152152
hf_hub_download(MODEL_IDENTIFIER, "file_0.txt", cache_dir=cache, revision="file-2")
153153

154-
expected_directory_name = f'models--{MODEL_IDENTIFIER.replace("/", "--")}'
154+
expected_directory_name = f"models--{MODEL_IDENTIFIER.replace('/', '--')}"
155155
expected_path = os.path.join(cache, expected_directory_name)
156156

157157
refs = os.listdir(os.path.join(expected_path, "refs"))
@@ -184,7 +184,7 @@ def test_file_downloaded_in_cache(self):
184184
with SoftTemporaryDirectory() as cache:
185185
snapshot_download(MODEL_IDENTIFIER, cache_dir=cache)
186186

187-
expected_directory_name = f'models--{MODEL_IDENTIFIER.replace("/", "--")}'
187+
expected_directory_name = f"models--{MODEL_IDENTIFIER.replace('/', '--')}"
188188
expected_path = os.path.join(cache, expected_directory_name)
189189

190190
refs = os.listdir(os.path.join(expected_path, "refs"))
@@ -216,7 +216,7 @@ def test_file_downloaded_in_cache_several_revisions(self):
216216
snapshot_download(MODEL_IDENTIFIER, cache_dir=cache, revision="file-3")
217217
snapshot_download(MODEL_IDENTIFIER, cache_dir=cache, revision="file-2")
218218

219-
expected_directory_name = f'models--{MODEL_IDENTIFIER.replace("/", "--")}'
219+
expected_directory_name = f"models--{MODEL_IDENTIFIER.replace('/', '--')}"
220220
expected_path = os.path.join(cache, expected_directory_name)
221221

222222
refs = os.listdir(os.path.join(expected_path, "refs"))
@@ -289,7 +289,7 @@ def test_update_reference(self):
289289
with SoftTemporaryDirectory() as cache:
290290
hf_hub_download(repo_id, "file.txt", cache_dir=cache)
291291

292-
expected_directory_name = f'models--{repo_id.replace("/", "--")}'
292+
expected_directory_name = f"models--{repo_id.replace('/', '--')}"
293293
expected_path = os.path.join(cache, expected_directory_name)
294294

295295
refs = os.listdir(os.path.join(expected_path, "refs"))

tests/test_utils_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def test_ref_to_missing_revision(self) -> None:
492492
self.assertEqual(
493493
str(report.warnings[0]),
494494
"Reference(s) refer to missing commit hashes: {'revision_hash_that_does_not_exist': {'not_main'}} "
495-
+ f"({self.repo_path }).",
495+
+ f"({self.repo_path}).",
496496
)
497497

498498
@xfail_on_windows("Last modified/last accessed work a bit differently on Windows.")

0 commit comments

Comments
 (0)