mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-12-03 02:37:06 +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:
@@ -6,7 +6,7 @@ import logging
|
||||
import threading
|
||||
import time
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from frigate.comms.inter_process import InterProcessRequestor
|
||||
from frigate.config import FrigateConfig
|
||||
@@ -49,9 +49,7 @@ class StatsEmitter(threading.Thread):
|
||||
self.stats_history.append(stats)
|
||||
return stats
|
||||
|
||||
def get_stats_history(
|
||||
self, keys: Optional[list[str]] = None
|
||||
) -> list[dict[str, Any]]:
|
||||
def get_stats_history(self, keys: list[str] | None = None) -> list[dict[str, Any]]:
|
||||
"""Get stats history.
|
||||
|
||||
Supports dot-notation for nested keys to avoid returning large objects
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import logging
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,7 +15,7 @@ class IntelGpuNameResolver:
|
||||
name with the pdev string used by DRM fdinfo.
|
||||
"""
|
||||
|
||||
_names: Optional[dict[str, str]] = None
|
||||
_names: dict[str, str] | None = None
|
||||
|
||||
def get_names(self) -> dict[str, str]:
|
||||
if self._names is not None:
|
||||
@@ -39,7 +38,7 @@ class IntelGpuNameResolver:
|
||||
self._names = names
|
||||
return names
|
||||
|
||||
cpu_name: Optional[str] = None
|
||||
cpu_name: str | None = None
|
||||
if "CPU" in devices:
|
||||
try:
|
||||
cpu_name = self._strip_trademarks(
|
||||
@@ -70,14 +69,14 @@ class IntelGpuNameResolver:
|
||||
return names
|
||||
|
||||
@staticmethod
|
||||
def _format_pdev(pci) -> Optional[str]:
|
||||
def _format_pdev(pci) -> str | None:
|
||||
try:
|
||||
return f"{pci.domain:04x}:{pci.bus:02x}:{pci.device:02x}.{pci.function:x}"
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _resolve_name(cls, raw_name: str, device_type, cpu_name: Optional[str]) -> str:
|
||||
def _resolve_name(cls, raw_name: str, device_type, cpu_name: str | None) -> str:
|
||||
"""Build a display name for a GPU.
|
||||
|
||||
Modern integrated Intel GPUs are reported by OpenVINO with a generic
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
import re
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
|
||||
from prometheus_client import CONTENT_TYPE_LATEST, generate_latest
|
||||
from prometheus_client.core import (
|
||||
@@ -11,7 +11,7 @@ from prometheus_client.core import (
|
||||
)
|
||||
|
||||
|
||||
class CustomCollector(object):
|
||||
class CustomCollector:
|
||||
def __init__(self, _url):
|
||||
self.complete_stats = {} # Store complete stats data
|
||||
self.process_stats = {} # Keep for CPU processing
|
||||
@@ -491,7 +491,7 @@ collector = CustomCollector(None)
|
||||
REGISTRY.register(collector)
|
||||
|
||||
|
||||
def update_metrics(stats: Dict[str, Any], event_counts: List[Dict[str, Any]]):
|
||||
def update_metrics(stats: dict[str, Any], event_counts: list[dict[str, Any]]):
|
||||
"""Updates the Prometheus metrics with the given stats data."""
|
||||
try:
|
||||
# Store the complete stats for later use by collect()
|
||||
|
||||
@@ -7,7 +7,7 @@ import shutil
|
||||
import time
|
||||
from json import JSONDecodeError
|
||||
from multiprocessing.managers import DictProxy
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
from requests.exceptions import RequestException
|
||||
@@ -78,7 +78,7 @@ def stats_init(
|
||||
return stats_tracking
|
||||
|
||||
|
||||
def read_temperature(path: str) -> Optional[float]:
|
||||
def read_temperature(path: str) -> float | None:
|
||||
if os.path.isfile(path):
|
||||
with open(path) as f:
|
||||
line = f.readline().strip()
|
||||
@@ -106,7 +106,7 @@ def get_temperatures() -> dict[str, float]:
|
||||
def get_detector_temperature(
|
||||
detector_type: str,
|
||||
detector_index_by_type: dict[str, int],
|
||||
) -> Optional[float]:
|
||||
) -> float | None:
|
||||
"""Get temperature for a specific detector based on its type."""
|
||||
if detector_type == "edgetpu":
|
||||
# Get temperatures for all attached Corals
|
||||
|
||||
Reference in New Issue
Block a user