Skip to content

Commit

Permalink
style(ruff): 💄 be compliant with ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
miragecentury committed Aug 20, 2024
1 parent 7fbeb19 commit 722a1c9
Show file tree
Hide file tree
Showing 40 changed files with 278 additions and 330 deletions.
4 changes: 1 addition & 3 deletions src/python_factory/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Re-Use the main function from the example module.
"""
"""Re-Use the main function from the example module."""

from python_factory.example import main

Expand Down
1 change: 1 addition & 0 deletions src/python_factory/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Python Factory Core Module."""
4 changes: 1 addition & 3 deletions src/python_factory/core/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Define the API for the Python Factory.
"""
"""Define the API for the Python Factory."""

from fastapi import APIRouter

Expand Down
6 changes: 3 additions & 3 deletions src/python_factory/core/api/tags.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Provides the Tag as Enum
"""
"""Provides the Tag as Enum."""

from enum import StrEnum, auto


class TagEnum(StrEnum):
"""Define Tag for OpenAPI Description."""

SYS = auto()
4 changes: 1 addition & 3 deletions src/python_factory/core/api/v1/sys/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Package for system related API endpoints.
"""
"""Package for system related API endpoints."""

from fastapi import APIRouter

Expand Down
16 changes: 6 additions & 10 deletions src/python_factory/core/api/v1/sys/health.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
API v1 sys health module.
"""API v1 sys health module.
Provide the Get health endpoint
"""
Expand All @@ -14,18 +13,14 @@


class HealthStatusEnum(StrEnum):
"""
Health status enum.
"""
"""Health status enum."""

HEALTHY = "healthy"
UNHEALTHY = "unhealthy"


class HealthResponseModel(BaseModel):
"""
Health response schema.
"""
"""Health response schema."""

status: HealthStatusEnum

Expand All @@ -46,10 +41,11 @@ class HealthResponseModel(BaseModel):
},
)
def get_api_v1_sys_health(response: Response) -> HealthResponseModel:
"""
Get the health of the system.
"""Get the health of the system.
Args:
response (Response): The response object.
Returns:
HealthResponse: The health status.
"""
Expand Down
16 changes: 6 additions & 10 deletions src/python_factory/core/api/v1/sys/readiness.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
API v1 sys readiness module.
"""API v1 sys readiness module.
Provide the Get readiness endpoint
"""
Expand All @@ -14,18 +13,14 @@


class ReadinessStatusEnum(StrEnum):
"""
Readiness status enum.
"""
"""Readiness status enum."""

READY = "ready"
NOT_READY = "not_ready"


class ReadinessResponseModel(BaseModel):
"""
Readiness response schema.
"""
"""Readiness response schema."""

status: ReadinessStatusEnum

Expand All @@ -46,10 +41,11 @@ class ReadinessResponseModel(BaseModel):
},
)
def get_api_v1_sys_readiness(response: Response) -> ReadinessResponseModel:
"""
Get the readiness of the system.
"""Get the readiness of the system.
Args:
response (Response): The response object.
Returns:
ReadinessResponse: The readiness status.
"""
Expand Down
5 changes: 1 addition & 4 deletions src/python_factory/core/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""
Package that contains the abstract classes
for the application and application configuration.
"""
"""Provides the core application module for the Python Factory."""

