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

ВСК-35 Добавление pre-commit #84

Merged
merged 8 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
uses: py-actions/flake8@v2
with:
path: "app"
args: "--config pyproject.toml"
args: "--config setup.cfg"
- uses: isort/isort-action@master
with:
configuration: .pyproject.toml
configuration: .setup.cfg
- name: Install dependencies
run: |
pip install --upgrade pip
Expand All @@ -40,4 +40,3 @@ jobs:
EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }}
run: |
pytest

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ dmypy.json
.idea

# fastapi stuff
fastapi.db
fastapi.db
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: app/requirements.txt
- id: trailing-whitespace
- id: check-merge-conflict
- id: double-quote-string-fixer

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: [ --profile=flake8, --line-length=79 ]

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- pep8-naming
- flake8-broken-line
- flake8-isort
- flake8-bugbear

- repo: local
hooks:
- id: pytest
name: Check pytest
entry: pytest tests/
language: system
pass_filenames: false
always_run: true
types: [python]
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ uvicorn app.main:app --host 127.0.0.1 --port 8000

Документация будет доступна по http://127.0.0.1/docs/

## Разработчики
## Полезные материалы

<details>
<summary><h3>Команды pre-commit</h3></summary>

- Установить pre-commit в проекте: `pre-commit install`
- Запустить проверку всех хуков: `pre-commit run -a`
- Запустить конкретный хук: `pre-commit run <имя-хука>`
- Деактивировать автоматическое выполнение хуков перед коммитом: `pre-commit uninstall`
- Обновить pre-commit хуки: `pre-commit autoupdate`

</details>

## Разработчики

-----

Expand All @@ -79,5 +92,3 @@ uvicorn app.main:app --host 127.0.0.1 --port 8000

