Fixed formatting
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 6s
Build on push / prepare (push) Successful in 9s
Build on push / core (push) Successful in 19s
Build on push / query (push) Successful in 19s
Build on push / dependency (push) Successful in 14s
Build on push / mail (push) Successful in 16s
Build on push / application (push) Successful in 19s
Build on push / database (push) Successful in 20s
Build on push / translation (push) Successful in 20s
Build on push / auth (push) Successful in 14s
Build on push / api (push) Successful in 15s
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 6s
Build on push / prepare (push) Successful in 9s
Build on push / core (push) Successful in 19s
Build on push / query (push) Successful in 19s
Build on push / dependency (push) Successful in 14s
Build on push / mail (push) Successful in 16s
Build on push / application (push) Successful in 19s
Build on push / database (push) Successful in 20s
Build on push / translation (push) Successful in 20s
Build on push / auth (push) Successful in 14s
Build on push / api (push) Successful in 15s
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from .error import APIError, AlreadyExists, EndpointNotImplemented, Forbidden, NotFound, Unauthorized
|
||||
from .logger import APILogger
|
||||
from .settings import ApiSettings
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from .application_builder import ApplicationBuilder
|
||||
from .host import Host
|
||||
from .host import Host
|
||||
|
||||
@@ -77,4 +77,4 @@ class Host:
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
return cls.get_loop().run_until_complete(func(*args, **kwargs))
|
||||
|
||||
return func(*args, **kwargs)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
@@ -17,5 +17,4 @@ def _with_permissions(self: _ApplicationABC, *permissions: Type[Enum]) -> _Appli
|
||||
return self
|
||||
|
||||
|
||||
|
||||
_ApplicationABC.extend(_ApplicationABC.with_permissions, _with_permissions)
|
||||
|
||||
@@ -14,6 +14,7 @@ def dependency_error(src: str, package_name: str, e: ImportError = None) -> None
|
||||
|
||||
exit(1)
|
||||
|
||||
|
||||
def module_dependency_error(src: str, module: str, e: ImportError = None) -> None:
|
||||
Console.error(f"'{module}' is required to use feature: {src}. Please initialize it with `add_module({module})`.")
|
||||
tb = traceback.format_exc()
|
||||
@@ -23,4 +24,4 @@ def module_dependency_error(src: str, module: str, e: ImportError = None) -> Non
|
||||
elif e is not None:
|
||||
Console.write_line("->", str(e))
|
||||
|
||||
exit(1)
|
||||
exit(1)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from .hosted_service import HostedService
|
||||
from .startup_task import StartupTask
|
||||
from .startup_task import StartupTask
|
||||
|
||||
@@ -6,4 +6,4 @@ class HostedService(ABC):
|
||||
async def start(self): ...
|
||||
|
||||
@abstractmethod
|
||||
async def stop(self): ...
|
||||
async def stop(self): ...
|
||||
|
||||
@@ -3,6 +3,7 @@ from typing import Type
|
||||
|
||||
TModule = Type["Module"]
|
||||
|
||||
|
||||
class Module(ABC):
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -23,7 +23,9 @@ class ServiceProvider:
|
||||
type_args = list(typing.get_args(service_type))
|
||||
|
||||
for descriptor in self._service_descriptors:
|
||||
if typing.get_origin(service_type) is None and (descriptor.service_type == service_type or issubclass(descriptor.base_type, service_type)):
|
||||
if typing.get_origin(service_type) is None and (
|
||||
descriptor.service_type == service_type or issubclass(descriptor.base_type, service_type)
|
||||
):
|
||||
return descriptor
|
||||
|
||||
descriptor_base_type = typing.get_origin(descriptor.base_type) or descriptor.base_type
|
||||
@@ -65,9 +67,7 @@ class ServiceProvider:
|
||||
implementations.append(descriptor.implementation)
|
||||
continue
|
||||
|
||||
implementation = self._build_service(
|
||||
descriptor, *args, origin_service_type=service_type, **kwargs
|
||||
)
|
||||
implementation = self._build_service(descriptor, *args, origin_service_type=service_type, **kwargs)
|
||||
if descriptor.lifetime in (ServiceLifetimeEnum.singleton, ServiceLifetimeEnum.scoped):
|
||||
descriptor.implementation = implementation
|
||||
|
||||
@@ -81,7 +81,9 @@ class ServiceProvider:
|
||||
parameter = param[1]
|
||||
if parameter.name != "self" and parameter.annotation != Parameter.empty:
|
||||
if typing.get_origin(parameter.annotation) == list:
|
||||
params.append(self._get_services(typing.get_args(parameter.annotation)[0], service_type=origin_service_type))
|
||||
params.append(
|
||||
self._get_services(typing.get_args(parameter.annotation)[0], service_type=origin_service_type)
|
||||
)
|
||||
|
||||
elif parameter.annotation == Source:
|
||||
params.append(origin_service_type.__name__)
|
||||
@@ -104,7 +106,9 @@ class ServiceProvider:
|
||||
|
||||
return params
|
||||
|
||||
def _build_service(self, descriptor: ServiceDescriptor, *args, origin_service_type: type = None, **kwargs) -> object:
|
||||
def _build_service(
|
||||
self, descriptor: ServiceDescriptor, *args, origin_service_type: type = None, **kwargs
|
||||
) -> object:
|
||||
if descriptor.implementation is not None:
|
||||
service_type = type(descriptor.implementation)
|
||||
else:
|
||||
@@ -131,7 +135,11 @@ class ServiceProvider:
|
||||
yield scoped_provider
|
||||
|
||||
def get_hosted_services(self) -> list[Optional[T]]:
|
||||
hosted_services = [self.get_service(d.service_type) for d in self._service_descriptors if d.lifetime == ServiceLifetimeEnum.hosted]
|
||||
hosted_services = [
|
||||
self.get_service(d.service_type)
|
||||
for d in self._service_descriptors
|
||||
if d.lifetime == ServiceLifetimeEnum.hosted
|
||||
]
|
||||
return hosted_services
|
||||
|
||||
def get_service(self, service_type: Type[T], *args, **kwargs) -> Optional[T]:
|
||||
|
||||
@@ -9,7 +9,6 @@ class MailModule(Module):
|
||||
def dependencies() -> list[TModule]:
|
||||
return []
|
||||
|
||||
|
||||
@staticmethod
|
||||
def register(collection: ServiceCollection):
|
||||
collection.add_singleton(EMailClientABC, EMailClient)
|
||||
collection.add_singleton(EMailClientABC, EMailClient)
|
||||
|
||||
Reference in New Issue
Block a user