Skip to content

Commit

Permalink
finally configure linter in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtedn21 committed Nov 21, 2023
1 parent daf8664 commit e3b7da1
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 138 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on: ["push", "pull_request"]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@master
- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry
python -m poetry install --only dev
- name: Run linters
run: |
poetry run isort --check --diff .
poetry run ruff check .
poetry run flake8 .
11 changes: 9 additions & 2 deletions martin_eden/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from martin_eden import (base, core, database, http_utils, openapi, routing,
utils)
from martin_eden import (
base,
core,
database,
http_utils,
openapi,
routing,
utils,
)

__all__ = [
'core',
Expand Down
25 changes: 16 additions & 9 deletions martin_eden/core.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import asyncio
from logging import getLogger
import dataclasses
from martin_eden.logs import configure_logging
import json
import socket
from asyncio import AbstractEventLoop
from logging import getLogger
from typing import Any, Optional

from dacite import from_dict as dataclass_from_dict

from martin_eden.base import Controller
from martin_eden.database import DataBase, query_params_to_alchemy_filters
from martin_eden.http_utils import (HttpHeadersParser, HttpMethod,
create_response_headers)
from martin_eden.http_utils import (
HttpHeadersParser,
HttpMethod,
create_response_headers,
)
from martin_eden.logs import configure_logging
from martin_eden.openapi import OpenApiBuilder
from martin_eden.routing import (ControllerDefinitionError,
FindControllerError, get_controller,
register_route)
from martin_eden.utils import get_argument_names
from martin_eden.routing import (
ControllerDefinitionError,
FindControllerError,
get_controller,
register_route,
)
from martin_eden.settings import Settings
from martin_eden.utils import get_argument_names

HTTP_MESSAGE_CHUNK_SIZE = 1024
db = DataBase()


Expand Down Expand Up @@ -185,7 +192,7 @@ async def handle_request(self, client_socket: socket.socket) -> None:
message = b''
while chunk := await self.event_loop.sock_recv(client_socket, 1024):
message += chunk
if len(chunk) < 1024:
if len(chunk) < HTTP_MESSAGE_CHUNK_SIZE:
break

handler = HttpMessageHandler(message)
Expand Down
28 changes: 17 additions & 11 deletions martin_eden/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
from dataclasses import field, make_dataclass
from datetime import date, datetime
from typing import Any, Callable, Iterable
from martin_eden.settings import Settings

from marshmallow.fields import Date, DateTime, Int, Nested, Str
from marshmallow_enum import EnumField as MarshmallowEnum
from sqlalchemy.ext.asyncio import (AsyncAttrs, AsyncEngine,
async_sessionmaker, create_async_engine)
from sqlalchemy.ext.asyncio import (
AsyncAttrs,
AsyncEngine,
async_sessionmaker,
create_async_engine,
)
from sqlalchemy.orm import DeclarativeBase

from martin_eden.base import CustomSchema
from martin_eden.utils import (get_name_of_model,
get_python_field_type_from_alchemy_field,
is_enum_alchemy_field,
is_property_secondary_relation,
is_simple_alchemy_field,
is_special_alchemy_field)
from martin_eden.settings import Settings
from martin_eden.utils import (
get_name_of_model,
get_python_field_type_from_alchemy_field,
is_enum_alchemy_field,
is_property_secondary_relation,
is_simple_alchemy_field,
is_special_alchemy_field,
)


class Base(AsyncAttrs, DeclarativeBase):
Expand Down Expand Up @@ -56,10 +62,10 @@ def query_params_to_alchemy_filters(
method_obj = getattr(field_obj, method_name)
return method_obj(f'%{value}%')
elif method_name == 'exactly':
method_obj = getattr(field_obj, 'in_')
method_obj = field_obj.in_
return method_obj([int(value)])
elif method_name == 'in':
method_obj = getattr(field_obj, 'in_')
method_obj = field_obj.in_
return method_obj(list(map(int, value.split(','))))


Expand Down
10 changes: 6 additions & 4 deletions martin_eden/openapi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
from datetime import date, datetime
from pathlib import Path
from typing import TYPE_CHECKING

from martin_eden.base import CustomJsonSchema, CustomSchema
from martin_eden.utils import (dict_set, get_name_of_model,
get_operation_id_for_openapi,
get_python_field_type_from_alchemy_field)
from martin_eden.utils import (
dict_set,
get_name_of_model,
get_operation_id_for_openapi,
get_python_field_type_from_alchemy_field,
)

if TYPE_CHECKING:
from database import Base as BaseModel
Expand Down
Loading

0 comments on commit e3b7da1

Please sign in to comment.