Skip to content

Commit

Permalink
Make style
Browse files Browse the repository at this point in the history
  • Loading branch information
nemo committed Jan 20, 2025
1 parent 37edded commit f0cabe0
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions scripts/ci_clean_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
Deletion can be enabled by passing `-d` parameter, otherwise it will only list the candidates.
"""

import sys
import argparse
from huggingface_hub import scan_cache_dir
from datetime import datetime as dt

from huggingface_hub import scan_cache_dir


def find_old_revisions(scan_results, max_age_days=30):
"""Find commit hashes of objects in the cache. These objects need a last access time that
Expand All @@ -30,8 +31,8 @@ def find_old_revisions(scan_results, max_age_days=30):

def delete_old_revisions(scan_results, delete_candidates, do_delete=False):
delete_operation = scan_results.delete_revisions(*delete_candidates)
print(f'Would free {delete_operation.expected_freed_size_str}')
print(f'Candidates: {delete_candidates}')
print(f"Would free {delete_operation.expected_freed_size_str}")
print(f"Candidates: {delete_candidates}")

if do_delete:
print("Deleting now.")
Expand All @@ -44,18 +45,23 @@ def delete_old_revisions(scan_results, delete_candidates, do_delete=False):
from argparse import ArgumentParser

parser = ArgumentParser()
parser.add_argument('-a', '--max-age', type=int, default=30, help="Max. age in days items in the cache may have.")
parser.add_argument('-d', '--delete', action='store_true', help=(
"Delete mode; Really delete items if there are candidates. Exit code = 0 when we found something to delete, 1 "
"otherwise."
))
parser.add_argument("-a", "--max-age", type=int, default=30, help="Max. age in days items in the cache may have.")
parser.add_argument(
"-d",
"--delete",
action="store_true",
help=(
"Delete mode; Really delete items if there are candidates. Exit code = 0 when we found something to delete, 1 "
"otherwise."
),
)
args = parser.parse_args()

scan_results = scan_cache_dir()

delete_candidates = find_old_revisions(scan_results, args.max_age)
if not delete_candidates:
print('No delete candidates found, not deleting anything.')
print("No delete candidates found, not deleting anything.")
sys.exit(1)

delete_old_revisions(scan_results, delete_candidates, do_delete=args.delete)

0 comments on commit f0cabe0

Please sign in to comment.