mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-08-11 13:21:10 +03:00
Increase ruff coverage (#23644)
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / Jetson Jetpack 6 (push) Waiting to run
* Pin ruff * Add python upgrade fixes This enables python upgrade checks in ruff to look for deprecated types and patterns. This namely fixes: - usage of deprecated `Typing` which is now built in - some specific exceptions which are caught and have new aliases Some specific UP checks were also ignored as they are stylistic / unimportant and likely to cause bugs * Remove async blocking calls Use asyncio.to_thread on two remaining blocking calls to fix hanging event thread loop. Enable this specific rule to block it in the future. * Use proper logging mechanism * Correctly format logs * Raise with context When raising an exception include the from context to improve debugging * Cleanup
This commit is contained in:
@@ -8,7 +8,7 @@ import sys
|
||||
import threading
|
||||
from json.decoder import JSONDecodeError
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
import regex
|
||||
from pathvalidate import ValidationError, sanitize_filename
|
||||
@@ -73,7 +73,7 @@ class EmbeddingsContext:
|
||||
# load stats from disk
|
||||
stats_file = os.path.join(CONFIG_DIR, ".search_stats.json")
|
||||
try:
|
||||
with open(stats_file, "r") as f:
|
||||
with open(stats_file) as f:
|
||||
data = json.loads(f.read())
|
||||
self.thumb_stats.from_dict(data["thumb_stats"])
|
||||
self.desc_stats.from_dict(data["desc_stats"])
|
||||
@@ -98,7 +98,7 @@ class EmbeddingsContext:
|
||||
self.requestor.stop()
|
||||
|
||||
def search_thumbnail(
|
||||
self, query: Union[Event, str], event_ids: list[str] = None
|
||||
self, query: Event | str, event_ids: list[str] = None
|
||||
) -> list[tuple[str, float]]:
|
||||
if query.__class__ == Event:
|
||||
cursor = self.db.execute_sql(
|
||||
@@ -255,7 +255,7 @@ class EmbeddingsContext:
|
||||
sanitized_old_name = sanitize_filename(old_name, replacement_text="_")
|
||||
sanitized_new_name = sanitize_filename(new_name, replacement_text="_")
|
||||
except ValidationError as e:
|
||||
raise ValueError(f"Invalid face name: {str(e)}")
|
||||
raise ValueError(f"Invalid face name: {str(e)}") from e
|
||||
|
||||
if not regex.match(valid_name_pattern, old_name):
|
||||
raise ValueError(f"Invalid old face name: {old_name}")
|
||||
|
||||
@@ -435,7 +435,7 @@ class EmbeddingMaintainer(threading.Thread):
|
||||
logger.error(f"No processor handled the topic {topic}")
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.error(f"Unable to handle embeddings request {e}", exc_info=True)
|
||||
logger.exception(f"Unable to handle embeddings request {e}")
|
||||
|
||||
self.embeddings_responder.check_for_request(_handle_request)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user