Skip to content

Commit

Permalink
feat: use Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
j3rrryy committed Nov 22, 2024
1 parent 0011068 commit 24f4a1d
Show file tree
Hide file tree
Showing 39 changed files with 61 additions and 55 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<a href="https://github.com/j3rrryy/school_464/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License">
</a>
<a href="https://github.com/psf/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Black formatter">
<a href="https://github.com/astral-sh/ruff">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
</a>
</p>

Expand Down Expand Up @@ -36,7 +36,7 @@

> [!NOTE]
> API located at `/api`
>
>
> Docs located at `/api/docs`, but Swagger does not support MessagePack, so use another tool to send requests with this content type
## :computer: Requirements
Expand Down
16 changes: 8 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ services:
env_file:
- ./docker/env/.env.dev
volumes:
- ./:/app/
- ./src/gateway/:/app/
networks:
- nginx_network
- main_network
depends_on:
- auth
- files
- mail
command: bash -c "cd ./src/gateway/ && python ./main.py"
command: python ./main.py
container_name: gateway_dev

auth:
Expand All @@ -64,14 +64,14 @@ services:
env_file:
- ./docker/env/.env.dev
volumes:
- ./:/app/
- ./src/auth/:/app/
networks:
- main_network
- auth_network
depends_on:
- auth_postgres
- auth_redis
command: bash -c "cd ./src/auth/ && alembic -c "./config/alembic.ini" upgrade head && python ./main.py"
command: bash -c "alembic -c "./config/alembic.ini" upgrade head && python ./main.py"
container_name: auth_dev

auth_postgres:
Expand Down Expand Up @@ -108,15 +108,15 @@ services:
env_file:
- ./docker/env/.env.dev
volumes:
- ./:/app/
- ./src/files/:/app/
networks:
- main_network
- files_network
depends_on:
- files_minio
- files_postgres
- files_redis
command: bash -c "cd ./src/files/ && alembic -c "./config/alembic.ini" upgrade head && python ./main.py"
command: bash -c "alembic -c "./config/alembic.ini" upgrade head && python ./main.py"
container_name: files_dev

files_minio:
Expand Down Expand Up @@ -202,10 +202,10 @@ services:
env_file:
- ./docker/env/.env.dev
volumes:
- ./:/app/
- ./src/mail/:/app/
networks:
- mail_network
depends_on:
- mail_kafka
command: bash -c "cd ./src/mail/ && python ./main.py"
command: python ./main.py
container_name: mail_dev
2 changes: 1 addition & 1 deletion src/auth/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .config import *
from .config import * # noqa: F403
2 changes: 1 addition & 1 deletion src/auth/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .database import *
from .database import * # noqa: F403
6 changes: 3 additions & 3 deletions src/auth/database/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .crud import *
from .engine import *
from .models import *
from .crud import * # noqa: F403
from .engine import * # noqa: F403
from .models import * # noqa: F403
2 changes: 1 addition & 1 deletion src/auth/database/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def validate_refresh_token(
).scalar_one_or_none()
else:
result = await session.get(RefreshToken, token_or_id)

return bool(result)
except Exception as exc:
exc.args = (StatusCode.INTERNAL, "Internal database error")
Expand Down
2 changes: 1 addition & 1 deletion src/auth/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .errors import *
from .errors import * # noqa: F403
2 changes: 1 addition & 1 deletion src/auth/proto/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .auth_pb2_grpc import *
from .auth_pb2_grpc import * # noqa: F403
1 change: 1 addition & 0 deletions src/auth/proto/auth_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/auth/proto/auth_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""

import grpc

