Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isort and ruff linter #6575

Merged
merged 7 commits into from
May 29, 2023
Merged

Conversation

mweinelt
Copy link
Contributor

@mweinelt mweinelt commented May 22, 2023

The idea of this PR is to gauge interest in setting up these linters. Both are pretty common among modern python code bases. If there is interest to add these linters I can take care of making the CI go green.


Removes the pylint dev requirement, since ruff replaces it.

Previews:

ruff
benchmark.py:1:8: F401 [*] `os` imported but unused
benchmark.py:8:5: F401 [*] `frigate.object_detection.LocalObjectDetector` imported but unused
benchmark.py:56:9: F841 [*] Local variable `detections` is assigned to but never used
docker/rootfs/usr/local/go2rtc/create_config.py:9:1: E402 Module level import not at top of file
docker/rootfs/usr/local/go2rtc/create_config.py:10:1: E402 Module level import not at top of file
frigate/__main__.py:5:1: E402 Module level import not at top of file
frigate/__main__.py:9:1: E402 Module level import not at top of file
frigate/app.py:136:16: E713 [*] Test for membership should be `not in`
frigate/app.py:139:16: E713 [*] Test for membership should be `not in`
frigate/app.py:297:18: F541 [*] f-string without any placeholders
frigate/app.py:470:21: F541 [*] f-string without any placeholders
frigate/comms/dispatcher.py:75:34: F841 [*] Local variable `e` is assigned to but never used
frigate/comms/dispatcher.py:83:34: F841 [*] Local variable `e` is assigned to but never used
frigate/comms/dispatcher.py:131:21: F541 [*] f-string without any placeholders
frigate/comms/dispatcher.py:199:21: F541 [*] f-string without any placeholders
frigate/comms/mqtt.py:180:16: E714 [*] Test for object identity should be `is not`
frigate/comms/mqtt.py:182:21: E714 [*] Test for object identity should be `is not`
frigate/comms/mqtt.py:183:25: E714 [*] Test for object identity should be `is not`
frigate/comms/mqtt.py:192:16: E714 [*] Test for object identity should be `is not`
frigate/comms/mqtt.py:194:16: E714 [*] Test for object identity should be `is not`
frigate/comms/ws.py:48:37: F841 [*] Local variable `e` is assigned to but never used
frigate/comms/ws.py:85:29: F841 [*] Local variable `e` is assigned to but never used
frigate/config.py:11:8: F401 [*] `yaml` imported but unused
frigate/config.py:29:5: F401 [*] `frigate.util.load_labels` imported but unused
frigate/config.py:39:5: F401 [*] `frigate.detectors.PixelFormatEnum` imported but unused
frigate/config.py:40:5: F401 [*] `frigate.detectors.InputTensorEnum` imported but unused
frigate/config.py:44:29: F401 [*] `frigate.version.VERSION` imported but unused
frigate/config.py:490:16: E713 [*] Test for membership should be `not in`
frigate/config.py:779:45: E713 [*] Test for membership should be `not in`
frigate/config.py:784:43: E713 [*] Test for membership should be `not in`
frigate/config.py:1065:20: E713 [*] Test for membership should be `not in`
frigate/detectors/__init__.py:3:28: F401 [*] `.detection_api.DetectionApi` imported but unused
frigate/detectors/__init__.py:5:5: F401 [*] `.detector_config.PixelFormatEnum` imported but unused
frigate/detectors/__init__.py:6:5: F401 [*] `.detector_config.InputTensorEnum` imported but unused
frigate/detectors/__init__.py:7:5: F401 [*] `.detector_config.ModelConfig` imported but unused
frigate/detectors/__init__.py:9:58: F401 [*] `.detector_types.DetectorConfig` imported but unused
frigate/detectors/detector_config.py:6:26: F401 [*] `typing.List` imported but unused
frigate/detectors/detector_config.py:6:49: F401 [*] `typing.Union` imported but unused
frigate/detectors/detector_config.py:6:56: F401 [*] `typing.Literal` imported but unused
frigate/detectors/detector_config.py:11:47: F401 [*] `pydantic.validator` imported but unused
frigate/detectors/plugins/cpu_tfl.py:7:22: F401 [*] `pydantic.Extra` imported but unused
frigate/detectors/plugins/deepstack.py:9:22: F401 [*] `pydantic.Extra` imported but unused
frigate/detectors/plugins/deepstack.py:51:9: F841 [*] Local variable `data` is assigned to but never used
frigate/detectors/plugins/deepstack.py:64:30: F541 [*] f-string without any placeholders
frigate/detectors/plugins/deepstack.py:68:30: F541 [*] f-string without any placeholders
frigate/detectors/plugins/edgetpu_tfl.py:7:22: F401 [*] `pydantic.Extra` imported but unused
frigate/detectors/plugins/openvino.py:8:22: F401 [*] `pydantic.Extra` imported but unused
frigate/detectors/plugins/openvino.py:44:13: E722 Do not use bare `except`
frigate/detectors/plugins/tensorrt.py:11:31: F841 [*] Local variable `e` is assigned to but never used
frigate/detectors/plugins/tensorrt.py:175:25: F541 [*] f-string without any placeholders
frigate/events/cleanup.py:10:20: F401 [*] `peewee.fn` imported but unused
frigate/events/cleanup.py:48:13: E741 Ambiguous variable name: `l`
frigate/events/cleanup.py:59:46: E712 [*] Comparison to `False` should be `cond is False`
frigate/events/cleanup.py:79:46: E712 [*] Comparison to `False` should be `cond is False`
frigate/events/cleanup.py:95:17: E741 Ambiguous variable name: `l`
frigate/events/cleanup.py:106:50: E712 [*] Comparison to `False` should be `cond is False`
frigate/events/cleanup.py:125:50: E712 [*] Comparison to `False` should be `cond is False`
frigate/events/cleanup.py:134:1: E101 Indentation contains mixed spaces and tabs
frigate/events/cleanup.py:135:1: E101 Indentation contains mixed spaces and tabs
frigate/events/cleanup.py:136:1: E101 Indentation contains mixed spaces and tabs
frigate/events/cleanup.py:172:35: E712 [*] Comparison to `False` should be `cond is False`
frigate/events/cleanup.py:172:64: E712 [*] Comparison to `False` should be `cond is False`
frigate/events/cleanup.py:176:21: F541 [*] f-string without any placeholders
frigate/events/external.py:6:8: F401 [*] `glob` imported but unused
frigate/events/maintainer.py:8:20: F401 [*] `peewee.fn` imported but unused
frigate/events/maintainer.py:68:31: E711 [*] Comparison to `None` should be `cond is None`
frigate/events/maintainer.py:102:31: E711 [*] Comparison to `None` should be `cond is None`
frigate/events/maintainer.py:104:21: F541 [*] f-string without any placeholders
frigate/http.py:108:12: E714 [*] Test for object identity should be `is not`
frigate/http.py:111:12: E714 [*] Test for object identity should be `is not`
frigate/http.py:256:12: E714 [*] Test for object identity should be `is not`
frigate/http.py:299:19: F541 [*] f-string without any placeholders
frigate/http.py:304:19: F541 [*] f-string without any placeholders
frigate/http.py:440:28: E713 [*] Test for membership should be `not in`
frigate/http.py:479:16: E714 [*] Test for object identity should be `is not`
frigate/http.py:489:28: E714 [*] Test for object identity should be `is not`
frigate/http.py:491:9: E722 Do not use bare `except`
frigate/http.py:596:61: E711 [*] Comparison to `None` should be `cond is not None`
frigate/http.py:612:28: E714 [*] Test for object identity should be `is not`
frigate/http.py:620:9: E722 Do not use bare `except`
frigate/http.py:622:5: E722 Do not use bare `except`
frigate/http.py:648:42: E712 [*] Comparison to `True` should be `cond is True`
frigate/http.py:656:42: E712 [*] Comparison to `True` should be `cond is True`
frigate/http.py:823:12: E714 [*] Test for object identity should be `is not`
frigate/http.py:826:12: E714 [*] Test for object identity should be `is not`
frigate/http.py:829:12: E714 [*] Test for object identity should be `is not`
frigate/http.py:897:5: E722 Do not use bare `except`
frigate/http.py:902:49: F541 [*] f-string without any placeholders
frigate/http.py:963:9: F841 [*] Local variable `check_runtime` is assigned to but never used
frigate/http.py:964:25: F841 [*] Local variable `e` is assigned to but never used
frigate/http.py:988:25: F841 [*] Local variable `e` is assigned to but never used
frigate/http.py:993:32: F541 [*] f-string without any placeholders
frigate/http.py:1534:43: F541 [*] f-string without any placeholders
frigate/log.py:13:27: F811 Redefinition of unused `Optional` from line 10
frigate/log.py:14:19: F811 Redefinition of unused `FrameType` from line 11
frigate/log.py:47:39: F541 [*] f-string without any placeholders
frigate/models.py:1:19: F401 [*] `numpy.unique` imported but unused
frigate/object_detection.py:164:17: E714 [*] Test for object identity should be `is not`
frigate/object_processing.py:144:46: E713 [*] Test for membership should be `not in`
frigate/object_processing.py:180:9: F841 [*] Local variable `snapshot_time` is assigned to but never used
frigate/object_processing.py:182:20: E714 [*] Test for object identity should be `is not`
frigate/object_processing.py:529:20: E713 [*] Test for membership should be `not in`
frigate/object_processing.py:1031:21: F541 [*] f-string without any placeholders
frigate/objects.py:1:8: F401 [*] `copy` imported but unused
frigate/objects.py:2:8: F401 [*] `datetime` imported but unused
frigate/objects.py:3:8: F401 [*] `itertools` imported but unused
frigate/objects.py:4:8: F401 [*] `multiprocessing` imported but unused
frigate/objects.py:7:8: F401 [*] `threading` imported but unused
frigate/objects.py:8:8: F401 [*] `time` imported but unused
frigate/objects.py:11:8: F401 [*] `cv2` imported but unused
frigate/objects.py:163:20: E713 [*] Test for membership should be `not in`
frigate/output.py:7:8: F401 [*] `operator` imported but unused
frigate/output.py:152:25: E722 Do not use bare `except`
frigate/output.py:188:16: E714 [*] Test for object identity should be `is not`
frigate/output.py:232:22: F541 [*] f-string without any placeholders
frigate/output.py:304:30: F541 [*] f-string without any placeholders
frigate/output.py:388:21: E714 [*] Test for object identity should be `is not`
frigate/output.py:426:39: F541 [*] f-string without any placeholders
frigate/output.py:427:18: F541 [*] f-string without any placeholders
frigate/plus.py:6:25: F401 [*] `typing.Dict` imported but unused
frigate/ptz.py:148:16: E713 [*] Test for membership should be `not in`
frigate/record/cleanup.py:228:20: E713 [*] Test for membership should be `not in`
frigate/record/cleanup.py:250:29: F541 [*] f-string without any placeholders
frigate/record/maintainer.py:66:13: E722 Do not use bare `except`
frigate/record/maintainer.py:118:40: E711 [*] Comparison to `None` should be `cond is None`
frigate/record/maintainer.py:130:25: E713 [*] Test for membership should be `not in`
frigate/record/maintainer.py:397:21: F541 [*] f-string without any placeholders
frigate/stats.py:34:5: E722 Do not use bare `except`
frigate/stats.py:311:21: F541 [*] f-string without any placeholders
frigate/storage.py:110:46: E712 [*] Comparison to `True` should be `cond is True`
frigate/storage.py:191:21: F541 [*] f-string without any placeholders
frigate/test/test_config.py:678:20: E713 [*] Test for membership should be `not in`
frigate/test/test_config.py:989:9: F841 [*] Local variable `runtime_config` is assigned to but never used
frigate/test/test_config.py:1148:73: E712 [*] Comparison to `False` should be `cond is False`
frigate/test/test_gpu_stats.py:4:66: F401 [*] `frigate.util.get_nvidia_gpu_stats` imported but unused
frigate/test/test_http.py:131:33: F541 [*] f-string without any placeholders
frigate/test/test_http.py:136:33: F541 [*] f-string without any placeholders
frigate/test/test_http.py:140:17: F541 [*] f-string without any placeholders
frigate/test/test_http.py:146:17: F541 [*] f-string without any placeholders
frigate/test/test_http.py:233:52: E712 [*] Comparison to `True` should be `cond is True`
frigate/test/test_http.py:238:52: E712 [*] Comparison to `False` should be `cond is False`
frigate/test/test_reduce_boxes.py:1:8: F401 [*] `numpy` imported but unused
frigate/test/test_storage.py:2:8: F401 [*] `json` imported but unused
frigate/test/test_storage.py:6:38: F401 [*] `unittest.mock.patch` imported but unused
frigate/test/test_storage.py:12:33: F401 [*] `playhouse.shortcuts.model_to_dict` imported but unused
frigate/test/test_storage.py:15:26: F401 [*] `frigate.http.create_app` imported but unused
frigate/test/test_yuv_region_2_rgb.py:36:9: F841 [*] Local variable `cropped` is assigned to but never used
frigate/util.py:23:8: F811 Redefinition of unused `os` from line 12
frigate/util.py:460:12: E714 [*] Test for object identity should be `is not`
frigate/util.py:843:9: E722 Do not use bare `except`
frigate/util.py:874:13: E722 Do not use bare `except`
frigate/util.py:994:5: E722 Do not use bare `except`
frigate/video.py:48:12: E713 [*] Test for membership should be `not in`
frigate/video.py:76:16: E714 [*] Test for object identity should be `is not`
frigate/video.py:172:9: F841 [*] Local variable `skipped_fps` is assigned to but never used
frigate/video.py:179:29: F841 [*] Local variable `e` is assigned to but never used
frigate/video.py:185:41: E711 [*] Comparison to `None` should be `cond is not None`
frigate/video.py:607:25: F541 [*] f-string without any placeholders
frigate/video.py:658:24: E713 [*] Test for membership should be `not in`
frigate/watchdog.py:5:8: F401 [*] `os` imported but unused
frigate/watchdog.py:6:8: F401 [*] `signal` imported but unused
frigate/watchdog.py:42:21: F541 [*] f-string without any placeholders
migrations/001_create_events_table.py:24:8: F401 [*] `datetime` imported but unused
migrations/001_create_events_table.py:26:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/001_create_events_table.py:29:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/002_add_clip_snapshot.py:24:8: F401 [*] `datetime` imported but unused
migrations/002_add_clip_snapshot.py:26:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/002_add_clip_snapshot.py:30:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/003_create_recordings_table.py:25:28: F401 [*] `frigate.models.Recordings` imported but unused
migrations/004_add_bbox_region_area.py:24:8: F401 [*] `datetime` imported but unused
migrations/004_add_bbox_region_area.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/004_add_bbox_region_area.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/004_add_bbox_region_area.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/004_add_bbox_region_area.py:41:16: F405 `JSONField` may be undefined, or defined from star imports: `playhouse.sqlite_ext`
migrations/004_add_bbox_region_area.py:42:13: F405 `JSONField` may be undefined, or defined from star imports: `playhouse.sqlite_ext`
migrations/005_make_end_time_nullable.py:24:8: F401 [*] `datetime` imported but unused
migrations/005_make_end_time_nullable.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/005_make_end_time_nullable.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/005_make_end_time_nullable.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/006_add_motion_active_objects.py:24:8: F401 [*] `datetime` imported but unused
migrations/006_add_motion_active_objects.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/006_add_motion_active_objects.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/006_add_motion_active_objects.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/007_add_retain_indefinitely.py:24:8: F401 [*] `datetime` imported but unused
migrations/007_add_retain_indefinitely.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/007_add_retain_indefinitely.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/007_add_retain_indefinitely.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/008_add_sub_label.py:24:8: F401 [*] `datetime` imported but unused
migrations/008_add_sub_label.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/008_add_sub_label.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/008_add_sub_label.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/010_add_plus_image_id.py:24:8: F401 [*] `datetime` imported but unused
migrations/010_add_plus_image_id.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/010_add_plus_image_id.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/010_add_plus_image_id.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/012_add_segment_size.py:24:8: F401 [*] `datetime` imported but unused
migrations/012_add_segment_size.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/012_add_segment_size.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/012_add_segment_size.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/013_create_timeline_table.py:24:8: F401 [*] `datetime` imported but unused
migrations/013_create_timeline_table.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/013_create_timeline_table.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/013_create_timeline_table.py:28:28: F401 [*] `frigate.models.Recordings` imported but unused
migrations/013_create_timeline_table.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/014_event_updates_for_fp.py:24:8: F401 [*] `datetime` imported but unused
migrations/014_event_updates_for_fp.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/014_event_updates_for_fp.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/014_event_updates_for_fp.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/015_event_refactor.py:24:8: F401 [*] `datetime` imported but unused
migrations/015_event_refactor.py:26:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
migrations/015_event_refactor.py:27:21: F401 [*] `decimal.ROUND_HALF_EVEN` imported but unused
migrations/015_event_refactor.py:31:12: F401 [*] `playhouse.postgres_ext` imported but unused
migrations/015_event_refactor.py:44:14: F405 `JSONField` may be undefined, or defined from star imports: `playhouse.sqlite_ext`
migrations/016_sublabel_increase.py:2:1: F403 `from playhouse.migrate import *` used; unable to detect undefined names
migrations/016_sublabel_increase.py:3:1: F403 `from playhouse.sqlite_ext import *` used; unable to detect undefined names
process_clip.py:2:31: F401 [*] `typing_extensions.runtime` imported but unused
process_clip.py:6:1: E402 Module level import not at top of file
process_clip.py:7:1: E402 Module level import not at top of file
process_clip.py:8:1: E402 Module level import not at top of file
process_clip.py:9:1: E402 Module level import not at top of file
process_clip.py:10:1: E402 Module level import not at top of file
process_clip.py:11:1: E402 Module level import not at top of file
process_clip.py:13:1: E402 Module level import not at top of file
process_clip.py:14:1: E402 Module level import not at top of file
process_clip.py:15:1: E402 Module level import not at top of file
process_clip.py:16:1: E402 Module level import not at top of file
process_clip.py:18:1: E402 Module level import not at top of file
process_clip.py:19:1: E402 Module level import not at top of file
process_clip.py:20:1: E402 Module level import not at top of file
process_clip.py:21:1: E402 Module level import not at top of file
process_clip.py:22:1: E402 Module level import not at top of file
process_clip.py:23:1: E402 Module level import not at top of file
process_clip.py:28:1: E402 Module level import not at top of file
Found 233 errors.
[*] 178 potentially fixable with the --fix option.
isort
diff --git a/benchmark.py b/benchmark.py
index 3d0cacd..cf9c1ab 100755
--- a/benchmark.py
+++ b/benchmark.py
@@ -1,8 +1,10 @@
+import datetime
+import multiprocessing as mp
 import os
 from statistics import mean
