From c32c07eaa68aadeb14fe0403b8aa825fa630de4c Mon Sep 17 00:00:00 2001 From: redphix <113045766+redphix@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:25:24 +0530 Subject: [PATCH] Python files style cleanup (#281) * Remove unused imports in python files * Add black and isort dependencies Also added pyproject.toml for isort config, but later can be used to configure various other python tools * Add flake8 in requirements.txt * Add py-linter workflow --- .github/workflows/py-linter.yml | 32 ++++++++++++++++++++++++++++++++ api/messages.py | 1 - api/serializers.py | 1 - api/urls.py | 2 +- api/views.py | 6 +----- pyproject.toml | 2 ++ requirements.txt | 4 ++++ 7 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/py-linter.yml create mode 100644 pyproject.toml diff --git a/.github/workflows/py-linter.yml b/.github/workflows/py-linter.yml new file mode 100644 index 00000000..2f5b21aa --- /dev/null +++ b/.github/workflows/py-linter.yml @@ -0,0 +1,32 @@ +name: Python Lint + +on: + push: + branches: + - main + pull_request: + branches: + - main + paths: + - '**.py' + +jobs: + run-linters: + name: Run linters + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: pip + - run: pip install black==22.8.0 flake8==5.0.4 isort==5.10.1 + - name: Run linters + uses: wearerequired/lint-action@v2 + with: + auto_fix: true + black: true + flake8: true + # Flake8 doesn't support auto-fixing + flake8_auto_fix: false diff --git a/api/messages.py b/api/messages.py index 0021729a..3fa7b846 100644 --- a/api/messages.py +++ b/api/messages.py @@ -2,7 +2,6 @@ from decouple import config from secrets import token_urlsafe from api.models import Order from api.utils import get_session -import time class Telegram(): ''' Simple telegram messages by requesting to API''' diff --git a/api/serializers.py b/api/serializers.py index b4b3aff5..eb33e179 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,4 +1,3 @@ -from django.template.defaultfilters import default from rest_framework import serializers from .models import MarketTick, Order from decouple import config diff --git a/api/urls.py b/api/urls.py index 2bfb32b9..446d656a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,6 +1,6 @@ from django.urls import path from .views import MakerView, OrderView, UserView, BookView, InfoView, RewardView, PriceView, LimitView, HistoricalView, TickView, StealthView -from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView +from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView from chat.views import ChatView urlpatterns = [ diff --git a/api/views.py b/api/views.py index 6fe4f3d1..2b782032 100644 --- a/api/views.py +++ b/api/views.py @@ -1,10 +1,6 @@ -import os -from re import T from django.db.models import Sum, Q -from drf_spectacular.types import OpenApiTypes -from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema +from drf_spectacular.utils import extend_schema from rest_framework import status, viewsets -from rest_framework.exceptions import bad_request from rest_framework.generics import CreateAPIView, ListAPIView, UpdateAPIView from rest_framework.views import APIView from rest_framework.response import Response diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..5d7bf33d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.isort] +profile = "black" diff --git a/requirements.txt b/requirements.txt index 852f0823..b18802df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,3 +29,7 @@ python-gnupg==0.4.9 daphne==3.0.2 drf-spectacular==0.24.0 drf-spectacular-sidecar==2022.9.1 +black==22.8.0 +isort==5.10.1 +flake8==5.0.4 +pyflakes==2.5.0