forked from Github/frigate
Add isort and ruff linter (#6575)
* Add isort and ruff linter Both linters are pretty common among modern python code bases. The isort tool provides stable sorting and grouping, as well as pruning of unused imports. Ruff is a modern linter, that is very fast due to being written in rust. It can detect many common issues in a python codebase. Removes the pylint dev requirement, since ruff replaces it. * treewide: fix issues detected by ruff * treewide: fix bare except clauses * .devcontainer: Set up isort * treewide: optimize imports * treewide: apply black * treewide: make regex patterns raw strings This is necessary for escape sequences to be properly recognized.
This commit is contained in:
@@ -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
|
||||
@@ -675,7 +673,7 @@ class TestConfig(unittest.TestCase):
|
||||
runtime_config = frigate_config.runtime_config()
|
||||
ffmpeg_cmds = runtime_config.cameras["back"].ffmpeg_cmds
|
||||
assert len(ffmpeg_cmds) == 1
|
||||
assert not "clips" in ffmpeg_cmds[0]["roles"]
|
||||
assert "clips" not in ffmpeg_cmds[0]["roles"]
|
||||
|
||||
def test_max_disappeared_default(self):
|
||||
config = {
|
||||
@@ -986,7 +984,7 @@ class TestConfig(unittest.TestCase):
|
||||
}
|
||||
|
||||
frigate_config = FrigateConfig(**config)
|
||||
runtime_config = frigate_config.runtime_config()
|
||||
frigate_config.runtime_config()
|
||||
|
||||
def test_global_detect(self):
|
||||
config = {
|
||||
@@ -1145,7 +1143,7 @@ class TestConfig(unittest.TestCase):
|
||||
assert config == frigate_config.dict(exclude_unset=True)
|
||||
|
||||
runtime_config = frigate_config.runtime_config()
|
||||
assert runtime_config.cameras["back"].snapshots.bounding_box == False
|
||||
assert runtime_config.cameras["back"].snapshots.bounding_box is False
|
||||
assert runtime_config.cameras["back"].snapshots.height == 150
|
||||
assert runtime_config.cameras["back"].snapshots.enabled
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import unittest
|
||||
|
||||
from frigate.config import FFMPEG_INPUT_ARGS_DEFAULT, FrigateConfig
|
||||
from frigate.ffmpeg_presets import parse_preset_input
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from frigate.util import get_amd_gpu_stats, get_intel_gpu_stats, get_nvidia_gpu_stats
|
||||
from frigate.util import get_amd_gpu_stats, get_intel_gpu_stats
|
||||
|
||||
|
||||
class TestGpuStats(unittest.TestCase):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -128,22 +127,22 @@ class TestHttp(unittest.TestCase):
|
||||
|
||||
with app.test_client() as client:
|
||||
_insert_mock_event(id)
|
||||
events = client.get(f"/events").json
|
||||
events = client.get("/events").json
|
||||
assert events
|
||||
assert len(events) == 1
|
||||
assert events[0]["id"] == id
|
||||
_insert_mock_event(id2)
|
||||
events = client.get(f"/events").json
|
||||
events = client.get("/events").json
|
||||
assert events
|
||||
assert len(events) == 2
|
||||
events = client.get(
|
||||
f"/events",
|
||||
"/events",
|
||||
query_string={"limit": 1},
|
||||
).json
|
||||
assert events
|
||||
assert len(events) == 1
|
||||
events = client.get(
|
||||
f"/events",
|
||||
"/events",
|
||||
query_string={"has_clip": 0},
|
||||
).json
|
||||
assert not events
|
||||
@@ -230,12 +229,12 @@ class TestHttp(unittest.TestCase):
|
||||
event = client.get(f"/events/{id}").json
|
||||
assert event
|
||||
assert event["id"] == id
|
||||
assert event["retain_indefinitely"] == True
|
||||
assert event["retain_indefinitely"] is True
|
||||
client.delete(f"/events/{id}/retain")
|
||||
event = client.get(f"/events/{id}").json
|
||||
assert event
|
||||
assert event["id"] == id
|
||||
assert event["retain_indefinitely"] == False
|
||||
assert event["retain_indefinitely"] is False
|
||||
|
||||
def test_set_delete_sub_label(self):
|
||||
app = create_app(
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import numpy as np
|
||||
from unittest import TestCase, main
|
||||
|
||||
from frigate.video import box_overlaps, reduce_boxes
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from peewee import DoesNotExist
|
||||
from peewee_migrate import Router
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -33,7 +35,7 @@ class TestYuvRegion2RGB(TestCase):
|
||||
# cv2.imwrite(f"bgr_frame.jpg", self.bgr_frame)
|
||||
yuv_frame = cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2YUV_I420)
|
||||
|
||||
cropped = yuv_region_2_rgb(yuv_frame, (0, 852, 648, 1500))
|
||||
yuv_region_2_rgb(yuv_frame, (0, 852, 648, 1500))
|
||||
# cv2.imwrite(f"cropped.jpg", cv2.cvtColor(cropped, cv2.COLOR_RGB2BGR))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user