-import multiprocessing as mp
+
 import numpy as np
-import datetime
+
 from frigate.config import DetectorTypeEnum
 from frigate.object_detection import (
     LocalObjectDetector,
diff --git a/docker/rootfs/usr/local/go2rtc/create_config.py b/docker/rootfs/usr/local/go2rtc/create_config.py
index d201eb3..c1a84d4 100644
--- a/docker/rootfs/usr/local/go2rtc/create_config.py
+++ b/docker/rootfs/usr/local/go2rtc/create_config.py
@@ -3,6 +3,7 @@
 import json
 import os
 import sys
+
 import yaml

sys.path.insert(0, "/opt/frigate")
diff --git a/frigate/main.py b/frigate/main.py
index b368811..cfc7bd2 100644
--- a/frigate/main.py
+++ b/frigate/main.py
@@ -1,4 +1,5 @@
import faulthandler
+
from flask import cli

faulthandler.enable()
diff --git a/frigate/app.py b/frigate/app.py
index 5e934cc..1fe6de9 100644
--- a/frigate/app.py
+++ b/frigate/app.py
@@ -1,16 +1,16 @@
import logging
import multiprocessing as mp
-from multiprocessing.queues import Queue
-from multiprocessing.synchronize import Event as MpEvent
import os
import shutil
import signal
import sys
-from typing import Optional
+import traceback
+from multiprocessing.queues import Queue
+from multiprocessing.synchronize import Event as MpEvent
from types import FrameType
-import psutil
+from typing import Optional

-import traceback
+import psutil
from peewee_migrate import Router
from playhouse.sqlite_ext import SqliteExtDatabase
from playhouse.sqliteq import SqliteQueueDatabase
@@ -27,13 +27,13 @@ from frigate.const import (
MODEL_CACHE_DIR,
RECORD_DIR,
)
-from frigate.object_detection import ObjectDetectProcess
from frigate.events.cleanup import EventCleanup
from frigate.events.external import ExternalEventProcessor
from frigate.events.maintainer import EventProcessor
from frigate.http import create_app
from frigate.log import log_process, root_configurer
from frigate.models import Event, Recordings, Timeline
+from frigate.object_detection import ObjectDetectProcess
from frigate.object_processing import TrackedObjectProcessor
from frigate.output import output_frames
from frigate.plus import PlusApi
@@ -42,10 +42,10 @@ from frigate.record.record import manage_recordings
from frigate.stats import StatsEmitter, stats_init
from frigate.storage import StorageMaintainer
from frigate.timeline import TimelineProcessor
+from frigate.types import CameraMetricsTypes, RecordMetricsTypes
from frigate.version import VERSION
from frigate.video import capture_camera, track_camera
from frigate.watchdog import FrigateWatchdog
-from frigate.types import CameraMetricsTypes, RecordMetricsTypes

logger = logging.getLogger(name)

diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.py
index d7fd2b4..d6dfeca 100644
--- a/frigate/comms/dispatcher.py
+++ b/frigate/comms/dispatcher.py
@@ -1,17 +1,14 @@
"""Handle communication between Frigate and other applications."""

import logging

-from typing import Any, Callable

from abc import ABC, abstractmethod
+from typing import Any, Callable

from frigate.config import FrigateConfig
-from frigate.ptz import OnvifController, OnvifCommandEnum
+from frigate.ptz import OnvifCommandEnum, OnvifController
from frigate.types import CameraMetricsTypes, RecordMetricsTypes
from frigate.util import restart_frigate

logger = logging.getLogger(name)

diff --git a/frigate/comms/mqtt.py b/frigate/comms/mqtt.py
index 37fdd44..5c58f2f 100644
--- a/frigate/comms/mqtt.py
+++ b/frigate/comms/mqtt.py
@@ -1,6 +1,5 @@
import logging
import threading

from typing import Any, Callable

import paho.mqtt.client as mqtt
@@ -8,7 +7,6 @@ import paho.mqtt.client as mqtt
from frigate.comms.dispatcher import Communicator
from frigate.config import FrigateConfig

logger = logging.getLogger(name)

diff --git a/frigate/comms/ws.py b/frigate/comms/ws.py
index c9cc398..606d705 100644
--- a/frigate/comms/ws.py
+++ b/frigate/comms/ws.py
@@ -3,10 +3,9 @@
import json
import logging
import threading

from typing import Callable

from wsgiref.simple_server import make_server
+
from ws4py.server.wsgirefserver import (
WebSocketWSGIHandler,
WebSocketWSGIRequestHandler,
@@ -18,7 +17,6 @@ from ws4py.websocket import WebSocket
from frigate.comms.dispatcher import Communicator
from frigate.config import FrigateConfig

logger = logging.getLogger(name)

diff --git a/frigate/config.py b/frigate/config.py
index 56e4dc4..ea10d70 100644
--- a/frigate/config.py
+++ b/frigate/config.py
@@ -9,25 +9,17 @@ from typing import Dict, List, Optional, Tuple, Union
import matplotlib.pyplot as plt
import numpy as np
import yaml
-from pydantic import BaseModel, Extra, Field, validator, parse_obj_as
+from pydantic import BaseModel, Extra, Field, parse_obj_as, validator
from pydantic.fields import PrivateAttr

-from frigate.const import (

  • CACHE_DIR,
  • DEFAULT_DB_PATH,
  • REGEX_CAMERA_NAME,
  • YAML_EXT,
    +from frigate.const import CACHE_DIR, DEFAULT_DB_PATH, REGEX_CAMERA_NAME, YAML_EXT
    +from frigate.detectors import (
  • DetectorConfig,
  • InputTensorEnum,
  • ModelConfig,
  • PixelFormatEnum,
    )
    from frigate.detectors.detector_config import BaseDetectorConfig
    -from frigate.plus import PlusApi
    -from frigate.util import (
  • create_mask,
  • deep_merge,
  • get_ffmpeg_arg_list,
  • escape_special_characters,
  • load_config_with_no_duplicates,
  • load_labels,
    -)
    from frigate.ffmpeg_presets import (
    parse_preset_hardware_acceleration_decode,
    parse_preset_hardware_acceleration_scale,
    @@ -35,15 +27,17 @@ from frigate.ffmpeg_presets import (
    parse_preset_output_record,
    parse_preset_output_rtmp,
    )
    -from frigate.detectors import (
  • PixelFormatEnum,
  • InputTensorEnum,
  • ModelConfig,
  • DetectorConfig,
    +from frigate.plus import PlusApi
    +from frigate.util import (
  • create_mask,
  • deep_merge,
  • escape_special_characters,
  • get_ffmpeg_arg_list,
  • load_config_with_no_duplicates,
  • load_labels,
    )
    from frigate.version import VERSION

logger = logging.getLogger(name)

TODO: Identify what the default format to display timestamps is

diff --git a/frigate/detectors/init.py b/frigate/detectors/init.py
index 7cbd82f..a19eed2 100644
--- a/frigate/detectors/init.py
+++ b/frigate/detectors/init.py
@@ -1,13 +1,8 @@
import logging

from .detection_api import DetectionApi
-from .detector_config import (

  • PixelFormatEnum,
  • InputTensorEnum,
  • ModelConfig,
    -)
    -from .detector_types import DetectorTypeEnum, api_types, DetectorConfig

+from .detector_config import InputTensorEnum, ModelConfig, PixelFormatEnum
+from .detector_types import DetectorConfig, DetectorTypeEnum, api_types

logger = logging.getLogger(name)

diff --git a/frigate/detectors/detection_api.py b/frigate/detectors/detection_api.py
index 60a90b1..f829da2 100644
--- a/frigate/detectors/detection_api.py
+++ b/frigate/detectors/detection_api.py
@@ -1,7 +1,6 @@
import logging
from abc import ABC, abstractmethod

logger = logging.getLogger(name)

diff --git a/frigate/detectors/detector_config.py b/frigate/detectors/detector_config.py
index e949065..c192913 100644
--- a/frigate/detectors/detector_config.py
+++ b/frigate/detectors/detector_config.py
@@ -1,20 +1,18 @@
import hashlib
import json
import logging
-from enum import Enum
import os
-from typing import Dict, List, Optional, Tuple, Union, Literal

+from enum import Enum
+from typing import Dict, List, Literal, Optional, Tuple, Union

-import requests
import matplotlib.pyplot as plt
+import requests
from pydantic import BaseModel, Extra, Field, validator
from pydantic.fields import PrivateAttr
-from frigate.plus import PlusApi

+from frigate.plus import PlusApi
from frigate.util import load_labels

logger = logging.getLogger(name)

diff --git a/frigate/detectors/detector_types.py b/frigate/detectors/detector_types.py
index 5c96b2e..418fcd6 100644
--- a/frigate/detectors/detector_types.py
+++ b/frigate/detectors/detector_types.py
@@ -1,16 +1,16 @@
-import logging
import importlib
+import logging
import pkgutil
-from typing import Union
-from typing_extensions import Annotated
from enum import Enum
+from typing import Union
+
from pydantic import Field
+from typing_extensions import Annotated

from . import plugins
from .detection_api import DetectionApi
from .detector_config import BaseDetectorConfig

logger = logging.getLogger(name)

diff --git a/frigate/detectors/plugins/cpu_tfl.py b/frigate/detectors/plugins/cpu_tfl.py
index b22ac9a..2a73434 100644
--- a/frigate/detectors/plugins/cpu_tfl.py
+++ b/frigate/detectors/plugins/cpu_tfl.py
@@ -1,10 +1,11 @@
import logging
+from typing import Literal
+
import numpy as np
+from pydantic import Extra, Field

from frigate.detectors.detection_api import DetectionApi
from frigate.detectors.detector_config import BaseDetectorConfig
-from typing import Literal
-from pydantic import Extra, Field

try:
from tflite_runtime.interpreter import Interpreter
diff --git a/frigate/detectors/plugins/deepstack.py b/frigate/detectors/plugins/deepstack.py
index 9f3d323..1fd61f5 100644
--- a/frigate/detectors/plugins/deepstack.py
+++ b/frigate/detectors/plugins/deepstack.py
@@ -1,14 +1,14 @@
+import io
import logging
+from typing import Literal
+
import numpy as np
import requests
-import io
+from PIL import Image
+from pydantic import Extra, Field

from frigate.detectors.detection_api import DetectionApi
from frigate.detectors.detector_config import BaseDetectorConfig
-from typing import Literal
-from pydantic import Extra, Field
-from PIL import Image

logger = logging.getLogger(name)

diff --git a/frigate/detectors/plugins/edgetpu_tfl.py b/frigate/detectors/plugins/edgetpu_tfl.py
index 6837adc..5980dc4 100644
--- a/frigate/detectors/plugins/edgetpu_tfl.py
+++ b/frigate/detectors/plugins/edgetpu_tfl.py
@@ -1,10 +1,11 @@
import logging
+from typing import Literal
+
import numpy as np
+from pydantic import Extra, Field

from frigate.detectors.detection_api import DetectionApi
from frigate.detectors.detector_config import BaseDetectorConfig
-from typing import Literal
-from pydantic import Extra, Field

try:
from tflite_runtime.interpreter import Interpreter, load_delegate
diff --git a/frigate/detectors/plugins/openvino.py b/frigate/detectors/plugins/openvino.py
index 993b2b8..fe85d60 100644
--- a/frigate/detectors/plugins/openvino.py
+++ b/frigate/detectors/plugins/openvino.py
@@ -1,12 +1,12 @@
import logging
+from typing import Literal
+
import numpy as np
import openvino.runtime as ov
+from pydantic import Extra, Field

from frigate.detectors.detection_api import DetectionApi
from frigate.detectors.detector_config import BaseDetectorConfig, ModelTypeEnum
-from typing import Literal
-from pydantic import Extra, Field

logger = logging.getLogger(name)

diff --git a/frigate/detectors/plugins/tensorrt.py b/frigate/detectors/plugins/tensorrt.py
index 2d2a678..15b58bc 100644
--- a/frigate/detectors/plugins/tensorrt.py
+++ b/frigate/detectors/plugins/tensorrt.py
@@ -1,6 +1,6 @@
+import ctypes
import logging

-import ctypes
import numpy as np

try:
@@ -11,11 +11,13 @@ try:
except ModuleNotFoundError as e:
TRT_SUPPORT = False

-from frigate.detectors.detection_api import DetectionApi
-from frigate.detectors.detector_config import BaseDetectorConfig
from typing import Literal
+
from pydantic import Field

+from frigate.detectors.detection_api import DetectionApi
+from frigate.detectors.detector_config import BaseDetectorConfig
+
logger = logging.getLogger(name)

DETECTOR_KEY = "tensorrt"
diff --git a/frigate/events/cleanup.py b/frigate/events/cleanup.py
index 09b1964..3f1637e 100644
--- a/frigate/events/cleanup.py
+++ b/frigate/events/cleanup.py
@@ -4,7 +4,7 @@ import datetime
import logging
import os
import threading

+from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path

from peewee import fn
@@ -13,8 +13,6 @@ from frigate.config import FrigateConfig
from frigate.const import CLIPS_DIR
from frigate.models import Event

-from multiprocessing.synchronize import Event as MpEvent

logger = logging.getLogger(name)

diff --git a/frigate/events/external.py b/frigate/events/external.py
index ee2906e..6266bd0 100644
--- a/frigate/events/external.py
+++ b/frigate/events/external.py
@@ -1,17 +1,16 @@
"""Handle external events created by the user."""

import base64
-import cv2
import datetime
import glob
import logging
import os
import random
import string

+from multiprocessing.queues import Queue
from typing import Optional

-from multiprocessing.queues import Queue
+import cv2

from frigate.config import CameraConfig, FrigateConfig
from frigate.const import CLIPS_DIR
diff --git a/frigate/events/maintainer.py b/frigate/events/maintainer.py
index 898218e..c871daf 100644
--- a/frigate/events/maintainer.py
+++ b/frigate/events/maintainer.py
@@ -2,8 +2,10 @@ import datetime
import logging
import queue
import threading

from enum import Enum
+from multiprocessing.queues import Queue
+from multiprocessing.synchronize import Event as MpEvent
+from typing import Dict

from peewee import fn

@@ -12,10 +14,6 @@ from frigate.models import Event
from frigate.types import CameraMetricsTypes
from frigate.util import to_relative_box

-from multiprocessing.queues import Queue
-from multiprocessing.synchronize import Event as MpEvent
-from typing import Dict

logger = logging.getLogger(name)

diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py
index 353a8b9..d78cd72 100644
--- a/frigate/ffmpeg_presets.py
+++ b/frigate/ffmpeg_presets.py
@@ -2,13 +2,11 @@

import logging
import os

from typing import Any

-from frigate.version import VERSION
from frigate.const import BTBN_PATH
from frigate.util import vainfo_hwaccel

+from frigate.version import VERSION

logger = logging.getLogger(name)

diff --git a/frigate/http.py b/frigate/http.py
index de9fd03..e8fbf00 100644
--- a/frigate/http.py
+++ b/frigate/http.py
@@ -1,23 +1,20 @@
import base64
-from datetime import datetime, timedelta, timezone
import copy
-import logging
import glob
import json
+import logging
import os
import subprocess as sp
-import pytz
import time
import traceback

+from datetime import datetime, timedelta, timezone
from functools import reduce
from pathlib import Path
-from tzlocal import get_localzone_name
from urllib.parse import unquote

import cv2

import numpy as np
+import pytz
from flask import (
Blueprint,
Flask,
@@ -27,26 +24,26 @@ from flask import (
make_response,
request,
)

-from peewee import SqliteDatabase, operator, fn, DoesNotExist
+from peewee import DoesNotExist, SqliteDatabase, fn, operator
from playhouse.shortcuts import model_to_dict
+from tzlocal import get_localzone_name

from frigate.config import FrigateConfig
from frigate.const import CLIPS_DIR, MAX_SEGMENT_DURATION, RECORD_DIR
-from frigate.models import Event, Recordings, Timeline
from frigate.events.external import ExternalEventProcessor
+from frigate.models import Event, Recordings, Timeline
from frigate.object_processing import TrackedObject
from frigate.plus import PlusApi
from frigate.ptz import OnvifController
from frigate.stats import stats_snapshot
+from frigate.storage import StorageMaintainer
from frigate.util import (
clean_camera_user_pass,
ffprobe_stream,

  • get_tz_modifiers,
    restart_frigate,
    vainfo_hwaccel,
  • get_tz_modifiers,
    )
    -from frigate.storage import StorageMaintainer
    from frigate.version import VERSION

logger = logging.getLogger(name)
diff --git a/frigate/log.py b/frigate/log.py
index 6786694..aea550c 100644
--- a/frigate/log.py
+++ b/frigate/log.py
@@ -1,18 +1,17 @@

adapted from https://medium.com/@jonathonbao/python3-logging-with-multiprocessing-f51f460b8778

import logging
-import threading
+import multiprocessing as mp
import os
-import signal
import queue
-import multiprocessing as mp
-from multiprocessing.queues import Queue
+import signal
+import threading
+from collections import deque
from logging import handlers
-from typing import Optional
+from multiprocessing.queues import Queue
from types import FrameType
-from setproctitle import setproctitle
from typing import Deque, Optional
-from types import FrameType
-from collections import deque
+
+from setproctitle import setproctitle

from frigate.util import clean_camera_user_pass

diff --git a/frigate/models.py b/frigate/models.py
index 0d5f1ab..aae2beb 100644
--- a/frigate/models.py
+++ b/frigate/models.py
@@ -1,12 +1,12 @@
from numpy import unique
from peewee import (

  • Model,
  • BooleanField,
    CharField,
    DateTimeField,
    FloatField,
  • BooleanField,
  • TextField,
    IntegerField,
  • Model,
  • TextField,
    )
    from playhouse.sqlite_ext import JSONField

diff --git a/frigate/motion.py b/frigate/motion.py
index 5580803..19d1629 100644
--- a/frigate/motion.py
+++ b/frigate/motion.py
@@ -1,6 +1,7 @@
import cv2
import imutils
import numpy as np
+
from frigate.config import MotionConfig

diff --git a/frigate/object_detection.py b/frigate/object_detection.py
index 129fd6b..35d4bec 100644
--- a/frigate/object_detection.py
+++ b/frigate/object_detection.py
@@ -12,7 +12,6 @@ from setproctitle import setproctitle

from frigate.config import InputTensorEnum
from frigate.detectors import create_detector

from frigate.util import EventsPerSecond, SharedMemoryFrameManager, listen, load_labels

logger = logging.getLogger(name)
diff --git a/frigate/object_processing.py b/frigate/object_processing.py
index 3088857..9e4397f 100644
--- a/frigate/object_processing.py
+++ b/frigate/object_processing.py
@@ -15,10 +15,10 @@ import numpy as np
from frigate.comms.dispatcher import Dispatcher
from frigate.config import (
CameraConfig,

  • FrigateConfig,
    MqttConfig,
  • SnapshotsConfig,
    RecordConfig,
  • FrigateConfig,
  • SnapshotsConfig,
    )
    from frigate.const import CLIPS_DIR
    from frigate.events.maintainer import EventTypeEnum
    diff --git a/frigate/output.py b/frigate/output.py
    index 79a0818..1cdf991 100644
    --- a/frigate/output.py
    +++ b/frigate/output.py
    @@ -3,8 +3,8 @@ import glob
    import logging
    import math
    import multiprocessing as mp
    -import os
    import operator
    +import os
    import queue
    import signal
    import subprocess as sp
    diff --git a/frigate/plus.py b/frigate/plus.py
    index 7ba67a6..f2b30df 100644
    --- a/frigate/plus.py
    +++ b/frigate/plus.py
    @@ -4,11 +4,13 @@ import logging
    import os
    import re
    from typing import Any, Dict, List
    -import requests
    -from frigate.const import PLUS_ENV_VAR, PLUS_API_HOST
    -from requests.models import Response

import cv2
+import requests
from numpy import ndarray
+from requests.models import Response
+
+from frigate.const import PLUS_API_HOST, PLUS_ENV_VAR

logger = logging.getLogger(name)

diff --git a/frigate/ptz.py b/frigate/ptz.py
index a52006b..44efc83 100644
--- a/frigate/ptz.py
+++ b/frigate/ptz.py
@@ -2,13 +2,12 @@

import logging
import site

from enum import Enum
+
from onvif import ONVIFCamera, ONVIFError

from frigate.config import FrigateConfig

logger = logging.getLogger(name)

diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.py
index 605979e..0396ef8 100644
--- a/frigate/record/cleanup.py
+++ b/frigate/record/cleanup.py
@@ -5,12 +5,12 @@ import itertools
import logging
import os
import threading
+from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path

from peewee import DoesNotExist
-from multiprocessing.synchronize import Event as MpEvent

-from frigate.config import RetainModeEnum, FrigateConfig
+from frigate.config import FrigateConfig, RetainModeEnum
from frigate.const import RECORD_DIR, SECONDS_IN_DAY
from frigate.models import Event, Recordings, Timeline
from frigate.record.util import remove_empty_directories
diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py
index 651bd12..0a19945 100644
--- a/frigate/record/maintainer.py
+++ b/frigate/record/maintainer.py
@@ -9,14 +9,14 @@ import random
import string
import subprocess as sp
import threading
-import psutil

from collections import defaultdict
from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path
from typing import Any, Tuple

-from frigate.config import RetainModeEnum, FrigateConfig
+import psutil
+
+from frigate.config import FrigateConfig, RetainModeEnum
from frigate.const import CACHE_DIR, MAX_SEGMENT_DURATION, RECORD_DIR
from frigate.models import Event, Recordings
from frigate.types import RecordMetricsTypes
diff --git a/frigate/record/record.py b/frigate/record/record.py
index 59fda09..3aaf564 100644
--- a/frigate/record/record.py
+++ b/frigate/record/record.py
@@ -4,12 +4,11 @@ import logging
import multiprocessing as mp
import signal
import threading

-from setproctitle import setproctitle
from types import FrameType
from typing import Optional

from playhouse.sqliteq import SqliteQueueDatabase
+from setproctitle import setproctitle

from frigate.config import FrigateConfig
from frigate.models import Event, Recordings, Timeline
diff --git a/frigate/stats.py b/frigate/stats.py
index 55db809..a9e3d44 100644
--- a/frigate/stats.py
+++ b/frigate/stats.py
@@ -1,23 +1,29 @@
import asyncio
import json
import logging
+import os
+import shutil
import threading
import time
+from multiprocessing.synchronize import Event as MpEvent
+from typing import Any, Optional
+
import psutil
-import shutil
-import os
import requests
-from typing import Optional, Any
-from multiprocessing.synchronize import Event as MpEvent

from frigate.comms.dispatcher import Dispatcher
from frigate.config import FrigateConfig
-from frigate.const import DRIVER_AMD, DRIVER_ENV_VAR, RECORD_DIR, CLIPS_DIR, CACHE_DIR
-from frigate.types import StatsTrackingTypes, CameraMetricsTypes
-from frigate.util import get_amd_gpu_stats, get_intel_gpu_stats, get_nvidia_gpu_stats
-from frigate.version import VERSION
-from frigate.util import get_cpu_stats, get_bandwidth_stats
+from frigate.const import CACHE_DIR, CLIPS_DIR, DRIVER_AMD, DRIVER_ENV_VAR, RECORD_DIR
from frigate.object_detection import ObjectDetectProcess
+from frigate.types import CameraMetricsTypes, StatsTrackingTypes
+from frigate.util import (

  • get_amd_gpu_stats,
  • get_bandwidth_stats,
  • get_cpu_stats,
  • get_intel_gpu_stats,
  • get_nvidia_gpu_stats,
    +)
    +from frigate.version import VERSION

logger = logging.getLogger(name)

diff --git a/frigate/storage.py b/frigate/storage.py
index 5b66abb..7068924 100644
--- a/frigate/storage.py
+++ b/frigate/storage.py
@@ -1,9 +1,9 @@
"""Handle storage retention and usage."""

import logging
-from pathlib import Path
import shutil
import threading
+from pathlib import Path

from peewee import fn

diff --git a/frigate/test/test_config.py b/frigate/test/test_config.py
index 7cd5e22..97ceeb4 100644
--- a/frigate/test/test_config.py
+++ b/frigate/test/test_config.py
@@ -1,13 +1,11 @@
import json
import os
import unittest
+
import numpy as np
from pydantic import ValidationError

-from frigate.config import (

  • BirdseyeModeEnum,
  • FrigateConfig,
    -)
    +from frigate.config import BirdseyeModeEnum, FrigateConfig
    from frigate.const import MODEL_CACHE_DIR
    from frigate.detectors import DetectorTypeEnum
    from frigate.plus import PlusApi
    diff --git a/frigate/test/test_copy_yuv_to_position.py b/frigate/test/test_copy_yuv_to_position.py
    index 16c97b7..33582e2 100644
    --- a/frigate/test/test_copy_yuv_to_position.py
    +++ b/frigate/test/test_copy_yuv_to_position.py
    @@ -1,7 +1,9 @@
    +from unittest import TestCase, main

import cv2
import numpy as np
-from unittest import TestCase, main
-from frigate.util import get_yuv_crop, copy_yuv_to_position
+
+from frigate.util import copy_yuv_to_position, get_yuv_crop

class TestCopyYuvToPosition(TestCase):
diff --git a/frigate/test/test_ffmpeg_presets.py b/frigate/test/test_ffmpeg_presets.py
index 92e0fa3..0d3dab8 100644
--- a/frigate/test/test_ffmpeg_presets.py
+++ b/frigate/test/test_ffmpeg_presets.py
@@ -1,4 +1,5 @@
import unittest
+
from frigate.config import FFMPEG_INPUT_ARGS_DEFAULT, FrigateConfig
from frigate.ffmpeg_presets import parse_preset_input

diff --git a/frigate/test/test_http.py b/frigate/test/test_http.py
index ecb5003..12962f4 100644
--- a/frigate/test/test_http.py
+++ b/frigate/test/test_http.py
@@ -6,15 +6,14 @@ import unittest
from unittest.mock import patch

from peewee_migrate import Router
+from playhouse.shortcuts import model_to_dict
from playhouse.sqlite_ext import SqliteExtDatabase
from playhouse.sqliteq import SqliteQueueDatabase
-from playhouse.shortcuts import model_to_dict

from frigate.config import FrigateConfig
from frigate.http import create_app
from frigate.models import Event, Recordings
from frigate.plus import PlusApi

from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS

diff --git a/frigate/test/test_object_detector.py b/frigate/test/test_object_detector.py
index 9cdeeb6..1e1efa9 100644
--- a/frigate/test/test_object_detector.py
+++ b/frigate/test/test_object_detector.py
@@ -4,10 +4,10 @@ from unittest.mock import Mock, patch
import numpy as np
from pydantic import parse_obj_as

-from frigate.config import DetectorConfig, InputTensorEnum, ModelConfig
-from frigate.detectors import DetectorTypeEnum
import frigate.detectors as detectors
import frigate.object_detection
+from frigate.config import DetectorConfig, InputTensorEnum, ModelConfig
+from frigate.detectors import DetectorTypeEnum

class TestLocalObjectDetector(unittest.TestCase):
diff --git a/frigate/test/test_reduce_boxes.py b/frigate/test/test_reduce_boxes.py
index 69d6f71..5333ffe 100644
--- a/frigate/test/test_reduce_boxes.py
+++ b/frigate/test/test_reduce_boxes.py
@@ -1,5 +1,7 @@
-import numpy as np
from unittest import TestCase, main
+
+import numpy as np
+
from frigate.video import box_overlaps, reduce_boxes

diff --git a/frigate/test/test_storage.py b/frigate/test/test_storage.py
index 22ea6fc..a9c89f2 100644
--- a/frigate/test/test_storage.py
+++ b/frigate/test/test_storage.py
@@ -7,15 +7,14 @@ from unittest.mock import MagicMock, patch

from peewee import DoesNotExist
from peewee_migrate import Router
+from playhouse.shortcuts import model_to_dict
from playhouse.sqlite_ext import SqliteExtDatabase
from playhouse.sqliteq import SqliteQueueDatabase
-from playhouse.shortcuts import model_to_dict

from frigate.config import FrigateConfig
from frigate.http import create_app
from frigate.models import Event, Recordings
from frigate.storage import StorageMaintainer

from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS

diff --git a/frigate/test/test_yuv_region_2_rgb.py b/frigate/test/test_yuv_region_2_rgb.py
index 96f4215..9f1c299 100644
--- a/frigate/test/test_yuv_region_2_rgb.py
+++ b/frigate/test/test_yuv_region_2_rgb.py
@@ -1,6 +1,8 @@
+from unittest import TestCase, main
+
import cv2
import numpy as np
-from unittest import TestCase, main
+
from frigate.util import yuv_region_2_rgb

diff --git a/frigate/timeline.py b/frigate/timeline.py
index e40549d..9ca617b 100644
--- a/frigate/timeline.py
+++ b/frigate/timeline.py
@@ -1,16 +1,14 @@
"""Record events for object, audio, etc. detections."""

import logging
-import threading
import queue
+import threading
+from multiprocessing.queues import Queue
+from multiprocessing.synchronize import Event as MpEvent

from frigate.config import FrigateConfig
from frigate.events.maintainer import EventTypeEnum
from frigate.models import Timeline

-from multiprocessing.queues import Queue
-from multiprocessing.synchronize import Event as MpEvent

from frigate.util import to_relative_box

logger = logging.getLogger(name)
diff --git a/frigate/types.py b/frigate/types.py
index 3cc401e..8c3e546 100644
--- a/frigate/types.py
+++ b/frigate/types.py
@@ -1,7 +1,7 @@
-from typing import Optional, TypedDict
+from multiprocessing.context import Process
from multiprocessing.queues import Queue
from multiprocessing.sharedctypes import Synchronized
-from multiprocessing.context import Process
+from typing import Optional, TypedDict

from frigate.object_detection import ObjectDetectProcess

diff --git a/frigate/util.py b/frigate/util.py
index 47b7b43..2f427e2 100755
--- a/frigate/util.py
+++ b/frigate/util.py
@@ -1,28 +1,26 @@
import copy
import datetime
-import logging
-import shlex
-import subprocess as sp
import json
+import logging
+import os
import re
+import shlex
import signal
+import subprocess as sp
import traceback
import urllib.parse
-import yaml
-import os

from abc import ABC, abstractmethod
from collections import Counter
from collections.abc import Mapping
from multiprocessing import shared_memory
from typing import Any, AnyStr, Optional, Tuple
-import py3nvml.py3nvml as nvml

import cv2
import numpy as np
-import os
import psutil
+import py3nvml.py3nvml as nvml
import pytz
+import yaml

from frigate.const import REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS

diff --git a/frigate/video.py b/frigate/video.py
index a3356a5..97ce8de 100755
--- a/frigate/video.py
+++ b/frigate/video.py
@@ -10,15 +10,15 @@ import threading
import time
from collections import defaultdict

-import numpy as np
import cv2
+import numpy as np
from setproctitle import setproctitle

from frigate.config import CameraConfig, DetectConfig, PixelFormatEnum
from frigate.const import CACHE_DIR
-from frigate.object_detection import RemoteObjectDetector
from frigate.log import LogPipe
from frigate.motion import MotionDetector
+from frigate.object_detection import RemoteObjectDetector
from frigate.objects import ObjectTracker
from frigate.util import (
EventsPerSecond,
@@ -30,8 +30,8 @@ from frigate.util import (
intersection,
intersection_over_union,
listen,

  • yuv_region_2_rgb,
    yuv_region_2_bgr,
  • yuv_region_2_rgb,
    yuv_region_2_yuv,
    )

diff --git a/frigate/watchdog.py b/frigate/watchdog.py
index 5df826f..81e846c 100644
--- a/frigate/watchdog.py
+++ b/frigate/watchdog.py
@@ -1,13 +1,13 @@
import datetime
import logging
-import threading
-import time
import os
import signal
+import threading
+import time
+from multiprocessing.synchronize import Event as MpEvent

from frigate.object_detection import ObjectDetectProcess
from frigate.util import restart_frigate
-from multiprocessing.synchronize import Event as MpEvent

logger = logging.getLogger(name)

diff --git a/migrations/001_create_events_table.py b/migrations/001_create_events_table.py
index d9b0f08..2de1efc 100644
--- a/migrations/001_create_events_table.py
+++ b/migrations/001_create_events_table.py
@@ -22,9 +22,10 @@ Some examples (model - class or model name)::
"""

import datetime as dt
-import peewee as pw
from decimal import ROUND_HALF_EVEN

+import peewee as pw
+
try:
import playhouse.postgres_ext as pw_pext
except ImportError:
diff --git a/migrations/002_add_clip_snapshot.py b/migrations/002_add_clip_snapshot.py
index aaa4a03..aac16f6 100644
--- a/migrations/002_add_clip_snapshot.py
+++ b/migrations/002_add_clip_snapshot.py
@@ -22,8 +22,10 @@ Some examples (model - class or model name)::
"""

import datetime as dt
-import peewee as pw
from decimal import ROUND_HALF_EVEN
+
+import peewee as pw
+
from frigate.models import Event

try:
diff --git a/migrations/004_add_bbox_region_area.py b/migrations/004_add_bbox_region_area.py
index bcc362a..ae77676 100644
--- a/migrations/004_add_bbox_region_area.py
+++ b/migrations/004_add_bbox_region_area.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Event

try:
diff --git a/migrations/005_make_end_time_nullable.py b/migrations/005_make_end_time_nullable.py
index 5c8cf65..b53b2bf 100644
--- a/migrations/005_make_end_time_nullable.py
+++ b/migrations/005_make_end_time_nullable.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Event

try:
diff --git a/migrations/006_add_motion_active_objects.py b/migrations/006_add_motion_active_objects.py
index 6bd564b..e3c56ea 100644
--- a/migrations/006_add_motion_active_objects.py
+++ b/migrations/006_add_motion_active_objects.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Recordings

try:
diff --git a/migrations/007_add_retain_indefinitely.py b/migrations/007_add_retain_indefinitely.py
index a46b72e..6c102dd 100644
--- a/migrations/007_add_retain_indefinitely.py
+++ b/migrations/007_add_retain_indefinitely.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Event

try:
diff --git a/migrations/008_add_sub_label.py b/migrations/008_add_sub_label.py
index 00603c6..06ca9d5 100644
--- a/migrations/008_add_sub_label.py
+++ b/migrations/008_add_sub_label.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Event

try:
diff --git a/migrations/009_add_object_filter_ratio.py b/migrations/009_add_object_filter_ratio.py
index cc23e1d..e5a0068 100644
--- a/migrations/009_add_object_filter_ratio.py
+++ b/migrations/009_add_object_filter_ratio.py
@@ -22,6 +22,7 @@ Some examples (model - class or model name)::
"""

import peewee as pw
+
from frigate.models import Event

SQL = pw.SQL
diff --git a/migrations/010_add_plus_image_id.py b/migrations/010_add_plus_image_id.py
index 0e239e5..1004fce 100644
--- a/migrations/010_add_plus_image_id.py
+++ b/migrations/010_add_plus_image_id.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Event

try:
diff --git a/migrations/012_add_segment_size.py b/migrations/012_add_segment_size.py
index c5ac1ed..6970242 100644
--- a/migrations/012_add_segment_size.py
+++ b/migrations/012_add_segment_size.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Recordings

try:
diff --git a/migrations/013_create_timeline_table.py b/migrations/013_create_timeline_table.py
index fea7867..918a2e2 100644
--- a/migrations/013_create_timeline_table.py
+++ b/migrations/013_create_timeline_table.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Recordings

try:
diff --git a/migrations/014_event_updates_for_fp.py b/migrations/014_event_updates_for_fp.py
index 5d07559..6678405 100644
--- a/migrations/014_event_updates_for_fp.py
+++ b/migrations/014_event_updates_for_fp.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Event

try:
diff --git a/migrations/015_event_refactor.py b/migrations/015_event_refactor.py
index d8a8a38..af6c4dd 100644
--- a/migrations/015_event_refactor.py
+++ b/migrations/015_event_refactor.py
@@ -22,9 +22,11 @@ Some examples (model - class or model name)::
"""

import datetime as dt
+from decimal import ROUND_HALF_EVEN
+
import peewee as pw
from playhouse.sqlite_ext import *
-from decimal import ROUND_HALF_EVEN
+
from frigate.models import Event

try:
diff --git a/migrations/016_sublabel_increase.py b/migrations/016_sublabel_increase.py
index b46b9fc..e6bf5ea 100644
--- a/migrations/016_sublabel_increase.py
+++ b/migrations/016_sublabel_increase.py
@@ -1,6 +1,7 @@
import peewee as pw
from playhouse.migrate import *
from playhouse.sqlite_ext import *
+
from frigate.models import Event

diff --git a/process_clip.py b/process_clip.py
index d8dabbe..c3f9a8b 100644
--- a/process_clip.py
+++ b/process_clip.py
@@ -1,8 +1,10 @@
import sys
+
from typing_extensions import runtime

sys.path.append("/lab/frigate")

+import csv
import json
import logging
import multiprocessing as mp
@@ -11,20 +13,15 @@ import subprocess as sp
import sys

import click
-import csv
import cv2
import numpy as np

from frigate.config import FrigateConfig
-from frigate.object_detection import LocalObjectDetector
from frigate.motion import MotionDetector
+from frigate.object_detection import LocalObjectDetector
from frigate.object_processing import CameraState
from frigate.objects import ObjectTracker
-from frigate.util import (

  • EventsPerSecond,
  • SharedMemoryFrameManager,
  • draw_box_with_label,
    -)
    +from frigate.util import EventsPerSecond, SharedMemoryFrameManager, draw_box_with_label
    from frigate.video import capture_frames, process_frames, start_or_restart_ffmpeg

logging.basicConfig()

@netlify
Copy link

netlify bot commented May 22, 2023

Deploy Preview for frigate-docs canceled.

Name Link
🔨 Latest commit b50868b
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/646d532124512c00089ee9fe

@blakeblackshear
Copy link
Owner

I have been meaning to fix up the linting, but haven't had time yet. We currently use black. I would like to make sure everything works nicely in the vscode devcontainer on save in addition to github actions. If you're willing to help iron all that out, this sounds great to me.

@mweinelt
Copy link
Contributor Author

mweinelt commented May 22, 2023

Not a vscode user, so I can't speak to the devcontainer bits. I'll provide the fixups shortly.

Personally a user of direnv and devenv.

@mweinelt mweinelt force-pushed the isort-ruff branch 2 times, most recently from 6724845 to 8233c7a Compare May 23, 2023 00:39
@mweinelt
Copy link
Contributor Author

mweinelt commented May 23, 2023

These are a bit annoying to resolve.

For example I looked up the openvino documentation, and they say, that they throw an exception, but not which one. I think going with Exception would be an improvement in such a case.

Other try except blocks are 40 lines long and a lot of things could happen in there.

frigate/detectors/plugins/openvino.py:44:13: E722 Do not use bare `except`
frigate/http.py:488:9: E722 Do not use bare `except`
frigate/http.py:617:9: E722 Do not use bare `except`
frigate/http.py:619:5: E722 Do not use bare `except`
frigate/http.py:894:5: E722 Do not use bare `except`
frigate/output.py:151:25: E722 Do not use bare `except`
frigate/record/maintainer.py:66:13: E722 Do not use bare `except`
frigate/stats.py:40:5: E722 Do not use bare `except`
frigate/util.py:841:9: E722 Do not use bare `except`
frigate/util.py:872:13: E722 Do not use bare `except`
frigate/util.py:992:5: E722 Do not use bare `except`

@mweinelt
Copy link
Contributor Author

Stole the isort setup for .devcontainer from https://github.com/AngellusMortis/pyunifiprotect/blob/master/.devcontainer/devcontainer.json, but I have no idea how to actually test it.

pyproject.toml Outdated Show resolved Hide resolved
@mweinelt mweinelt force-pushed the isort-ruff branch 2 times, most recently from fb07fe2 to 3c3099e Compare May 23, 2023 01:49
@mweinelt mweinelt force-pushed the isort-ruff branch 2 times, most recently from a3d6099 to 9472fa6 Compare May 23, 2023 01:57
@mweinelt
Copy link
Contributor Author

mweinelt commented May 23, 2023

Looks like I broke something related to pydantic. I've never used pydantic, so I'm not sure I understand the traceback in its entirety.

The test failures are already on the dev branch apparently. I can reproduce them on 846a180.

The escaped is Did you mean file:***192.168.1.3:554
E.....E...E..EEEE...
======================================================================
ERROR: frigate.detectors (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: frigate.detectors
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/opt/frigate/frigate/detectors/__init__.py", line 3, in <module>
    from .detector_types import DetectorTypeEnum, api_types
  File "/opt/frigate/frigate/detectors/detector_types.py", line 25, in <module>
    plugin_modules.append(importlib.import_module(name))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/frigate/frigate/detectors/plugins/cpu_tfl.py", line 21, in <module>
    class CpuDetectorConfig(BaseDetectorConfig):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/lib/python3.9/typing.py", line 835, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class


======================================================================
ERROR: frigate.test.test_config (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: frigate.test.test_config
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/opt/frigate/frigate/test/test_config.py", line 8, in <module>
    from frigate.config import BirdseyeModeEnum, FrigateConfig
  File "/opt/frigate/frigate/config.py", line 15, in <module>
    from frigate.detectors import DetectorConfig, ModelConfig
  File "/opt/frigate/frigate/detectors/__init__.py", line 3, in <module>
    from .detector_types import DetectorTypeEnum, api_types
  File "/opt/frigate/frigate/detectors/detector_types.py", line 25, in <module>
    plugin_modules.append(importlib.import_module(name))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/frigate/frigate/detectors/plugins/cpu_tfl.py", line 21, in <module>
    class CpuDetectorConfig(BaseDetectorConfig):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/lib/python3.9/typing.py", line 835, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class


======================================================================
ERROR: frigate.test.test_ffmpeg_presets (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: frigate.test.test_ffmpeg_presets
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/opt/frigate/frigate/test/test_ffmpeg_presets.py", line 3, in <module>
    from frigate.config import FFMPEG_INPUT_ARGS_DEFAULT, FrigateConfig
  File "/opt/frigate/frigate/config.py", line 15, in <module>
    from frigate.detectors import DetectorConfig, ModelConfig
  File "/opt/frigate/frigate/detectors/__init__.py", line 3, in <module>
    from .detector_types import DetectorTypeEnum, api_types
  File "/opt/frigate/frigate/detectors/detector_types.py", line 25, in <module>
    plugin_modules.append(importlib.import_module(name))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/frigate/frigate/detectors/plugins/cpu_tfl.py", line 21, in <module>
    class CpuDetectorConfig(BaseDetectorConfig):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/lib/python3.9/typing.py", line 835, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class


======================================================================
ERROR: frigate.test.test_http (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: frigate.test.test_http
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/opt/frigate/frigate/test/test_http.py", line 13, in <module>
    from frigate.config import FrigateConfig
  File "/opt/frigate/frigate/config.py", line 15, in <module>
    from frigate.detectors import DetectorConfig, ModelConfig
  File "/opt/frigate/frigate/detectors/__init__.py", line 3, in <module>
    from .detector_types import DetectorTypeEnum, api_types
  File "/opt/frigate/frigate/detectors/detector_types.py", line 25, in <module>
    plugin_modules.append(importlib.import_module(name))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/frigate/frigate/detectors/plugins/cpu_tfl.py", line 21, in <module>
    class CpuDetectorConfig(BaseDetectorConfig):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/lib/python3.9/typing.py", line 835, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class


======================================================================
ERROR: frigate.test.test_object_detector (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: frigate.test.test_object_detector
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/opt/frigate/frigate/test/test_object_detector.py", line 7, in <module>
    import frigate.detectors as detectors
  File "/opt/frigate/frigate/detectors/__init__.py", line 3, in <module>
    from .detector_types import DetectorTypeEnum, api_types
  File "/opt/frigate/frigate/detectors/detector_types.py", line 25, in <module>
    plugin_modules.append(importlib.import_module(name))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/frigate/frigate/detectors/plugins/cpu_tfl.py", line 21, in <module>
    class CpuDetectorConfig(BaseDetectorConfig):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/lib/python3.9/typing.py", line 835, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class


======================================================================
ERROR: frigate.test.test_reduce_boxes (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: frigate.test.test_reduce_boxes
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/opt/frigate/frigate/test/test_reduce_boxes.py", line 3, in <module>
    from frigate.video import box_overlaps, reduce_boxes
  File "/opt/frigate/frigate/video.py", line 17, in <module>
    from frigate.config import CameraConfig, DetectConfig, PixelFormatEnum
  File "/opt/frigate/frigate/config.py", line 15, in <module>
    from frigate.detectors import DetectorConfig, ModelConfig
  File "/opt/frigate/frigate/detectors/__init__.py", line 3, in <module>
    from .detector_types import DetectorTypeEnum, api_types
  File "/opt/frigate/frigate/detectors/detector_types.py", line 25, in <module>
    plugin_modules.append(importlib.import_module(name))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/frigate/frigate/detectors/plugins/cpu_tfl.py", line 21, in <module>
    class CpuDetectorConfig(BaseDetectorConfig):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/lib/python3.9/typing.py", line 835, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class


======================================================================
ERROR: frigate.test.test_storage (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: frigate.test.test_storage
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/opt/frigate/frigate/test/test_storage.py", line 12, in <module>
    from frigate.config import FrigateConfig
  File "/opt/frigate/frigate/config.py", line 15, in <module>
    from frigate.detectors import DetectorConfig, ModelConfig
  File "/opt/frigate/frigate/detectors/__init__.py", line 3, in <module>
    from .detector_types import DetectorTypeEnum, api_types
  File "/opt/frigate/frigate/detectors/detector_types.py", line 25, in <module>
    plugin_modules.append(importlib.import_module(name))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/frigate/frigate/detectors/plugins/cpu_tfl.py", line 21, in <module>
    class CpuDetectorConfig(BaseDetectorConfig):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/lib/python3.9/typing.py", line 835, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class


----------------------------------------------------------------------
Ran 20 tests in 0.053s

FAILED (errors=7)

@mweinelt
Copy link
Contributor Author

mweinelt commented May 23, 2023

Looks like pydantic/pydantic#5821, but downgrading to typing-extensions<4.6.0 didn't make them go away for me.

@NickM-27
Copy link
Collaborator

I don't see why this just started happening though, their last release was March 22

@NickM-27
Copy link
Collaborator

If you rebase on latest dev it's fixed

@mweinelt mweinelt force-pushed the isort-ruff branch 2 times, most recently from d21330e to a3e85b1 Compare May 23, 2023 15:07
@mweinelt
Copy link
Contributor Author

mweinelt commented May 23, 2023

Rebased. The following issue will remain until #6579 is on dev and I rebase another time.

frigate/detectors/plugins/deepstack.py:51:9: F841 [*] Local variable data is assigned to but never used

Should be good to go otherwise.

@mweinelt
Copy link
Contributor Author

mweinelt commented May 23, 2023

I don't see why this just started happening though, their last release was March 22

This is about the typing-extensions 4.6.0 bump, not a pydantic update.

@mweinelt
Copy link
Contributor Author

The tests on dev are failing for me with the same error.

======================================================================
ERROR: test_detector_custom_model_path (frigate.test.test_config.TestConfig)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/frigate/frigate/test/test_config.py", line 93, in test_detector_custom_model_path
    runtime_config = frigate_config.runtime_config()
  File "/opt/frigate/frigate/config.py", line 1030, in runtime_config
    detector_config: DetectorConfig = parse_obj_as(DetectorConfig, detector)
  File "pydantic/tools.py", line 38, in pydantic.tools.parse_obj_as
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for ParsingModel[Annotated[Union[frigate.detectors.plugins.cpu_tfl.CpuDetectorConfig, frigate.detectors.plugins.deepstack.DeepstackDetectorConfig, frigate.detectors.plugins.edgetpu_tfl.EdgeTpuDetectorConfig, frigate.detectors.plugins.tensorrt.TensorRTDetectorConfig], FieldInfo(default=PydanticUndefined, discriminator='type', extra={})]]
__root__
  No match for discriminator 'type' and value 'openvino' (allowed values: 'cpu', 'deepstack', 'edgetpu', 'tensorrt') (type=value_error.discriminated_union.invalid_discriminator; discriminator_key=type; discriminator_value=openvino; allowed_values='cpu', 'deepstack', 'edgetpu', 'tensorrt')

----------------------------------------------------------------------

@NickM-27
Copy link
Collaborator

Looks like a different error to me? also, my commit this morning fixed the tests and confirmed with new test run

@mweinelt
Copy link
Contributor Author

mweinelt commented May 23, 2023

Yeah, but running the tests against dev again shows they are failing now. This is a different error of course.

I run the tests like so:

make
docker run --rm --entrypoint=python3 frigate:latest -u -m unittest

@mweinelt
Copy link
Contributor Author

And now it succeeded again. Possibly flaky.

mweinelt added 6 commits May 24, 2023 01:38
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.
This is necessary for escape sequences to be properly recognized.
@blakeblackshear
Copy link
Owner

Is there a reason to have both ruff and black here? There is a vscode extension for ruff as well.

@mweinelt
Copy link
Contributor Author

mweinelt commented May 27, 2023

Ruff is only a generic linter, it finds all sorts of quirks like that not foo in bar should be foo not in bar, while black takes care of (re)formatting the code, but would not reformat such a case IME.

Again, not a vscode user, so my exposure to its extensions is very limited. Feel free to update the devcontainer accordingly.

@blakeblackshear blakeblackshear merged commit ab50d0b into blakeblackshear:dev May 29, 2023
@mweinelt mweinelt deleted the isort-ruff branch May 29, 2023 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants