Add isort and ruff linter (#6575)

* Add isort and ruff linter

Both linters are pretty common among modern python code bases.

The isort tool provides stable sorting and grouping, as well as pruning
of unused imports.

Ruff is a modern linter, that is very fast due to being written in rust.
It can detect many common issues in a python codebase.

Removes the pylint dev requirement, since ruff replaces it.

* treewide: fix issues detected by ruff

* treewide: fix bare except clauses

* .devcontainer: Set up isort

* treewide: optimize imports

* treewide: apply black

* treewide: make regex patterns raw strings

This is necessary for escape sequences to be properly recognized.
This commit is contained in:
Martin Weinelt
2023-05-29 12:31:17 +02:00
committed by GitHub
parent 1e17dbaa91
commit ab50d0b006
71 changed files with 346 additions and 459 deletions

View File

@@ -15,10 +15,10 @@ import numpy as np
from frigate.comms.dispatcher import Dispatcher
from frigate.config import (
CameraConfig,
MqttConfig,
SnapshotsConfig,
RecordConfig,
FrigateConfig,
MqttConfig,
RecordConfig,
SnapshotsConfig,
)
from frigate.const import CLIPS_DIR
from frigate.events.maintainer import EventTypeEnum
@@ -141,7 +141,7 @@ class TrackedObject:
# check each zone
for name, zone in self.camera_config.zones.items():
# if the zone is not for this object type, skip
if len(zone.objects) > 0 and not obj_data["label"] in zone.objects:
if len(zone.objects) > 0 and obj_data["label"] not in zone.objects:
continue
contour = zone.contour
# check if the object is in the zone
@@ -177,11 +177,7 @@ class TrackedObject:
return (thumb_update, significant_change)
def to_dict(self, include_thumbnail: bool = False):
snapshot_time = (
self.thumbnail_data["frame_time"]
if not self.thumbnail_data is None
else 0.0
)
(self.thumbnail_data["frame_time"] if self.thumbnail_data is not None else 0.0)
event = {
"id": self.obj_data["id"],
"camera": self.camera,
@@ -526,7 +522,7 @@ class CameraState:
for id in removed_ids:
# publish events to mqtt
removed_obj = tracked_objects[id]
if not "end_time" in removed_obj.obj_data:
if "end_time" not in removed_obj.obj_data:
removed_obj.obj_data["end_time"] = frame_time
for c in self.callbacks["end"]:
c(self.name, removed_obj, frame_time)
@@ -1028,4 +1024,4 @@ class TrackedObjectProcessor(threading.Thread):
event_id, camera = self.event_processed_queue.get()
self.camera_states[camera].finished(event_id)
logger.info(f"Exiting object processor...")
logger.info("Exiting object processor...")