feat: add linters and ci (#28)

* feat: introduce linting and ci
* add locks
* prettier
* black and sorting
* f405 missing imports
* E902
* mypy
* renderer
* circular imports
* check comment
* add exports
* add lnurlerrorhandler only on lnurl routes
* add test case
This commit is contained in:
dni ⚡ 2024-07-11 10:30:28 +02:00 committed by GitHub
commit a44820f61f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 2934 additions and 145 deletions

View file

@ -1,13 +1,9 @@
from fastapi import APIRouter, Request, Response
from fastapi.routing import APIRoute
from fastapi import APIRouter
from fastapi.responses import JSONResponse
from lnbits.db import Database
from lnbits.helpers import template_renderer
from typing import Callable
db = Database("ext_withdraw")
from .crud import db
from .views import withdraw_ext_generic
from .views_api import withdraw_ext_api
from .views_lnurl import withdraw_ext_lnurl
withdraw_static_files = [
{
@ -16,36 +12,9 @@ withdraw_static_files = [
}
]
class LNURLErrorResponseHandler(APIRoute):
def get_route_handler(self) -> Callable:
original_route_handler = super().get_route_handler()
async def custom_route_handler(request: Request) -> Response:
try:
response = await original_route_handler(request)
except HTTPException as exc:
logger.debug(f"HTTPException: {exc}")
response = JSONResponse(
status_code=exc.status_code,
content={"status": "ERROR", "reason": f"{exc.detail}"},
)
except Exception as exc:
raise exc
return response
return custom_route_handler
withdraw_ext: APIRouter = APIRouter(prefix="/withdraw", tags=["withdraw"])
withdraw_ext.route_class = LNURLErrorResponseHandler
withdraw_ext.include_router(withdraw_ext_generic)
withdraw_ext.include_router(withdraw_ext_api)
withdraw_ext.include_router(withdraw_ext_lnurl)
def withdraw_renderer():
return template_renderer(["withdraw/templates"])
from .lnurl import * # noqa: F401,F403
from .views import * # noqa: F401,F403
from .views_api import * # noqa: F401,F403
__all__ = ["withdraw_ext", "withdraw_static_files", "db"]