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
This commit is contained in:
redphix 2022-10-20 15:25:24 +05:30 committed by GitHub
parent 437145225e
commit c32c07eaa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 8 deletions

32
.github/workflows/py-linter.yml vendored Normal file
View File

@ -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

View File

@ -2,7 +2,6 @@ from decouple import config
from secrets import token_urlsafe from secrets import token_urlsafe
from api.models import Order from api.models import Order
from api.utils import get_session from api.utils import get_session
import time
class Telegram(): class Telegram():
''' Simple telegram messages by requesting to API''' ''' Simple telegram messages by requesting to API'''

View File

@ -1,4 +1,3 @@
from django.template.defaultfilters import default
from rest_framework import serializers from rest_framework import serializers
from .models import MarketTick, Order from .models import MarketTick, Order
from decouple import config from decouple import config

View File

@ -1,6 +1,6 @@
from django.urls import path from django.urls import path
from .views import MakerView, OrderView, UserView, BookView, InfoView, RewardView, PriceView, LimitView, HistoricalView, TickView, StealthView 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 from chat.views import ChatView
urlpatterns = [ urlpatterns = [

View File

@ -1,10 +1,6 @@
import os
from re import T
from django.db.models import Sum, Q from django.db.models import Sum, Q
from drf_spectacular.types import OpenApiTypes from drf_spectacular.utils import extend_schema
from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema
from rest_framework import status, viewsets from rest_framework import status, viewsets
from rest_framework.exceptions import bad_request
from rest_framework.generics import CreateAPIView, ListAPIView, UpdateAPIView from rest_framework.generics import CreateAPIView, ListAPIView, UpdateAPIView
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.response import Response from rest_framework.response import Response

2
pyproject.toml Normal file
View File

@ -0,0 +1,2 @@
[tool.isort]
profile = "black"

View File

@ -29,3 +29,7 @@ python-gnupg==0.4.9
daphne==3.0.2 daphne==3.0.2
drf-spectacular==0.24.0 drf-spectacular==0.24.0
drf-spectacular-sidecar==2022.9.1 drf-spectacular-sidecar==2022.9.1
black==22.8.0
isort==5.10.1
flake8==5.0.4
pyflakes==2.5.0