Skip to content

Commit f3e3902

Browse files
authored
Merge pull request #155 from python-ellar/lazy_module_import
Feat(LazyModuleImport): New feature
2 parents a7be09f + c7aab28 commit f3e3902

File tree

25 files changed

+178
-39
lines changed

25 files changed

+178
-39
lines changed

ellar/app/factory.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from ellar.common import EllarTyper
77
from ellar.common.constants import MODULE_METADATA, MODULE_WATERMARK
88
from ellar.common.models import GuardCanActivate
9-
from ellar.core.conf import Config
10-
from ellar.core.modules import DynamicModule, ModuleBase, ModuleSetup
9+
from ellar.core import Config, DynamicModule, LazyModuleImport, ModuleBase, ModuleSetup
1110
from ellar.di import EllarInjector, ProviderConfig
1211
from ellar.reflect import reflect
1312
from starlette.routing import Host, Mount
@@ -48,6 +47,9 @@ def read_all_module(cls, module_config: ModuleSetup) -> t.Dict[t.Type, ModuleSet
4847
)
4948
module_dependency = OrderedDict()
5049
for module in modules:
50+
if isinstance(module, LazyModuleImport):
51+
module = module.get_module(module_config.module.__name__)
52+
5153
if isinstance(module, DynamicModule):
5254
module.apply_configuration()
5355
module_config = ModuleSetup(module.module)

ellar/app/lifespan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import typing as t
2+
from contextlib import asynccontextmanager
23

34
from anyio import create_task_group
45
from ellar.common import IApplicationShutdown, IApplicationStartup
56
from ellar.common.logger import logger
6-
from ellar.reflect import asynccontextmanager
77

88
if t.TYPE_CHECKING:
99
from ellar.app import App

ellar/auth/policy/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __or__(
4040

4141
@t.no_type_check
4242
def __invert__(
43-
cls: t.Union["BasePolicyHandler", t.Type["BasePolicyHandler"]]
43+
cls: t.Union["BasePolicyHandler", t.Type["BasePolicyHandler"]],
4444
) -> "BasePolicyHandler":
4545
return _NOTPolicy(cls)
4646

ellar/common/datastructures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from starlette.datastructures import (
2626
URLPath,
2727
)
28-
from typing_extensions import Annotated, Doc # type: ignore[attr-defined]
28+
from typing_extensions import Annotated, Doc
2929

3030
__all__ = [
3131
"URL",

ellar/common/decorators/exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _add_exception_handler(
1919

2020

2121
def exception_handler(
22-
exc_class_or_status_code: t.Union[int, t.Type[Exception]]
22+
exc_class_or_status_code: t.Union[int, t.Type[Exception]],
2323
) -> t.Callable:
2424
"""
2525
========= MODULE DECORATOR ==============

ellar/common/decorators/guards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def UseGuards(
12-
*_guards: t.Union[t.Type["GuardCanActivate"], "GuardCanActivate"]
12+
*_guards: t.Union[t.Type["GuardCanActivate"], "GuardCanActivate"],
1313
) -> t.Callable:
1414
"""
1515
=========CONTROLLER AND ROUTE FUNCTION DECORATOR ==============

ellar/common/decorators/interceptor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def UseInterceptors(
12-
*args: t.Union[t.Type["EllarInterceptor"], "EllarInterceptor"]
12+
*args: t.Union[t.Type["EllarInterceptor"], "EllarInterceptor"],
1313
) -> t.Callable:
1414
"""
1515
=========CONTROLLER AND FUNCTION DECORATOR ==============

ellar/common/params/decorators/inject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def add_default_resolver(
4747

4848

4949
def get_default_resolver(
50-
type_identifier: t.Union[t.Type, str]
50+
type_identifier: t.Union[t.Type, str],
5151
) -> t.Optional[t.Type[SystemParameterResolver]]:
5252
return _DEFAULT_RESOLVERS.get(type_identifier)
5353

ellar/common/params/resolvers/parameter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ async def process_and_validate(
273273
results: t.List[t.Union[bytes, str]] = []
274274

275275
async def process_fn(
276-
fn: t.Callable[[], t.Coroutine[t.Any, t.Any, t.Any]]
276+
fn: t.Callable[[], t.Coroutine[t.Any, t.Any, t.Any]],
277277
) -> None:
278278
result = await fn()
279279
results.append(result)

ellar/core/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .connection import HTTPConnection, Request, WebSocket
55
from .execution_context import ExecutionContext, HostContext
66
from .guards import GuardConsumer
7-
from .modules import DynamicModule, ModuleBase, ModuleSetup
7+
from .modules import DynamicModule, LazyModuleImport, ModuleBase, ModuleSetup
88
from .services import Reflector, reflector
99

1010
__all__ = [
@@ -21,6 +21,7 @@
2121
"Reflector",
2222
"reflector",
2323
"GuardConsumer",
24+
"LazyModuleImport",
2425
]
2526

2627

0 commit comments

Comments
 (0)