Skip to content

Commit 65763a6

Browse files
authored
Merge pull request #5 from Ifechukwu001/fix/github-actions
Github Actions for Linting and Static Typing
2 parents d4dc7e2 + 434b242 commit 65763a6

File tree

8 files changed

+52
-26
lines changed

8 files changed

+52
-26
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Linter & Type Checker
2+
on: [push, pull_request]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
9+
- name: Lint with Ruff
10+
uses: astral-sh/ruff-action@v3
11+
with:
12+
version: 0.9.6
13+
14+
- name: Format with Ruff
15+
uses: astral-sh/ruff-action@v3
16+
with:
17+
version: 0.9.6
18+
args: "format --check --diff"
19+
20+
pyright:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Setup UV
26+
uses: astral-sh/setup-uv@v5
27+
with:
28+
enable-cache: true
29+
30+
- name: Synchronize dependencies
31+
run: uv sync
32+
33+
- name: Check with Pyright
34+
uses: jakebailey/pyright-action@v2
35+
with:
36+
pylance-version: latest-release
37+
project: pyproject.toml

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Developers Foundry Wallet User Service System
44

55
 
66
[![Version: v1.2.0](https://img.shields.io/badge/api-v1.2.0-blue?style=flat&logo=money)](CHANGELOG.md)
7+
[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
8+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
79

810
---
911

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ version = { attr = "src.__version__" }
3535

3636
[tool.ruff]
3737
fix = true
38+
extend-exclude = ["manage.py", "**/migrations/*.py"]
3839

3940
[tool.ruff.lint]
4041
extend-select = [

src/api/middlewares/AppMiddleware.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
from typing import Annotated
2-
31
import jwt
42
from django.http import HttpRequest
53
from ninja.security import HttpBearer
64

75
from src.env import jwt_config
8-
from src.utils.svcs import Service
96
from src.utils.logger import Logger
107

118

12-
@Service()
139
class Authentication(HttpBearer):
14-
def __init__(self, logger: Annotated[Logger, "Authentication"]) -> None:
10+
def __init__(self, logger: Logger) -> None:
1511
super().__init__()
1612
self.logger = logger
1713

@@ -35,3 +31,10 @@ def authenticate(self, request: HttpRequest, token: str) -> str:
3531
setattr(request, "auth_email", jwt_data["email"])
3632
setattr(request, "auth_id", jwt_data["user_id"])
3733
return token
34+
35+
36+
def get_authentication() -> Authentication:
37+
return Authentication(Logger("Authentication"))
38+
39+
40+
authentication = get_authentication()

src/api/routes/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from django.http import HttpRequest
33

44
from src.env import app
5-
from src.utils.svcs import Depends
6-
from src.api.middlewares.AppMiddleware import Authentication
5+
from src.api.middlewares.AppMiddleware import authentication
76

87
api: NinjaAPI = NinjaAPI(
98
version=app["version"],
@@ -15,12 +14,10 @@
1514

1615

1716
@api.get("/")
18-
def home(request: HttpRequest) -> dict:
17+
async def home(request: HttpRequest) -> dict:
1918
return {"message": "Hello, World!"}
2019

2120

22-
authentication = Depends(Authentication)
23-
2421
api.add_router("/auth", "src.api.routes.Auth.router", tags=["Auth"])
2522
api.add_router(
2623
"/password/reset", "src.api.routes.PasswordReset.router", tags=["Password"]

src/utils/logger/Logger.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import inspect
21
import logging
3-
from typing import TypedDict, get_type_hints
2+
from typing import TypedDict
43

54
from src.env import app
65

@@ -14,14 +13,6 @@ class LogDataFormat(TypedDict):
1413
# @Service()
1514
class Logger:
1615
def __init__(self, context: str = "Root") -> None:
17-
frame = inspect.currentframe()
18-
if frame and (fb := frame.f_back) and (class_self := fb.f_locals.get("self")):
19-
# Extract metadata from the constructor
20-
init_params = get_type_hints(class_self.__class__.__init__)
21-
metadata = init_params.get("logger", None)
22-
23-
if metadata and hasattr(metadata, "__metadata__"):
24-
context = metadata.__metadata__[0]
2516
self.context = context
2617

2718
def debug(

src/utils/svcs/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from .registry import init_registry, close_registry
2-
from .services import Depends, Service, ADepends
2+
from .services import Service, ADepends
33

44
__all__ = [
55
"ADepends",
6-
"Depends",
76
"Service",
87
"close_registry",
98
"init_registry",

src/utils/svcs/services.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import TypeVar, Annotated, get_type_hints
22

3-
from asgiref.sync import async_to_sync
43
from svcs.exceptions import ServiceNotFoundError
54

65
from src.utils.logger import Logger
@@ -17,9 +16,6 @@ async def ADepends(cls: type[T]) -> T:
1716
return await container.aget(cls)
1817

1918

20-
Depends = async_to_sync(ADepends)
21-
22-
2319
async def get_logger(ann_context: str = "Root") -> Logger:
2420
ann = Annotated[Logger, ann_context]
2521

0 commit comments

Comments
 (0)