- [Глеб Кондратьев](https://github.com/gleb60)
----


2 changes: 1 addition & 1 deletion alembic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ alembic downgrade base

```
alembic history
```
```
8 changes: 4 additions & 4 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os
from logging.config import fileConfig

from alembic import context
from dotenv import load_dotenv
from sqlalchemy import pool
from sqlalchemy.ext.asyncio import async_engine_from_config

from alembic import context
from app.core.base import Base

config = context.config
Expand Down Expand Up @@ -34,12 +34,12 @@ def run_migrations_offline() -> None:
script output.

"""
url = config.get_main_option("sqlalchemy.url")
url = config.get_main_option('sqlalchemy.url')
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
dialect_opts={'paramstyle': 'named'},
)

with context.begin_transaction():
Expand All @@ -65,7 +65,7 @@ async def run_async_migrations() -> None:

connectable = async_engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)

Expand Down
2 changes: 1 addition & 1 deletion alembic/versions/4098f76764d4_initial_migration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Initial migration

Revision ID: 4098f76764d4
Revises:
Revises:
Create Date: 2023-12-07 23:54:47.680798

"""
Expand Down
20 changes: 10 additions & 10 deletions app/admin/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

class AdminAuth(AuthenticationBackend):
async def login(
self,
request: Request,
session: AsyncSession = AsyncSessionLocal(),
strategy: JWTStrategy = get_jwt_strategy()
self,
request: Request,
session: AsyncSession = AsyncSessionLocal(),
strategy: JWTStrategy = get_jwt_strategy()
) -> bool:
form = await request.form()
email, password = form["username"], form["password"]
email, password = form['username'], form['password']
user = await user_crud.get_user_by_credentials(
email, password, session
)
if not user:
return False
token = await strategy.write_token(user)
request.session.update({"token": token})
request.session.update({'token': token})

return True

Expand All @@ -33,11 +33,11 @@ async def logout(self, request: Request) -> bool:
return True

async def authenticate(
self,
request: Request,
session: AsyncSession = AsyncSessionLocal()
self,
request: Request,
session: AsyncSession = AsyncSessionLocal()
) -> bool:
token = request.session.get("token")
token = request.session.get('token')
if not token:
return False
return True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут и формы и токен. Странный файл....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да

8 changes: 4 additions & 4 deletions app/admin/tariff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TariffAdmin(ModelView, model=Tariff):
can_edit = True
can_delete = False
can_view_details = True
name = "Tariff"
name_plural = "Tariffs"
icon = "fa-solid fa-dollar-sign"
category = "tariff"
name = 'Tariff'
name_plural = 'Tariffs'
icon = 'fa-solid fa-dollar-sign'
category = 'tariff'
8 changes: 4 additions & 4 deletions app/admin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class UserAdmin(ModelView, model=User):
can_edit = True
can_delete = False
can_view_details = True
name = "User"
name_plural = "Users"
icon = "fa-solid fa-user"
category = "accounts"
name = 'User'
name_plural = 'Users'
icon = 'fa-solid fa-user'
category = 'accounts'
column_searchable_list = [User.username]
column_sortable_list = [User.id]
column_formatters = {User.username: lambda m, a: m.username[:10]}
12 changes: 6 additions & 6 deletions app/api/endpoints/achievement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
DELETE_ACHIEVEMENT_DESCRIPTION, GET_ACHIEVEMENT,
GET_ACHIEVEMENT_CURRENTUSER_ID_DESCRIPTION, GET_ACHIEVEMENTS,
GET_ACHIEVEMENTS_CURRENTUSER_DESCRIPTION, GET_ALL_ACHIEVEMENTS_DESCRIPTION,
GET_ME_ACHIEVEMENT, PATCH_ACHIEVEMENT_ID_DESCRIPTION
GET_ME_ACHIEVEMENT, PATCH_ACHIEVEMENT_ID_DESCRIPTION,
)
from app.api_docs_responses.utils_docs import (
REQUEST_NAME_AND_DESCRIPTION_VALUE
REQUEST_NAME_AND_DESCRIPTION_VALUE,
)
from app.core.db import get_async_session
from app.core.user import current_superuser, current_user
from app.crud import achievement_crud
from app.models import Achievement, User
from app.schemas.achievement import (
AchievementCreate, AchievementRead, AchievementUpdate
AchievementCreate, AchievementRead, AchievementUpdate,
)
from app.services.endpoints_services import delete_obj
from app.services.utils import (
Pagination, add_response_headers, get_pagination_params, paginated
Pagination, add_response_headers, get_pagination_params, paginated,
)

router = APIRouter()
Expand Down Expand Up @@ -101,7 +101,7 @@ async def get_self_achievement_by_id(


@router.post(
"/",
'/',
response_model=AchievementRead,
dependencies=[Depends(current_superuser)],
status_code=status.HTTP_201_CREATED,
Expand Down Expand Up @@ -145,7 +145,7 @@ async def update_achievement(


@router.delete(
"/{achievement_id}",
'/{achievement_id}',
dependencies=[Depends(current_superuser)],
status_code=status.HTTP_204_NO_CONTENT,
responses=DELETE_ACHIEVEMENT,
Expand Down
18 changes: 9 additions & 9 deletions app/api/endpoints/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from app.api.validators import check_name_duplicate, check_obj_exists
from app.api_docs_responses.course import (
CREATE_COURSE, DELETE_COURSE, GET_COURSE, GET_COURSES, GET_USER_COURSE,
GET_USER_COURSES, PATCH_COURSE
GET_USER_COURSES, PATCH_COURSE,
)
from app.api_docs_responses.utils_docs import (
REQUEST_NAME_AND_DESCRIPTION_VALUE
REQUEST_NAME_AND_DESCRIPTION_VALUE,
)
from app.core.db import get_async_session
from app.core.user import current_superuser, current_user
Expand All @@ -16,14 +16,14 @@
from app.schemas.course import CourseCreate, CourseRead, CourseUpdate
from app.services.endpoints_services import delete_obj
from app.services.utils import (
Pagination, add_response_headers, get_pagination_params, paginated
Pagination, add_response_headers, get_pagination_params, paginated,
)

router = APIRouter()


@router.get(
"/",
'/',
response_model=list[CourseRead],
**GET_COURSES,
)
Expand All @@ -39,7 +39,7 @@ async def get_all_courses(


@router.get(
"/me",
'/me',
response_model=list[CourseRead],
dependencies=[Depends(current_user)],
**GET_USER_COURSES,
Expand All @@ -59,7 +59,7 @@ async def get_all_user_courses(


@router.get(
"/me/{course_id}",
'/me/{course_id}',
response_model=CourseRead,
dependencies=[Depends(current_user)],
**GET_USER_COURSE,
Expand Down Expand Up @@ -100,7 +100,7 @@ async def get_course(


@router.post(
"/",
'/',
response_model=CourseRead,
dependencies=[Depends(current_superuser)],
status_code=status.HTTP_201_CREATED,
Expand All @@ -117,7 +117,7 @@ async def create_course(


@router.patch(
"/{course_id}",
'/{course_id}',
response_model=CourseRead,
dependencies=[Depends(current_superuser)],
**PATCH_COURSE,
Expand All @@ -142,7 +142,7 @@ async def update_course(


@router.delete(
"/{course_id}",
'/{course_id}',
dependencies=[Depends(current_superuser)],
status_code=status.HTTP_204_NO_CONTENT,
**DELETE_COURSE,
Expand Down
12 changes: 6 additions & 6 deletions app/api/endpoints/examination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
from app.api.validators import check_name_duplicate, check_obj_exists
from app.api_docs_responses.examination import (
CREATE_EXAMINATION, DELETE_EXAMINATION, GET_EXAMINATION, GET_EXAMINATIONS,
GET_USER_EXAMINATIONS, UPDATE_EXAMINATION
GET_USER_EXAMINATIONS, UPDATE_EXAMINATION,
)
from app.api_docs_responses.utils_docs import (
REQUEST_NAME_AND_DESCRIPTION_VALUE
REQUEST_NAME_AND_DESCRIPTION_VALUE,
)
from app.core.db import get_async_session
from app.core.user import current_superuser, current_user
from app.crud import examination_crud
from app.models import User
from app.schemas.examination import (
ExaminationCreate, ExaminationRead, ExaminationUpdate
ExaminationCreate, ExaminationRead, ExaminationUpdate,
)
from app.services.endpoints_services import delete_obj

router = APIRouter()


@router.get(
"/",
'/',
response_model=list[ExaminationRead],
**GET_EXAMINATIONS,
)
Expand Down Expand Up @@ -62,7 +62,7 @@ async def get_examination(


@router.post(
"/",
'/',
response_model=ExaminationRead,
dependencies=[Depends(current_superuser)],
status_code=status.HTTP_201_CREATED,
Expand Down Expand Up @@ -100,7 +100,7 @@ async def update_examination(


@router.delete(
"/{examination_id}",
'/{examination_id}',
dependencies=[Depends(current_superuser)],
status_code=status.HTTP_204_NO_CONTENT,
**DELETE_EXAMINATION
Expand Down
Loading
Loading