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

* 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:
Nicolas Mowen
2026-07-06 12:28:02 -05:00
committed by GitHub
parent 455b8687e8
commit 4ee12e6237
169 changed files with 1053 additions and 1150 deletions
+12 -14
View File
@@ -15,7 +15,7 @@ from collections import deque
from collections.abc import Mapping
from multiprocessing.managers import ValueProxy
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any
import numpy as np
from ruamel.yaml import YAML
@@ -152,7 +152,7 @@ def get_record_segment_time(config: "CameraConfig") -> int:
def load_labels(
path: Optional[str], encoding="utf-8", prefill=91, indexed: bool | None = None
path: str | None, encoding="utf-8", prefill=91, indexed: bool | None = None
):
"""Loads labels from file (with or without index numbers).
Args:
@@ -164,7 +164,7 @@ def load_labels(
if path is None:
return {}
with open(path, "r", encoding=encoding) as f:
with open(path, encoding=encoding) as f:
labels = {index: "unknown" for index in range(prefill)}
lines = f.readlines()
if not lines:
@@ -180,8 +180,8 @@ def load_labels(
def to_relative_box(
width: int, height: int, box: Tuple[int, int, int, int]
) -> Tuple[int | float, int | float, int | float, int | float]:
width: int, height: int, box: tuple[int, int, int, int]
) -> tuple[int | float, int | float, int | float, int | float]:
return (
box[0] / width, # x
box[1] / height, # y
@@ -195,7 +195,7 @@ def create_mask(frame_shape, mask):
mask_img[:] = 255
def process_config_query_string(query_string: Dict[str, list]) -> Dict[str, Any]:
def process_config_query_string(query_string: dict[str, list]) -> dict[str, Any]:
updates = {}
for key_path_str, new_value_list in query_string.items():
# use the string key as-is for updates dictionary
@@ -213,8 +213,8 @@ def process_config_query_string(query_string: Dict[str, list]) -> Dict[str, Any]
def flatten_config_data(
config_data: Dict[str, Any], parent_key: str = ""
) -> Dict[str, Any]:
config_data: dict[str, Any], parent_key: str = ""
) -> dict[str, Any]:
items = []
for key, value in config_data.items():
escaped_key = escape_config_key_segment(str(key))
@@ -261,12 +261,12 @@ def split_config_key_path(key_path_str: str) -> list[str]:
return parts
def update_yaml_file_bulk(file_path: str, updates: Dict[str, Any]):
def update_yaml_file_bulk(file_path: str, updates: dict[str, Any]):
yaml = YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
try:
with open(file_path, "r") as f:
with open(file_path) as f:
data = yaml.load(f)
except FileNotFoundError:
logger.error(
@@ -438,9 +438,7 @@ def generate_color_palette(n):
return colors
def serialize(
vector: Union[list[float], np.ndarray, float], pack: bool = True
) -> bytes:
def serialize(vector: list[float] | np.ndarray | float, pack: bool = True) -> bytes:
"""Serializes a list of floats, numpy array, or single float into a compact "raw bytes" format"""
if isinstance(vector, np.ndarray):
# Convert numpy array to list of floats
@@ -459,7 +457,7 @@ def serialize(
else:
return vector
except struct.error as e:
raise ValueError(f"Failed to pack vector: {e}. Vector: {vector}")
raise ValueError(f"Failed to pack vector: {e}. Vector: {vector}") from e
def deserialize(bytes_data: bytes) -> list[float]: