From a39c1f79a4d1f637f978cc06c45ad3b8fb7f858c Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Thu, 16 Nov 2023 06:08:44 -0600 Subject: [PATCH] go all in on ruff --- .devcontainer/devcontainer.json | 6 +----- .github/workflows/pull_request.yml | 9 +++------ docker-compose.yml | 15 ++++++++------- docker/main/requirements-dev.txt | 2 -- frigate/record/maintainer.py | 8 ++------ frigate/util/image.py | 14 ++++---------- pyproject.toml | 6 ++---- 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7769737a7..0c460cfad 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -42,7 +42,6 @@ "extensions": [ "ms-python.python", "ms-python.vscode-pylance", - "ms-python.black-formatter", "visualstudioexptteam.vscodeintellicode", "mhutchie.git-graph", "ms-azuretools.vscode-docker", @@ -53,13 +52,10 @@ "csstools.postcss", "blanu.vscode-styled-jsx", "bradlc.vscode-tailwindcss", - "ms-python.isort", "charliermarsh.ruff" ], "settings": { "remote.autoForwardPorts": false, - "python.linting.pylintEnabled": true, - "python.linting.enabled": true, "python.formatting.provider": "none", "python.languageServer": "Pylance", "editor.formatOnPaste": false, @@ -72,7 +68,7 @@ "eslint.workingDirectories": ["./web"], "isort.args": ["--settings-path=./pyproject.toml"], "[python]": { - "editor.defaultFormatter": "ms-python.black-formatter", + "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll": true, diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 10ba723eb..4b2d5fb4c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -72,13 +72,10 @@ jobs: run: | python3 -m pip install -U pip python3 -m pip install -r docker/main/requirements-dev.txt - - name: Check black + - name: Check formatting run: | - black --check --diff frigate migrations docker *.py - - name: Check isort - run: | - isort --check --diff frigate migrations docker *.py - - name: Check ruff + ruff format --check --diff frigate migrations docker *.py + - name: Check lint run: | ruff check frigate migrations docker *.py diff --git a/docker-compose.yml b/docker-compose.yml index be04ad0a3..a4d349194 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,13 +14,14 @@ services: dockerfile: docker/main/Dockerfile # Use target devcontainer-trt for TensorRT dev target: devcontainer - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: 1 - capabilities: [gpu] + ## Uncomment this block for nvidia gpu support + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: 1 + # capabilities: [gpu] environment: YOLO_MODELS: yolov7-320 devices: diff --git a/docker/main/requirements-dev.txt b/docker/main/requirements-dev.txt index 9a68e601d..af3ee5763 100644 --- a/docker/main/requirements-dev.txt +++ b/docker/main/requirements-dev.txt @@ -1,3 +1 @@ -black == 23.10.* -isort ruff diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index 449824b1b..4fdca7c83 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -225,12 +225,8 @@ class RecordingMaintainer(threading.Thread): # if cached file's start_time is earlier than the retain days for the camera if start_time <= ( - ( - datetime.datetime.now().astimezone(datetime.timezone.utc) - - datetime.timedelta( - days=self.config.cameras[camera].record.retain.days - ) - ) + datetime.datetime.now().astimezone(datetime.timezone.utc) + - datetime.timedelta(days=self.config.cameras[camera].record.retain.days) ): # if the cached segment overlaps with the events: overlaps = False diff --git a/frigate/util/image.py b/frigate/util/image.py index d5eaaf885..c2cd9e5b9 100644 --- a/frigate/util/image.py +++ b/frigate/util/image.py @@ -287,17 +287,14 @@ def yuv_crop_and_resize(frame, region, height=None): # copy u2 yuv_cropped_frame[ size + uv_channel_y_offset : size + uv_channel_y_offset + uv_crop_height, - size // 2 - + uv_channel_x_offset : size // 2 + size // 2 + uv_channel_x_offset : size // 2 + uv_channel_x_offset + uv_crop_width, ] = frame[u2[1] : u2[3], u2[0] : u2[2]] # copy v1 yuv_cropped_frame[ - size - + size // 4 - + uv_channel_y_offset : size + size + size // 4 + uv_channel_y_offset : size + size // 4 + uv_channel_y_offset + uv_crop_height, @@ -306,14 +303,11 @@ def yuv_crop_and_resize(frame, region, height=None): # copy v2 yuv_cropped_frame[ - size - + size // 4 - + uv_channel_y_offset : size + size + size // 4 + uv_channel_y_offset : size + size // 4 + uv_channel_y_offset + uv_crop_height, - size // 2 - + uv_channel_x_offset : size // 2 + size // 2 + uv_channel_x_offset : size // 2 + uv_channel_x_offset + uv_crop_width, ] = frame[v2[1] : v2[3], v2[0] : v2[2]] diff --git a/pyproject.toml b/pyproject.toml index 3123a3242..a1d5cf00d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,3 @@ -[tool.isort] -profile = "black" - [tool.ruff] -ignore = ["E501","E711","E712"] \ No newline at end of file +ignore = ["E501","E711","E712"] +extend-select = ["I"] \ No newline at end of file