Skip to content

Commit

Permalink
treewide: optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mweinelt committed May 23, 2023
1 parent bea7c82 commit 3fc4e7b
Show file tree
Hide file tree
Showing 63 changed files with 171 additions and 275 deletions.
8 changes: 4 additions & 4 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
7 changes: 5 additions & 2 deletions docker/rootfs/usr/local/go2rtc/create_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 0 additions & 1 deletion frigate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from frigate.app import FrigateApp


faulthandler.enable()

threading.current_thread().name = "frigate"
Expand Down
14 changes: 7 additions & 7 deletions frigate/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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__)

Expand Down
7 changes: 2 additions & 5 deletions frigate/comms/dispatcher.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down
2 changes: 0 additions & 2 deletions frigate/comms/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import logging
import threading

from typing import Any, Callable

import paho.mqtt.client as mqtt

from frigate.comms.dispatcher import Communicator
from frigate.config import FrigateConfig


logger = logging.getLogger(__name__)


Expand Down
4 changes: 1 addition & 3 deletions frigate/comms/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,7 +17,6 @@
from frigate.comms.dispatcher import Communicator
from frigate.config import FrigateConfig


logger = logging.getLogger(__name__)


Expand Down
31 changes: 12 additions & 19 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,30 @@

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,
parse_preset_input,
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
Expand Down
4 changes: 2 additions & 2 deletions frigate/detectors/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
1 change: 0 additions & 1 deletion frigate/detectors/detection_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from abc import ABC, abstractmethod


logger = logging.getLogger(__name__)


Expand Down
8 changes: 3 additions & 5 deletions frigate/detectors/detector_config.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down
8 changes: 4 additions & 4 deletions frigate/detectors/detector_types.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down
6 changes: 3 additions & 3 deletions frigate/detectors/plugins/cpu_tfl.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
10 changes: 5 additions & 5 deletions frigate/detectors/plugins/deepstack.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
5 changes: 3 additions & 2 deletions frigate/detectors/plugins/edgetpu_tfl.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions frigate/detectors/plugins/openvino.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
7 changes: 4 additions & 3 deletions frigate/detectors/plugins/tensorrt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ctypes
import logging

import ctypes
import numpy as np

try:
Expand All @@ -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__)

Expand Down
5 changes: 1 addition & 4 deletions frigate/events/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down
5 changes: 2 additions & 3 deletions frigate/events/external.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit 3fc4e7b

Please sign in to comment.