Skip to content

Commit

Permalink
Merge pull request #2 from tjarhad/master
Browse files Browse the repository at this point in the history
Added Linting tool and pre-commit hook
  • Loading branch information
anandtripathi5 authored Nov 13, 2022
2 parents 948ce2b + e0172ae commit 99311ff
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 88
exclude =
.git,
__pycache__,
__init__.py,
.pytest_cache
migrations
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: local
hooks:
- id: lint-check
name: Lint check
entry: ./scripts/lint.sh
language: system
always_run: true
pass_filenames: false
3 changes: 1 addition & 2 deletions apis/books/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from sqlalchemy import Column, String, Integer, Text

from extensions import Base
from sqlalchemy import Column, Integer, String, Text


class Book(Base):
Expand Down
6 changes: 3 additions & 3 deletions apis/books/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from flask_apispec import use_kwargs, marshal_with, MethodResource, doc
from extensions import db, security_params
from flask_apispec import MethodResource, doc, marshal_with, use_kwargs
from flask_restful import Resource
from marshmallow import Schema
from utils.helpers import auth_required
from webargs import fields

from apis.books.models import Book
from apis.users.models import PermissionEnum
from extensions import db, security_params
from utils.helpers import auth_required


class BookModel(Schema):
Expand Down
3 changes: 1 addition & 2 deletions apis/rest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from extensions import db, docs, jwt
from flask_restful import Api

from apis.books.views import Books
from apis.urls import urls
from apis.users.models import User
from extensions import docs, jwt, db

api = Api()

Expand Down
2 changes: 1 addition & 1 deletion apis/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from apis.books.views import Books
from apis.users.views import Signup, Refresh, Login
from apis.users.views import Login, Refresh, Signup


class API:
Expand Down
3 changes: 1 addition & 2 deletions apis/users/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from enum import Enum

from extensions import Base
from sqlalchemy import Column, Integer, String
from sqlalchemy_utils import ChoiceType, PasswordType

from extensions import Base


class PermissionEnum(Enum):
user = "user"
Expand Down
10 changes: 7 additions & 3 deletions apis/users/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from extensions import db, security_params
from flask_apispec import MethodResource, doc, use_kwargs
from flask_jwt_extended import create_access_token, create_refresh_token, \
jwt_required, get_jwt_identity
from flask_jwt_extended import (
create_access_token,
create_refresh_token,
get_jwt_identity,
jwt_required,
)
from flask_restful import Resource
from marshmallow import Schema
from webargs import fields

from apis.users.models import User
from extensions import db, docs, security_params


class SignupRequest(Schema):
Expand Down
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin
from pydantic import BaseSettings
from pydantic.config import Optional

Expand Down
2 changes: 1 addition & 1 deletion flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from apis.rest import api, init_routes
from config import settings
from extensions import session, Base, db, exc, docs, jwt
from extensions import db, docs, exc, jwt, session
from utils.log import configure_logging


Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.black]
line-length = 88

#extend-exclude = ["migrations" ]

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
line_length = 88
src_paths = ["apis", "tests"]
18 changes: 18 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,46 @@ aniso8601==9.0.1
apispec==5.2.2
apispec-webframeworks==0.5.2
attrs==22.1.0
autoflake==1.7.7
beautifulsoup4==4.11.1
black==22.10.0
blinker==1.5
cfgv==3.3.1
click==8.1.3
distlib==0.3.6
filelock==3.8.0
flake8==5.0.4
Flask==2.1.2
flask-apispec==0.11.4
Flask-JWT-Extended==4.4.4
Flask-RESTful==0.3.9
Flask-WebTest==0.0.9
greenlet==1.1.3
gunicorn==20.1.0
identify==2.5.8
importlib-metadata==4.12.0
iniconfig==1.1.1
isort==5.10.1
itsdangerous==2.1.2
Jinja2==3.1.2
jsonschema==4.14.0
Mako==1.2.2
MarkupSafe==2.1.1
marshmallow==3.17.1
mccabe==0.7.0
mypy-extensions==0.4.3
nodeenv==1.7.0
packaging==21.3
passlib==1.7.4
pathspec==0.10.2
platformdirs==2.5.4
pluggy==1.0.0
pre-commit==2.20.0
psycopg2-binary==2.9.3
py==1.11.0
pycodestyle==2.9.1
pydantic==1.9.2
pyflakes==2.5.0
PyJWT==2.4.0
pyparsing==3.0.9
pyrsistent==0.18.1
Expand All @@ -38,8 +54,10 @@ six==1.16.0
soupsieve==2.3.2.post1
SQLAlchemy==1.4.40
SQLAlchemy-Utils==0.38.3
toml==0.10.2
tomli==2.0.1
typing_extensions==4.3.0
virtualenv==20.16.7
waitress==2.1.2
webargs==8.2.0
WebOb==1.8.7
Expand Down
8 changes: 8 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e
set -x

#black --check .
isort --check-only apis
flake8 .
6 changes: 6 additions & 0 deletions scripts/lint_fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -x
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place . --exclude=__init__.py
#black apis
isort apis

0 comments on commit 99311ff

Please sign in to comment.