from .base import (
AppConfigAbstract,
Expand Down
4 changes: 1 addition & 3 deletions src/python_factory/core/app/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Package for the base application, abstract config classes and related exceptions.
"""
"""Package for the base application, abstract config classes and related exceptions."""

from .application import BaseApplication
from .config_abstract import AppConfigAbstract
Expand Down
22 changes: 13 additions & 9 deletions src/python_factory/core/app/base/application.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Provides the abstract class for the application.
"""
"""Provides the abstract class for the application."""

from typing import cast

Expand All @@ -12,14 +10,22 @@


class BaseApplication(FastAPIAbstract, ApplicationPluginManagerAbstract):
"""
Application abstract class.
"""
"""Application abstract class."""

PACKAGE_NAME: str = ""

def __init__(self, config: AppConfigAbstract) -> None:
"""Instanciate the application.
Args:
config (AppConfigAbstract): The application configuration.
Returns:
None
Raises:
ValueError: If the package name is not set.
"""
if self.PACKAGE_NAME == "":
raise ValueError(
"The package name must be set in the concrete application class."
Expand All @@ -34,7 +40,5 @@ def __init__(self, config: AppConfigAbstract) -> None:
)

def get_config(self) -> AppConfigAbstract:
"""
Get the application configuration.
"""
"""Get the application configuration."""
return self._config
6 changes: 3 additions & 3 deletions src/python_factory/core/app/base/config_abstract.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Provide the configuration for the app server.
"""
"""Provide the configuration for the app server."""

from ..enums import EnvironmentEnum
from .fastapi_application_abstract import FastAPIConfigAbstract


class AppConfigAbstract(FastAPIConfigAbstract):
"""Application configuration abstract class."""

environment: EnvironmentEnum
service_name: str
service_namespace: str
12 changes: 9 additions & 3 deletions src/python_factory/core/app/base/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
"""
Provides the exceptions for the application factory.
"""
"""Provides the exceptions for the application factory."""


class BaseApplicationException(BaseException):
"""Base application exception."""

pass


class ApplicationFactoryException(BaseApplicationException):
"""Application factory exception."""

pass


class ApplicationConfigFactoryException(BaseApplicationException):
"""Application configuration factory exception."""

pass


class ApplicationPluginManagerException(BaseApplicationException):
"""Application plugin manager exception."""

pass
31 changes: 16 additions & 15 deletions src/python_factory/core/app/base/fastapi_application_abstract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Provide
"""
"""Provides an abstract class for FastAPI application integration."""

from abc import ABC
from typing import Any
Expand All @@ -10,9 +8,7 @@


class FastAPIConfigAbstract(ABC, BaseModel):
"""
Partial configuration for FastAPI.
"""
"""Partial configuration for FastAPI."""

model_config = ConfigDict(strict=False)

Expand All @@ -37,13 +33,22 @@ class FastAPIConfigAbstract(ABC, BaseModel):


class FastAPIAbstract(ABC):
"""
Application integration with FastAPI.
"""
"""Application integration with FastAPI."""

def __init__(
self, config: FastAPIConfigAbstract, api_router: APIRouter | None = None
) -> None:
"""Instanciate the FastAPI application.
Args:
config (FastAPIConfigAbstract): The FastAPI configuration.
api_router (APIRouter, optional): The API router to include.
Defaults to None.
Returns:
None
"""
self._fastapi_app: FastAPI = FastAPI(
title=config.title,
description=config.description,
Expand All @@ -55,13 +60,9 @@ def __init__(
self._fastapi_app.include_router(router=api_router)

def get_asgi_app(self) -> FastAPI:
"""
Get the ASGI application.
"""
"""Get the ASGI application."""
return self._fastapi_app

async def __call__(self, scope: Any, receive: Any, send: Any) -> None:
"""
Forward the call to the FastAPI app.
"""
"""Forward the call to the FastAPI app."""
return await self._fastapi_app.__call__(scope=scope, receive=receive, send=send)
27 changes: 13 additions & 14 deletions src/python_factory/core/app/base/module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Provide a generic module for injection bindings for the application.
"""
"""Provide a generic module for injection bindings for the application."""

from typing import Generic, TypeVar, get_args

Expand All @@ -22,16 +20,18 @@


class GenericBaseApplicationModule(Generic[APP_T, CONFIG_T], injector.Module):
"""
Generic application module.
"""
"""Generic application module."""

def configure(self, binder: injector.Binder) -> None:
"""
Configure injection bindings for the application
in a generic way.
"""
"""Configure injection bindings for the application in a generic way.
Args:
binder (injector.Binder): The injector binder.
Returns:
None
"""
# Retrieve the concrete application class and configuration class
app_concrete_class, app_config_concrete_class = get_args(
self.__orig_bases__[0] # type: ignore[attr-defined]
Expand All @@ -54,7 +54,7 @@ def configure(self, binder: injector.Binder) -> None:
# Like the application class, bind the concrete application configuration
# and the application configuration abstract class to the same provider.
application_config_callable_provider = injector.CallableProvider(
self._build_generic_application_config
callable=self._build_generic_application_config
)
binder.bind(
interface=app_config_concrete_class,
Expand All @@ -70,8 +70,8 @@ def configure(self, binder: injector.Binder) -> None:
binder.install(module=OpenTelemetryPluginModule)

def _build_generic_application_config(self) -> CONFIG_T | None:
"""
Generic Builder for the application configuration.
"""Generic Builder for the application configuration.
Use the concrete application class to build the concrete application
configuration class.
Expand All @@ -87,7 +87,6 @@ def _build_generic_application_config(self) -> CONFIG_T | None:
The application configuration
"""

# Retrieve the concrete application class
# and the concrete application configuration class
app_concrete_class, app_config_concrete_class = get_args(
Expand Down
Loading

0 comments on commit 722a1c9

Please sign in to comment.