diff --git a/benchmark.py b/benchmark.py index ea388ef13a..8ba22d0932 100755 --- a/benchmark.py +++ b/benchmark.py @@ -1,11 +1,11 @@ -import os -from statistics import mean +import datetime import multiprocessing as mp +from statistics import mean + import numpy as np -import datetime + from frigate.config import DetectorTypeEnum from frigate.object_detection import ( - LocalObjectDetector, ObjectDetectProcess, RemoteObjectDetector, load_labels, diff --git a/docker/rootfs/usr/local/go2rtc/create_config.py b/docker/rootfs/usr/local/go2rtc/create_config.py index d201eb3819..1397adee8e 100644 --- a/docker/rootfs/usr/local/go2rtc/create_config.py +++ b/docker/rootfs/usr/local/go2rtc/create_config.py @@ -3,11 +3,14 @@ import json import os import sys + import yaml sys.path.insert(0, "/opt/frigate") -from frigate.const import BIRDSEYE_PIPE, BTBN_PATH -from frigate.ffmpeg_presets import parse_preset_hardware_acceleration_encode +from frigate.const import BIRDSEYE_PIPE, BTBN_PATH # noqa: E402 +from frigate.ffmpeg_presets import ( # noqa: E402 + parse_preset_hardware_acceleration_encode, +) sys.path.remove("/opt/frigate") diff --git a/frigate/__main__.py b/frigate/__main__.py index 8fa98fe530..8442069082 100644 --- a/frigate/__main__.py +++ b/frigate/__main__.py @@ -5,7 +5,6 @@ from frigate.app import FrigateApp - faulthandler.enable() threading.current_thread().name = "frigate" diff --git a/frigate/app.py b/frigate/app.py index c66fab187e..bcbd3ed2d0 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 @@ 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.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 61e1c75221..b7e9e88586 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 0e8fb4d711..07799f9dab 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 @@ 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 d036da8e70..3c1d2eb12b 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 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 f9203582b5..5c2f27b5aa 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -8,24 +8,14 @@ import matplotlib.pyplot as plt import numpy as np -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, ModelConfig +from frigate.detectors.detector_config import InputTensorEnum # noqa: F401 +from frigate.detectors.detector_config import PixelFormatEnum # noqa: F401 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, -) from frigate.ffmpeg_presets import ( parse_preset_hardware_acceleration_decode, parse_preset_hardware_acceleration_scale, @@ -33,12 +23,15 @@ parse_preset_output_record, parse_preset_output_rtmp, ) -from frigate.detectors import ( - 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, ) - 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 c04891f50a..7465ed7c0c 100644 --- a/frigate/detectors/__init__.py +++ b/frigate/detectors/__init__.py @@ -1,7 +1,7 @@ import logging -from .detector_types import DetectorTypeEnum, api_types, DetectorConfig - +from .detector_config import InputTensorEnum, ModelConfig, PixelFormatEnum # noqa: F401 +from .detector_types import DetectorConfig, DetectorTypeEnum, api_types # noqa: F401 logger = logging.getLogger(__name__) diff --git a/frigate/detectors/detection_api.py b/frigate/detectors/detection_api.py index 60a90b1b5a..f829da27a5 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 ce11adb2f7..f65826a572 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 enum import Enum from typing import Dict, Optional, Tuple - -import requests import matplotlib.pyplot as plt +import requests from pydantic import BaseModel, Extra, Field 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 5c96b2e16b..418fcd625c 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 6439a9c3db..8a54363e1a 100644 --- a/frigate/detectors/plugins/cpu_tfl.py +++ b/frigate/detectors/plugins/cpu_tfl.py @@ -1,12 +1,12 @@ import logging + import numpy as np +from pydantic import Field +from typing_extensions import Literal from frigate.detectors.detection_api import DetectionApi from frigate.detectors.detector_config import BaseDetectorConfig -from typing_extensions import Literal -from pydantic import Field - try: from tflite_runtime.interpreter import Interpreter except ModuleNotFoundError: diff --git a/frigate/detectors/plugins/deepstack.py b/frigate/detectors/plugins/deepstack.py index 6ef702cb1b..fd79e27d0c 100644 --- a/frigate/detectors/plugins/deepstack.py +++ b/frigate/detectors/plugins/deepstack.py @@ -1,14 +1,14 @@ +import io import logging + import numpy as np import requests -import io +from PIL import Image +from pydantic import Field +from typing_extensions import Literal from frigate.detectors.detection_api import DetectionApi from frigate.detectors.detector_config import BaseDetectorConfig -from typing_extensions import Literal -from pydantic import 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 7e35877c4e..ca03d483b1 100644 --- a/frigate/detectors/plugins/edgetpu_tfl.py +++ b/frigate/detectors/plugins/edgetpu_tfl.py @@ -1,10 +1,11 @@ import logging + import numpy as np +from pydantic import Field +from typing_extensions import Literal from frigate.detectors.detection_api import DetectionApi from frigate.detectors.detector_config import BaseDetectorConfig -from typing_extensions import Literal -from pydantic import 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 3592cb7db8..5cb1ea39c3 100644 --- a/frigate/detectors/plugins/openvino.py +++ b/frigate/detectors/plugins/openvino.py @@ -1,12 +1,12 @@ import logging + import numpy as np import openvino.runtime as ov +from pydantic import Field +from typing_extensions import Literal from frigate.detectors.detection_api import DetectionApi from frigate.detectors.detector_config import BaseDetectorConfig, ModelTypeEnum -from typing_extensions import Literal -from pydantic import Field - logger = logging.getLogger(__name__) diff --git a/frigate/detectors/plugins/tensorrt.py b/frigate/detectors/plugins/tensorrt.py index 26fa92ccb7..7251b8751e 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,10 +11,11 @@ except ModuleNotFoundError: TRT_SUPPORT = False +from pydantic import Field +from typing_extensions import Literal + from frigate.detectors.detection_api import DetectionApi from frigate.detectors.detector_config import BaseDetectorConfig -from typing_extensions import Literal -from pydantic import Field logger = logging.getLogger(__name__) diff --git a/frigate/events/cleanup.py b/frigate/events/cleanup.py index a78794a830..5afd285c49 100644 --- a/frigate/events/cleanup.py +++ b/frigate/events/cleanup.py @@ -4,16 +4,13 @@ import logging import os import threading - +from multiprocessing.synchronize import Event as MpEvent from pathlib import Path - 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 2c17c9a032..5422de2608 100644 --- a/frigate/events/external.py +++ b/frigate/events/external.py @@ -1,16 +1,15 @@ """Handle external events created by the user.""" import base64 -import cv2 import datetime 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 f674c5ccfa..5459fea6c3 100644 --- a/frigate/events/maintainer.py +++ b/frigate/events/maintainer.py @@ -2,19 +2,16 @@ 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 frigate.config import EventsConfig, FrigateConfig 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 353a8b9229..d78cd72ef1 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 dd3ddfd76f..9d7aa2c47f 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 @@ 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 f835b59002..4a44545adf 100644 --- a/frigate/log.py +++ b/frigate/log.py @@ -1,17 +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 typing import Deque, Optional + from setproctitle import setproctitle -from typing import Deque -from collections import deque from frigate.util import clean_camera_user_pass diff --git a/frigate/models.py b/frigate/models.py index 6a81eeda4d..5f6ac7339c 100644 --- a/frigate/models.py +++ b/frigate/models.py @@ -1,11 +1,11 @@ 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 5580803a38..19d1629561 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 de9494fb15..9201dfcd19 100644 --- a/frigate/object_detection.py +++ b/frigate/object_detection.py @@ -12,7 +12,6 @@ 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 09181c26fd..8c16ef64ed 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -15,10 +15,10 @@ 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/plus.py b/frigate/plus.py index 8638989176..b219e02a2d 100644 --- a/frigate/plus.py +++ b/frigate/plus.py @@ -4,11 +4,13 @@ import os import re from typing import Any, 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 3d02b8a9ea..385a230bc9 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 f1f01486cf..bb54d8b866 100644 --- a/frigate/record/cleanup.py +++ b/frigate/record/cleanup.py @@ -5,12 +5,12 @@ 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 522da48d81..afcd6af28d 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -9,14 +9,14 @@ 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 59fda095b2..3aaf56476a 100644 --- a/frigate/record/record.py +++ b/frigate/record/record.py @@ -4,12 +4,11 @@ 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 3359a76027..3fd8810290 100644 --- a/frigate/stats.py +++ b/frigate/stats.py @@ -1,24 +1,30 @@ 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 requests.exceptions import RequestException 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 c22a6363f9..6cdd54bdcb 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 51109b35ce..8c1b5b5865 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 16c97b79d7..33582e2d1e 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 92e0fa3bd9..0d3dab8569 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 1eb0de1978..3557eccd3a 100644 --- a/frigate/test/test_http.py +++ b/frigate/test/test_http.py @@ -6,15 +6,14 @@ 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 9cdeeb6c78..1e1efa9576 100644 --- a/frigate/test/test_object_detector.py +++ b/frigate/test/test_object_detector.py @@ -4,10 +4,10 @@ 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 1b961a3d4d..d26fcd40c9 100644 --- a/frigate/test/test_reduce_boxes.py +++ b/frigate/test/test_reduce_boxes.py @@ -1,4 +1,5 @@ from unittest import TestCase, main + from frigate.video import box_overlaps, reduce_boxes diff --git a/frigate/test/test_storage.py b/frigate/test/test_storage.py index a17e067d41..468d319169 100644 --- a/frigate/test/test_storage.py +++ b/frigate/test/test_storage.py @@ -12,7 +12,6 @@ from frigate.config import FrigateConfig 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 6681b56362..a56a78b1cc 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 e40549d08e..9ca617ba91 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 3cc401ebba..8c3e546541 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 2f93fefa05..056c5eb1b2 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -1,27 +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 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 263d8f893f..f7ec08e995 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -10,15 +10,15 @@ 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 @@ 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 94612e4faf..d1573f0b00 100644 --- a/frigate/watchdog.py +++ b/frigate/watchdog.py @@ -2,10 +2,10 @@ import logging 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 d9b0f08530..9e8ad1b607 100644 --- a/migrations/001_create_events_table.py +++ b/migrations/001_create_events_table.py @@ -21,14 +21,7 @@ """ -import datetime as dt import peewee as pw -from decimal import ROUND_HALF_EVEN - -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass SQL = pw.SQL diff --git a/migrations/002_add_clip_snapshot.py b/migrations/002_add_clip_snapshot.py index aaa4a03c98..1431c9c85f 100644 --- a/migrations/002_add_clip_snapshot.py +++ b/migrations/002_add_clip_snapshot.py @@ -21,15 +21,9 @@ """ -import datetime as dt import peewee as pw -from decimal import ROUND_HALF_EVEN -from frigate.models import Event -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/003_create_recordings_table.py b/migrations/003_create_recordings_table.py index e13ae657e4..82b15eb9cd 100644 --- a/migrations/003_create_recordings_table.py +++ b/migrations/003_create_recordings_table.py @@ -22,8 +22,6 @@ """ import peewee as pw -from frigate.models import Recordings - SQL = pw.SQL diff --git a/migrations/004_add_bbox_region_area.py b/migrations/004_add_bbox_region_area.py index bcc362aac2..da4ca7ac81 100644 --- a/migrations/004_add_bbox_region_area.py +++ b/migrations/004_add_bbox_region_area.py @@ -21,16 +21,10 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Event +from playhouse.sqlite_ext import JSONField -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/005_make_end_time_nullable.py b/migrations/005_make_end_time_nullable.py index 5c8cf65054..87d0e3fd45 100644 --- a/migrations/005_make_end_time_nullable.py +++ b/migrations/005_make_end_time_nullable.py @@ -21,16 +21,9 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Event -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/006_add_motion_active_objects.py b/migrations/006_add_motion_active_objects.py index 6bd564b8c9..2980b441db 100644 --- a/migrations/006_add_motion_active_objects.py +++ b/migrations/006_add_motion_active_objects.py @@ -21,16 +21,9 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Recordings -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Recordings SQL = pw.SQL diff --git a/migrations/007_add_retain_indefinitely.py b/migrations/007_add_retain_indefinitely.py index a46b72e291..cb5f9da920 100644 --- a/migrations/007_add_retain_indefinitely.py +++ b/migrations/007_add_retain_indefinitely.py @@ -21,16 +21,9 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Event -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/008_add_sub_label.py b/migrations/008_add_sub_label.py index 00603c63e1..56c4bb75ad 100644 --- a/migrations/008_add_sub_label.py +++ b/migrations/008_add_sub_label.py @@ -21,16 +21,9 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Event -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/009_add_object_filter_ratio.py b/migrations/009_add_object_filter_ratio.py index cc23e1d86b..e5a00683de 100644 --- a/migrations/009_add_object_filter_ratio.py +++ b/migrations/009_add_object_filter_ratio.py @@ -22,6 +22,7 @@ """ 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 0e239e58b9..6b8c7ccc61 100644 --- a/migrations/010_add_plus_image_id.py +++ b/migrations/010_add_plus_image_id.py @@ -21,16 +21,9 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Event -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/012_add_segment_size.py b/migrations/012_add_segment_size.py index c5ac1ed93c..7a1c797362 100644 --- a/migrations/012_add_segment_size.py +++ b/migrations/012_add_segment_size.py @@ -21,16 +21,9 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Recordings -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Recordings SQL = pw.SQL diff --git a/migrations/013_create_timeline_table.py b/migrations/013_create_timeline_table.py index fea7867afe..b96822df16 100644 --- a/migrations/013_create_timeline_table.py +++ b/migrations/013_create_timeline_table.py @@ -21,16 +21,7 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Recordings - -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass SQL = pw.SQL diff --git a/migrations/014_event_updates_for_fp.py b/migrations/014_event_updates_for_fp.py index 5d075596b4..caa609bfaf 100644 --- a/migrations/014_event_updates_for_fp.py +++ b/migrations/014_event_updates_for_fp.py @@ -21,16 +21,9 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Event -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/015_event_refactor.py b/migrations/015_event_refactor.py index d8a8a387c0..1bcb9c510e 100644 --- a/migrations/015_event_refactor.py +++ b/migrations/015_event_refactor.py @@ -21,16 +21,10 @@ """ -import datetime as dt import peewee as pw -from playhouse.sqlite_ext import * -from decimal import ROUND_HALF_EVEN -from frigate.models import Event +from playhouse.sqlite_ext import JSONField -try: - import playhouse.postgres_ext as pw_pext -except ImportError: - pass +from frigate.models import Event SQL = pw.SQL diff --git a/migrations/016_sublabel_increase.py b/migrations/016_sublabel_increase.py index b46b9fc79b..536ea0a610 100644 --- a/migrations/016_sublabel_increase.py +++ b/migrations/016_sublabel_increase.py @@ -1,6 +1,5 @@ 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 d8dabbeddd..e122ebf369 100644 --- a/process_clip.py +++ b/process_clip.py @@ -1,8 +1,4 @@ -import sys -from typing_extensions import runtime - -sys.path.append("/lab/frigate") - +import csv import json import logging import multiprocessing as mp @@ -11,21 +7,26 @@ 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_processing import CameraState -from frigate.objects import ObjectTracker -from frigate.util import ( +sys.path.append("/lab/frigate") + +from frigate.config import FrigateConfig # noqa: E402 +from frigate.motion import MotionDetector # noqa: E402 +from frigate.object_detection import LocalObjectDetector # noqa: E402 +from frigate.object_processing import CameraState # noqa: E402 +from frigate.objects import ObjectTracker # noqa: E402 +from frigate.util import ( # noqa: E402 EventsPerSecond, SharedMemoryFrameManager, draw_box_with_label, ) -from frigate.video import capture_frames, process_frames, start_or_restart_ffmpeg +from frigate.video import ( # noqa: E402 + capture_frames, + process_frames, + start_or_restart_ffmpeg, +) logging.basicConfig() logging.root.setLevel(logging.DEBUG)