style: Format code with black

This commit is contained in:
Paul Gauthier (aider) 2024-08-25 07:55:08 -07:00
parent 7f1f2cb7ba
commit 2570a4d193
2 changed files with 8 additions and 3 deletions

View file

@ -458,7 +458,9 @@ class Model(ModelSettings):
cache_dir.mkdir(parents=True, exist_ok=True)
current_time = time.time()
cache_age = current_time - cache_file.stat().st_mtime if cache_file.exists() else float('inf')
cache_age = (
current_time - cache_file.stat().st_mtime if cache_file.exists() else float("inf")
)
if cache_file.exists() and cache_age < 86400: # 86400 seconds = 1 day
content = safe_read_json(cache_file)

View file

@ -82,6 +82,7 @@ def make_repo(path=None):
import json
def is_image_file(file_name):
"""
Check if the given file name has an image file extension.
@ -92,16 +93,18 @@ def is_image_file(file_name):
file_name = str(file_name) # Convert file_name to string
return any(file_name.endswith(ext) for ext in IMAGE_EXTENSIONS)
def safe_read_json(file_path):
try:
with open(file_path, 'r') as f:
with open(file_path, "r") as f:
return json.load(f)
except Exception:
return None
def safe_write_json(file_path, data):
try:
with open(file_path, 'w') as f:
with open(file_path, "w") as f:
json.dump(data, f)
return True
except Exception: