Skip to content

Commit

Permalink
Merge pull request #104 from python-ellar/app_context_default_async
Browse files Browse the repository at this point in the history
App context default async
  • Loading branch information
eadwinCode authored Aug 21, 2024
2 parents f372e4b + 8e29b18 commit b0d50e7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ellar_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Ellar CLI Tool for Scaffolding Ellar Projects, Modules and also running Ellar Commands"""

__version__ = "0.4.2b1"
__version__ = "0.4.2"
5 changes: 5 additions & 0 deletions ellar_cli/click/group.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import inspect
import typing as t

import click
from ellar.app import AppFactory
from ellar.common.constants import MODULE_METADATA
from ellar.core import ModuleBase, ModuleSetup, reflector
from ellar.threading import run_as_sync

from ellar_cli.constants import ELLAR_META
from ellar_cli.service import EllarCLIService, EllarCLIServiceWithPyProject
Expand All @@ -30,6 +32,9 @@ def command( # type:ignore[override]
wrap_for_ctx = kwargs.pop("with_injector_context", True)

def decorator(f: t.Callable) -> t.Any:
if inspect.iscoroutinefunction(f):
f = run_as_sync(f)

if wrap_for_ctx:
f = with_injector_context(f)
return super(AppContextGroup, self).command(*args, **kwargs)(f)
Expand Down
2 changes: 1 addition & 1 deletion ellar_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def version_callback(ctx: click.Context, _: t.Any, value: bool) -> None:
raise click.Exit(0)


def create_ellar_cli(app_import_string: t.Optional[str] = None) -> click.Group:
def create_ellar_cli(app_import_string: t.Optional[str] = None) -> EllarCommandGroup:
@click.group(
name="Ellar CLI Tool... ",
cls=EllarCommandGroup,
Expand Down
2 changes: 1 addition & 1 deletion ellar_cli/service/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _import_and_validate_application(
)

if is_callable:
app = app() # type:ignore[call-arg]
app = app()

if not isinstance(app, App):
raise EllarCLIException(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ classifiers = [
dependencies = [
# exclude 0.11.2 and 0.11.3 due to https://github.com/sdispater/tomlkit/issues/225
"tomlkit >=0.11.1,<1.0.0,!=0.11.2,!=0.11.3",
"ellar >= 0.8b1",
"ellar >= 0.8.1",
"uvicorn[standard] == 0.30.4",
"click >= 8.1.7",
]
Expand Down

0 comments on commit b0d50e7

Please sign in to comment.