Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace flake8 with ruff #2092

Merged
merged 18 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

6 changes: 2 additions & 4 deletions .github/workflows/python-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ jobs:
run: |
poetry install --only=dev-host

- name: Analyzing the code with flake8
- name: Analyzing the code with ruff
run: |
if [ -n "$(git ls-files '*.py')" ]; then
poetry run flake8 $(git ls-files '*.py')
fi
poetry run ruff check .
7 changes: 4 additions & 3 deletions anthias_app/helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import uuid
import yaml
from os import getenv, path

import yaml
from django.shortcuts import render
from django.utils import timezone

from anthias_app.models import Asset
from lib.github import is_up_to_date
from lib.utils import get_video_duration
from os import getenv, path
from anthias_app.models import Asset
from settings import settings


Expand Down
1 change: 1 addition & 0 deletions anthias_app/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid

from django.db import models
from django.utils import timezone

Expand Down
1 change: 1 addition & 0 deletions anthias_app/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import path

from . import views

app_name = 'anthias_app'
Expand Down
28 changes: 15 additions & 13 deletions anthias_app/views.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import ipaddress
from datetime import timedelta
from django.views.decorators.http import require_http_methods
from hurry.filesize import size
from os import (
getenv,
statvfs,
)
from platform import machine
from settings import (
CONFIGURABLE_SETTINGS,
DEFAULTS,
settings,
ZmqPublisher,
)
from urllib.parse import urlparse

import psutil
from django.views.decorators.http import require_http_methods
from hurry.filesize import size

from lib import (
diagnostics,
device_helper,
diagnostics,
)
from lib.auth import authorized
from lib.utils import (
Expand All @@ -26,14 +24,18 @@
is_demo_node,
is_docker,
)
from settings import (
CONFIGURABLE_SETTINGS,
DEFAULTS,
ZmqPublisher,
settings,
)

from .helpers import (
add_default_assets,
remove_default_assets,
template,
)
import ipaddress
import psutil


r = connect_to_redis()

Expand Down Expand Up @@ -138,7 +140,7 @@ def settings_page(request):
context['flash'] = {'class': "danger", 'message': e}
else:
settings.load()
for field, default in list(DEFAULTS['viewer'].items()):
for field, _default in list(DEFAULTS['viewer'].items()):
context[field] = settings[field]

auth_backends = []
Expand Down
5 changes: 3 additions & 2 deletions anthias_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import pytz
import secrets
from pathlib import Path
from os import getenv
from pathlib import Path

import pytz

from settings import settings as device_settings

Expand Down
1 change: 1 addition & 0 deletions anthias_django/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.contrib import admin
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView

from lib.auth import authorized


Expand Down
5 changes: 3 additions & 2 deletions api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from dateutil import parser as date_parser
from rest_framework import status
from rest_framework.views import exception_handler
from rest_framework.response import Response
from rest_framework.views import exception_handler

from anthias_app.models import Asset


class AssetCreationException(Exception):
class AssetCreationError(Exception):
def __init__(self, errors):
self.errors = errors

Expand Down
2 changes: 2 additions & 0 deletions api/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os import path

from django.utils import timezone
from rest_framework.serializers import (
CharField,
Expand All @@ -7,6 +8,7 @@
ModelSerializer,
Serializer,
)

from anthias_app.models import Asset
from lib.utils import validate_url

Expand Down
1 change: 1 addition & 0 deletions api/serializers/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
url_fails,
)
from settings import settings

