diff --git a/ellar_cli/__init__.py b/ellar_cli/__init__.py index 5e4079f..bc10288 100644 --- a/ellar_cli/__init__.py +++ b/ellar_cli/__init__.py @@ -1,3 +1,3 @@ """Ellar CLI Tool for Scaffolding Ellar Projects, Modules and also running Ellar Commands""" -__version__ = "0.3.4" +__version__ = "0.3.5" diff --git a/ellar_cli/click/__init__.py b/ellar_cli/click/__init__.py index 7e510c4..8ea5faa 100644 --- a/ellar_cli/click/__init__.py +++ b/ellar_cli/click/__init__.py @@ -42,11 +42,12 @@ from click.utils import get_binary_stream as get_binary_stream from click.utils import get_text_stream as get_text_stream from click.utils import open_file as open_file +from ellar.threading import run_as_async from .argument import Argument from .command import Command from .group import AppContextGroup, EllarCommandGroup -from .util import run_as_async, with_app_context +from .util import with_app_context def argument( diff --git a/ellar_cli/click/util.py b/ellar_cli/click/util.py index 950b32e..4f94472 100644 --- a/ellar_cli/click/util.py +++ b/ellar_cli/click/util.py @@ -1,12 +1,9 @@ -import asyncio -import functools import typing as t from functools import update_wrapper import click from ellar.threading.sync_worker import ( - execute_async_context_manager_with_sync_worker, - execute_coroutine_with_sync_worker, + execute_async_context_manager, ) from ellar_cli.constants import ELLAR_META @@ -24,32 +21,9 @@ def decorator(__ctx: click.Context, *args: t.Any, **kwargs: t.Any) -> t.Any: if meta_ and meta_.has_meta: __ctx.with_resource( - execute_async_context_manager_with_sync_worker( - meta_.get_application_context() - ) + execute_async_context_manager(meta_.get_application_context()) ) return __ctx.invoke(f, *args, **kwargs) return update_wrapper(decorator, f) - - -def run_as_async(f: t.Callable) -> t.Callable: - """ - Runs async click commands - - eg: - - @click.command() - @click.argument('name') - @click.run_as_async - async def print_name(name: str): - click.echo(f'Hello {name}, this is an async command.') - """ - assert asyncio.iscoroutinefunction(f), "Decorated function must be Coroutine" - - @functools.wraps(f) - def _decorator(*args: t.Any, **kw: t.Any) -> t.Any: - return execute_coroutine_with_sync_worker(f(*args, **kw)) - - return _decorator diff --git a/ellar_cli/manage_commands/create_module.py b/ellar_cli/manage_commands/create_module.py index 6b57d0d..c17c913 100644 --- a/ellar_cli/manage_commands/create_module.py +++ b/ellar_cli/manage_commands/create_module.py @@ -4,7 +4,7 @@ from importlib import import_module from pathlib import Path -from ellar.common.utils.module_loading import module_dir +from ellar.utils.module_loading import module_dir import ellar_cli.click as eClick from ellar_cli import scaffolding diff --git a/ellar_cli/manage_commands/create_project.py b/ellar_cli/manage_commands/create_project.py index 5570af7..27b3287 100644 --- a/ellar_cli/manage_commands/create_project.py +++ b/ellar_cli/manage_commands/create_project.py @@ -4,7 +4,7 @@ from importlib import import_module from pathlib import Path -from ellar.common.utils.module_loading import module_dir +from ellar.utils.module_loading import module_dir import ellar_cli.click as eClick from ellar_cli import scaffolding diff --git a/ellar_cli/manage_commands/new.py b/ellar_cli/manage_commands/new.py index b0f2f75..c23648c 100644 --- a/ellar_cli/manage_commands/new.py +++ b/ellar_cli/manage_commands/new.py @@ -3,7 +3,7 @@ import subprocess import typing as t -from ellar.common.utils.module_loading import module_dir +from ellar.utils.module_loading import module_dir import ellar_cli.click as eClick from ellar_cli import scaffolding diff --git a/ellar_cli/manage_commands/runserver.py b/ellar_cli/manage_commands/runserver.py index 7f1eaea..71e0ef5 100644 --- a/ellar_cli/manage_commands/runserver.py +++ b/ellar_cli/manage_commands/runserver.py @@ -5,7 +5,7 @@ from datetime import datetime from ellar import __version__ as ellar_version -from ellar.common.utils.enums import create_enums_from_list +from ellar.utils.enums import create_enums_from_list from uvicorn import config as uvicorn_config from uvicorn import run as uvicorn_run from uvicorn.config import ( diff --git a/ellar_cli/scaffolding/project_template/project_name/server.ellar b/ellar_cli/scaffolding/project_template/project_name/server.ellar index e2d6b6b..1357c58 100644 --- a/ellar_cli/scaffolding/project_template/project_name/server.ellar +++ b/ellar_cli/scaffolding/project_template/project_name/server.ellar @@ -21,7 +21,8 @@ def bootstrap() -> App: # document_builder.set_title('{{project_name | capitalize}} Title') \ # .set_version('1.0.2') \ # .set_contact(name='Author Name', url='https://www.author-name.com', email='authorname@gmail.com') \ - # .set_license('MIT Licence', url='https://www.google.com') + # .set_license('MIT Licence', url='https://www.google.com') \ + # .add_server('/', description='Development Server') # # document = document_builder.build_document(application) # module = OpenAPIDocumentModule.setup( diff --git a/ellar_cli/service/cli.py b/ellar_cli/service/cli.py index 570b933..a03b786 100644 --- a/ellar_cli/service/cli.py +++ b/ellar_cli/service/cli.py @@ -7,8 +7,8 @@ from ellar.app import App from ellar.app.context import ApplicationContext from ellar.common.constants import ELLAR_CONFIG_MODULE -from ellar.common.utils.importer import import_from_string, module_import from ellar.core import Config, ModuleBase +from ellar.utils.importer import import_from_string, module_import from tomlkit import dumps as tomlkit_dumps from tomlkit import parse as tomlkit_parse from tomlkit.items import Table diff --git a/pyproject.toml b/pyproject.toml index 97a3ea8..8ebc890 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", - "uvicorn[standard] == 0.25.0", + "uvicorn[standard] == 0.27.1", "ellar >= 0.6.6", ] diff --git a/tests/click/test_app_context_group.py b/tests/click/test_app_context_group.py index 8464a17..e05d9c8 100644 --- a/tests/click/test_app_context_group.py +++ b/tests/click/test_app_context_group.py @@ -1,4 +1,5 @@ -from ellar.app import current_app +from ellar.app import current_injector +from ellar.core import Config from ellar_cli.click.group import AppContextGroup @@ -12,7 +13,7 @@ def app_group(): @app_group.command(with_app_context=False) def invoke_without_app_context(): - assert current_app.config + assert current_injector.get(Config) print("Application Context wont be initialized.") diff --git a/tests/sample_app/example_project/commands.py b/tests/sample_app/example_project/commands.py index 9386303..33a168c 100644 --- a/tests/sample_app/example_project/commands.py +++ b/tests/sample_app/example_project/commands.py @@ -1,4 +1,5 @@ -from ellar.app import current_config +from ellar.app import current_injector +from ellar.core import Config import ellar_cli.click as click @@ -29,5 +30,5 @@ def say_hello(): @click.with_app_context def command_with_app_context(): print( - f"Running a command with application context - {current_config.APPLICATION_NAME}" + f"Running a command with application context - {current_injector.get(Config).APPLICATION_NAME}" ) diff --git a/tests/sample_app/plain_project/plain_project/root_module.py b/tests/sample_app/plain_project/plain_project/root_module.py index f89b769..8753554 100644 --- a/tests/sample_app/plain_project/plain_project/root_module.py +++ b/tests/sample_app/plain_project/plain_project/root_module.py @@ -1,4 +1,4 @@ -from ellar.app import current_app +from ellar.app import current_injector from ellar.common import ( IExecutionContext, JSONResponse, @@ -16,7 +16,7 @@ @click.with_app_context def plain_project(): """Project 2 Custom Command""" - assert isinstance(current_app.config, Config) + assert isinstance(current_injector.get(Config), Config) print("Plain Project Command works. Executed within application context")