from . import auth_pb2 as auth__pb2
Expand All @@ -20,7 +21,7 @@
if _version_not_supported:
raise RuntimeError(
f"The grpc package installed is at version {GRPC_VERSION},"
+ f" but the generated code in auth_pb2_grpc.py depends on"
+ " but the generated code in auth_pb2_grpc.py depends on"
+ f" grpcio>={GRPC_GENERATED_VERSION}."
+ f" Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}"
+ f" or downgrade your generated code using grpcio-tools<={GRPC_VERSION}."
Expand Down
2 changes: 1 addition & 1 deletion src/auth/service/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .service import *
from .service import * # noqa: F403
2 changes: 1 addition & 1 deletion src/auth/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .utils import *
from .utils import * # noqa: F403
2 changes: 1 addition & 1 deletion src/files/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .config import *
from .config import * # noqa: F403
4 changes: 2 additions & 2 deletions src/files/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .database import *
from .storage import *
from .database import * # noqa: F403
from .storage import * # noqa: F403
2 changes: 1 addition & 1 deletion src/files/controllers/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def upload_file(
) -> dict[str, str]:
SIZE_NAMES = ("B", "KB", "MB", "GB")

metadata = await anext(data_iterator)
metadata = await anext(data_iterator) # noqa: F821
data = {"user_id": metadata.user_id, "name": metadata.name}

file_size = await CRUD.upload_file(data_iterator, data, client)
Expand Down
6 changes: 3 additions & 3 deletions src/files/database/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .crud import *
from .engine import *
from .models import *
from .crud import * # noqa: F403
from .engine import * # noqa: F403
from .models import * # noqa: F403
2 changes: 1 addition & 1 deletion src/files/proto/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .files_pb2_grpc import *
from .files_pb2_grpc import * # noqa: F403
1 change: 1 addition & 0 deletions src/files/proto/files_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/files/proto/files_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""

import grpc

from . import files_pb2 as files__pb2
Expand All @@ -20,7 +21,7 @@
if _version_not_supported:
raise RuntimeError(
f"The grpc package installed is at version {GRPC_VERSION},"
+ f" but the generated code in files_pb2_grpc.py depends on"
+ " but the generated code in files_pb2_grpc.py depends on"
+ f" grpcio>={GRPC_GENERATED_VERSION}."
+ f" Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}"
+ f" or downgrade your generated code using grpcio-tools<={GRPC_VERSION}."
Expand Down
2 changes: 1 addition & 1 deletion src/files/service/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .service import *
from .service import * # noqa: F403
4 changes: 2 additions & 2 deletions src/files/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .crud import *
from .engine import *
from .crud import * # noqa: F403
from .engine import * # noqa: F403
2 changes: 1 addition & 1 deletion src/files/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .utils import *
from .utils import * # noqa: F403
2 changes: 1 addition & 1 deletion src/gateway/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .config import *
from .config import * # noqa: F403
4 changes: 2 additions & 2 deletions src/gateway/proto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .auth_pb2_grpc import *
from .files_pb2_grpc import *
from .auth_pb2_grpc import * # noqa: F403
from .files_pb2_grpc import * # noqa: F403
1 change: 1 addition & 0 deletions src/gateway/proto/auth_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/gateway/proto/auth_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""

import grpc

from . import auth_pb2 as auth__pb2
Expand All @@ -20,7 +21,7 @@
if _version_not_supported:
raise RuntimeError(
f"The grpc package installed is at version {GRPC_VERSION},"
+ f" but the generated code in auth_pb2_grpc.py depends on"
+ " but the generated code in auth_pb2_grpc.py depends on"
+ f" grpcio>={GRPC_GENERATED_VERSION}."
+ f" Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}"
+ f" or downgrade your generated code using grpcio-tools<={GRPC_VERSION}."
Expand Down
1 change: 1 addition & 0 deletions src/gateway/proto/files_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/gateway/proto/files_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""

import grpc

from . import files_pb2 as files__pb2
Expand All @@ -20,7 +21,7 @@
if _version_not_supported:
raise RuntimeError(
f"The grpc package installed is at version {GRPC_VERSION},"
+ f" but the generated code in files_pb2_grpc.py depends on"
+ " but the generated code in files_pb2_grpc.py depends on"
+ f" grpcio>={GRPC_GENERATED_VERSION}."
+ f" Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}"
+ f" or downgrade your generated code using grpcio-tools<={GRPC_VERSION}."
Expand Down
1 change: 0 additions & 1 deletion src/gateway/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .v1 import auth, files
1 change: 0 additions & 1 deletion src/gateway/schemas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@


class BaseStruct(Struct):

def to_dict(self) -> dict[str, Any]:
return {field: getattr(self, field) for field in self.__struct_fields__}
8 changes: 4 additions & 4 deletions src/gateway/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .auth import *
from .connect import *
from .files import *
from .mail import *
from .auth import * # noqa: F403
from .connect import * # noqa: F403
from .files import * # noqa: F403
from .mail import * # noqa: F403
2 changes: 1 addition & 1 deletion src/gateway/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .utils import *
from .utils import * # noqa: F403
2 changes: 1 addition & 1 deletion src/gateway/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def chunk_generator(


async def converted_chunks_generator(
chunk_generator: AsyncGenerator[dict[str, str | bytes], None]
chunk_generator: AsyncGenerator[dict[str, str | bytes], None],
) -> AsyncGenerator[pb2.UploadFileRequest, None]:
async for chunk in chunk_generator:
request = pb2.UploadFileRequest(**chunk)
Expand Down
2 changes: 1 addition & 1 deletion src/mail/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .config import *
from .config import * # noqa: F403
2 changes: 1 addition & 1 deletion src/mail/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .mail import *
from .mail import * # noqa: F403
4 changes: 2 additions & 2 deletions src/mail/mail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .engine import *
from .send import *
from .engine import * # noqa: F403
from .send import * # noqa: F403
2 changes: 1 addition & 1 deletion src/mail/service/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .service import *
from .service import * # noqa: F403
2 changes: 1 addition & 1 deletion src/mail/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .connect import *
from .connect import * # noqa: F403
2 changes: 1 addition & 1 deletion src/mail/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .utils import *
from .utils import * # noqa: F403

0 comments on commit 24f4a1d

Please sign in to comment.