from . import (
get_unique_name,
validate_uri,
Expand Down
2 changes: 2 additions & 0 deletions api/serializers/v1_1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid
from os import path, rename

from django.utils import timezone
from rest_framework.serializers import (
BooleanField,
Expand All @@ -15,6 +16,7 @@
url_fails,
)
from settings import settings

from . import (
get_unique_name,
validate_uri,
Expand Down
2 changes: 1 addition & 1 deletion api/serializers/v2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.utils import timezone
from anthias_app.models import Asset
from rest_framework.serializers import (
BooleanField,
CharField,
Expand All @@ -9,6 +8,7 @@
Serializer,
)

from anthias_app.models import Asset
from api.serializers import UpdateAssetSerializer
from api.serializers.mixins import CreateAssetSerializerMixin

Expand Down
13 changes: 6 additions & 7 deletions api/tests.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import json
from os import path
from pathlib import Path
from unittest import mock

from django.conf import settings as django_settings
from django.test import TestCase
from django.urls import reverse
from os import path
from pathlib import Path
from rest_framework.test import APIClient
from rest_framework import status
from settings import settings as anthias_settings
from unittest import mock
from unittest_parametrize import parametrize, ParametrizedTestCase
from rest_framework.test import APIClient
from unittest_parametrize import ParametrizedTestCase, parametrize

from anthias_app.models import Asset

from settings import settings as anthias_settings

ASSET_LIST_V1_1_URL = reverse('api:asset_list_v1_1')
ASSET_CREATION_DATA = {
Expand Down
14 changes: 7 additions & 7 deletions api/urls/v1.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from django.urls import path

from api.views.v1 import (
AssetViewV1,
AssetListViewV1,
AssetContentViewV1,
FileAssetViewV1,
PlaylistOrderViewV1,
BackupViewV1,
RecoverViewV1,
AssetListViewV1,
AssetsControlViewV1,
AssetViewV1,
BackupViewV1,
FileAssetViewV1,
InfoView,
PlaylistOrderViewV1,
RebootViewV1,
RecoverViewV1,
ShutdownViewV1,
ViewerCurrentAssetViewV1
ViewerCurrentAssetViewV1,
)


Expand Down
5 changes: 1 addition & 4 deletions api/urls/v1_1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.urls import path

from api.views.v1_1 import (
AssetListViewV1_1,
AssetViewV1_1
)
from api.views.v1_1 import AssetListViewV1_1, AssetViewV1_1


def get_url_patterns():
Expand Down
5 changes: 1 addition & 4 deletions api/urls/v1_2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.urls import path

from api.views.v1_2 import (
AssetListViewV1_2,
AssetViewV1_2
)
from api.views.v1_2 import AssetListViewV1_2, AssetViewV1_2


def get_url_patterns():
Expand Down
6 changes: 3 additions & 3 deletions api/urls/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from api.views.v2 import (
AssetContentViewV2,
AssetsControlViewV2,
AssetListViewV2,
AssetsControlViewV2,
AssetViewV2,
BackupViewV2,
FileAssetViewV2,
PlaylistOrderViewV2,
RecoverViewV2,
RebootViewV2,
RecoverViewV2,
ShutdownViewV2,
FileAssetViewV2
)


Expand Down
14 changes: 7 additions & 7 deletions api/views/mixins.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import uuid

from base64 import b64encode
from inspect import cleandoc
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
from mimetypes import guess_type, guess_extension
from mimetypes import guess_extension, guess_type
from os import path, remove

from drf_spectacular.utils import OpenApiParameter, OpenApiTypes, extend_schema
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from lib import backup_helper
from lib.auth import authorized

from anthias_app.models import Asset
from api.helpers import save_active_assets_ordering
from celery_tasks import reboot_anthias, shutdown_anthias
from os import path, remove
from settings import settings, ZmqPublisher
from lib import backup_helper
from lib.auth import authorized
from settings import ZmqPublisher, settings


class DeleteAssetViewMixin:
Expand Down
43 changes: 22 additions & 21 deletions api/views/v1.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
from os import statvfs

from drf_spectacular.utils import (
OpenApiExample,
OpenApiRequest,
extend_schema,
inline_serializer,
)
from hurry.filesize import size
from rest_framework import serializers, status
from rest_framework.response import Response
from rest_framework.views import APIView
from api.serializers.v1_1 import CreateAssetSerializerV1_1
from api.serializers import (
AssetSerializer,
UpdateAssetSerializer,
)

from anthias_app.models import Asset
from api.helpers import (
AssetCreationException,
AssetCreationError,
parse_request,
)
from drf_spectacular.utils import (
extend_schema,
inline_serializer,
OpenApiExample,
OpenApiRequest,
from api.serializers import (
AssetSerializer,
UpdateAssetSerializer,
)
from hurry.filesize import size
from lib import diagnostics
from lib.auth import authorized
from lib.github import is_up_to_date
from lib.utils import connect_to_redis
from os import statvfs
from anthias_app.models import Asset
from api.serializers.v1_1 import CreateAssetSerializerV1_1
from api.views.mixins import (
AssetContentViewMixin,
AssetsControlViewMixin,
Expand All @@ -34,9 +32,12 @@
RecoverViewMixin,
ShutdownViewMixin,
)
from lib import diagnostics
from lib.auth import authorized
from lib.github import is_up_to_date
from lib.utils import connect_to_redis
from settings import ZmqCollector, ZmqPublisher


r = connect_to_redis()

MODEL_STRING_EXAMPLE = """
Expand Down Expand Up @@ -146,8 +147,8 @@ def post(self, request, format=None):
try:
serializer = CreateAssetSerializerV1_1(data=data)
if not serializer.is_valid():
raise AssetCreationException(serializer.errors)
except AssetCreationException as error:
raise AssetCreationError(serializer.errors)
except AssetCreationError as error:
return Response(error.errors, status=status.HTTP_400_BAD_REQUEST)

asset = Asset.objects.create(**serializer.data)
Expand Down
Loading
Loading