go all in on ruff

This commit is contained in:
Blake Blackshear 2023-11-16 06:08:44 -06:00
parent 7b520e8a9d
commit a39c1f79a4
7 changed files with 20 additions and 40 deletions

View File

@ -42,7 +42,6 @@
"extensions": [ "extensions": [
"ms-python.python", "ms-python.python",
"ms-python.vscode-pylance", "ms-python.vscode-pylance",
"ms-python.black-formatter",
"visualstudioexptteam.vscodeintellicode", "visualstudioexptteam.vscodeintellicode",
"mhutchie.git-graph", "mhutchie.git-graph",
"ms-azuretools.vscode-docker", "ms-azuretools.vscode-docker",
@ -53,13 +52,10 @@
"csstools.postcss", "csstools.postcss",
"blanu.vscode-styled-jsx", "blanu.vscode-styled-jsx",
"bradlc.vscode-tailwindcss", "bradlc.vscode-tailwindcss",
"ms-python.isort",
"charliermarsh.ruff" "charliermarsh.ruff"
], ],
"settings": { "settings": {
"remote.autoForwardPorts": false, "remote.autoForwardPorts": false,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "none", "python.formatting.provider": "none",
"python.languageServer": "Pylance", "python.languageServer": "Pylance",
"editor.formatOnPaste": false, "editor.formatOnPaste": false,
@ -72,7 +68,7 @@
"eslint.workingDirectories": ["./web"], "eslint.workingDirectories": ["./web"],
"isort.args": ["--settings-path=./pyproject.toml"], "isort.args": ["--settings-path=./pyproject.toml"],
"[python]": { "[python]": {
"editor.defaultFormatter": "ms-python.black-formatter", "editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true, "editor.formatOnSave": true,
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll": true, "source.fixAll": true,

View File

@ -72,13 +72,10 @@ jobs:
run: | run: |
python3 -m pip install -U pip python3 -m pip install -U pip
python3 -m pip install -r docker/main/requirements-dev.txt python3 -m pip install -r docker/main/requirements-dev.txt
- name: Check black - name: Check formatting
run: | run: |
black --check --diff frigate migrations docker *.py ruff format --check --diff frigate migrations docker *.py
- name: Check isort - name: Check lint
run: |
isort --check --diff frigate migrations docker *.py
- name: Check ruff
run: | run: |
ruff check frigate migrations docker *.py ruff check frigate migrations docker *.py

View File

@ -14,13 +14,14 @@ services:
dockerfile: docker/main/Dockerfile dockerfile: docker/main/Dockerfile
# Use target devcontainer-trt for TensorRT dev # Use target devcontainer-trt for TensorRT dev
target: devcontainer target: devcontainer
deploy: ## Uncomment this block for nvidia gpu support
resources: # deploy:
reservations: # resources:
devices: # reservations:
- driver: nvidia # devices:
count: 1 # - driver: nvidia
capabilities: [gpu] # count: 1
# capabilities: [gpu]
environment: environment:
YOLO_MODELS: yolov7-320 YOLO_MODELS: yolov7-320
devices: devices:

View File

@ -1,3 +1 @@
black == 23.10.*
isort
ruff ruff

View File

@ -225,12 +225,8 @@ class RecordingMaintainer(threading.Thread):
# if cached file's start_time is earlier than the retain days for the camera # if cached file's start_time is earlier than the retain days for the camera
if start_time <= ( if start_time <= (
( datetime.datetime.now().astimezone(datetime.timezone.utc)
datetime.datetime.now().astimezone(datetime.timezone.utc) - datetime.timedelta(days=self.config.cameras[camera].record.retain.days)
- datetime.timedelta(
days=self.config.cameras[camera].record.retain.days
)
)
): ):
# if the cached segment overlaps with the events: # if the cached segment overlaps with the events:
overlaps = False overlaps = False

View File

@ -287,17 +287,14 @@ def yuv_crop_and_resize(frame, region, height=None):
# copy u2 # copy u2
yuv_cropped_frame[ yuv_cropped_frame[
size + uv_channel_y_offset : size + uv_channel_y_offset + uv_crop_height, size + uv_channel_y_offset : size + uv_channel_y_offset + uv_crop_height,
size // 2 size // 2 + uv_channel_x_offset : size // 2
+ uv_channel_x_offset : size // 2
+ uv_channel_x_offset + uv_channel_x_offset
+ uv_crop_width, + uv_crop_width,
] = frame[u2[1] : u2[3], u2[0] : u2[2]] ] = frame[u2[1] : u2[3], u2[0] : u2[2]]
# copy v1 # copy v1
yuv_cropped_frame[ yuv_cropped_frame[
size size + size // 4 + uv_channel_y_offset : size
+ size // 4
+ uv_channel_y_offset : size
+ size // 4 + size // 4
+ uv_channel_y_offset + uv_channel_y_offset
+ uv_crop_height, + uv_crop_height,
@ -306,14 +303,11 @@ def yuv_crop_and_resize(frame, region, height=None):
# copy v2 # copy v2
yuv_cropped_frame[ yuv_cropped_frame[
size size + size // 4 + uv_channel_y_offset : size
+ size // 4
+ uv_channel_y_offset : size
+ size // 4 + size // 4
+ uv_channel_y_offset + uv_channel_y_offset
+ uv_crop_height, + uv_crop_height,
size // 2 size // 2 + uv_channel_x_offset : size // 2
+ uv_channel_x_offset : size // 2
+ uv_channel_x_offset + uv_channel_x_offset
+ uv_crop_width, + uv_crop_width,
] = frame[v2[1] : v2[3], v2[0] : v2[2]] ] = frame[v2[1] : v2[3], v2[0] : v2[2]]

View File

@ -1,5 +1,3 @@
[tool.isort]
profile = "black"
[tool.ruff] [tool.ruff]
ignore = ["E501","E711","E712"] ignore = ["E501","E711","E712"]
extend-select = ["I"]